Skip to content

Commit

Permalink
feat(provider/oraclebmcs): Destroy server group operation (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlord authored and Matt Duftler committed Apr 24, 2017
1 parent 3609ef0 commit 3e8faeb
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2017 Oracle America, Inc.
*
* The contents of this file are subject to the Apache License Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* If a copy of the Apache License Version 2.0 was not distributed with this file,
* You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.html
*/
package com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.converter

import com.netflix.spinnaker.clouddriver.oraclebmcs.OracleBMCSOperation
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.description.DestroyOracleBMCSServerGroupDescription
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.op.DestroyOracleBMCSServerGroupAtomicOperation
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperations
import com.netflix.spinnaker.clouddriver.security.AbstractAtomicOperationsCredentialsSupport
import groovy.util.logging.Slf4j
import org.springframework.stereotype.Component

@Slf4j
@OracleBMCSOperation(AtomicOperations.DESTROY_SERVER_GROUP)
@Component("destroyOracleBMCSServerGroupDescription")
class DestroyOracleBMCSServerGroupAtomicOperationConverter extends AbstractAtomicOperationsCredentialsSupport {

@Override
AtomicOperation convertOperation(Map input) {
log.info("DestroyOracleBMCSServerGroupAtomicOperationConverter convertOperation, input: $input")
new DestroyOracleBMCSServerGroupAtomicOperation(convertDescription(input))
}

@Override
DestroyOracleBMCSServerGroupDescription convertDescription(Map input) {
OracleBMCSAtomicOperationConverterHelper.convertDescription(input, this, DestroyOracleBMCSServerGroupDescription)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2017 Oracle America, Inc.
*
* The contents of this file are subject to the Apache License Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* If a copy of the Apache License Version 2.0 was not distributed with this file,
* You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.html
*/
package com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.description

import groovy.transform.ToString

@ToString(includeNames = true)
class DestroyOracleBMCSServerGroupDescription extends AbstractOracleBMCSCredentialsDescription {

String accountName
String region
String serverGroupName
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2017 Oracle America, Inc.
*
* The contents of this file are subject to the Apache License Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* If a copy of the Apache License Version 2.0 was not distributed with this file,
* You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.html
*/
package com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.op

import com.netflix.spinnaker.clouddriver.data.task.Task
import com.netflix.spinnaker.clouddriver.data.task.TaskRepository
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.description.DestroyOracleBMCSServerGroupDescription
import com.netflix.spinnaker.clouddriver.oraclebmcs.service.servergroup.OracleBMCSServerGroupService
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation
import org.springframework.beans.factory.annotation.Autowired

class DestroyOracleBMCSServerGroupAtomicOperation implements AtomicOperation<Void> {

private final DestroyOracleBMCSServerGroupDescription description

private static final String BASE_PHASE = "DESTROY_SERVER_GROUP"

private static Task getTask() {
TaskRepository.threadLocalTask.get()
}

@Autowired
OracleBMCSServerGroupService oracleBMCSServerGroupService

DestroyOracleBMCSServerGroupAtomicOperation(DestroyOracleBMCSServerGroupDescription description) {
this.description = description
}

@Override
Void operate(List priorOutputs) {
task.updateStatus BASE_PHASE, "Destroying server group: " + description.serverGroupName
oracleBMCSServerGroupService.destroyServerGroup(task, description.credentials, description.serverGroupName)
task.updateStatus BASE_PHASE, "Completed server group destruction"
return null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2017 Oracle America, Inc.
*
* The contents of this file are subject to the Apache License Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* If a copy of the Apache License Version 2.0 was not distributed with this file,
* You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.html
*/
package com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.validator

import com.netflix.spinnaker.clouddriver.deploy.DescriptionValidator
import com.netflix.spinnaker.clouddriver.oraclebmcs.OracleBMCSOperation
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.description.DestroyOracleBMCSServerGroupDescription
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperations
import org.springframework.stereotype.Component
import org.springframework.validation.Errors

@OracleBMCSOperation(AtomicOperations.DESTROY_SERVER_GROUP)
@Component("destroyOracleBMCSServerGroupDescriptionValidator")
class DestroyOracleBMCSServerGroupDescriptionValidator extends DescriptionValidator<DestroyOracleBMCSServerGroupDescription> {

@Override
void validate(List priorDescriptions, DestroyOracleBMCSServerGroupDescription description, Errors errors) {

def helper = new StandardOracleBMCSAttributeValidator("destroyServerGroupDescription", errors)

helper.validateNotEmptyString(description.accountName, "accountName")
helper.validateNotEmptyString(description.region, "region")
helper.validateNotEmptyString(description.serverGroupName, "serverGroupName")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2017 Oracle America, Inc.
*
* The contents of this file are subject to the Apache License Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* If a copy of the Apache License Version 2.0 was not distributed with this file,
* You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.html
*/
package com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.converter

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.description.DestroyOracleBMCSServerGroupDescription
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.op.DestroyOracleBMCSServerGroupAtomicOperation
import com.netflix.spinnaker.clouddriver.oraclebmcs.security.OracleBMCSNamedAccountCredentials
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsProvider
import spock.lang.Shared
import spock.lang.Specification

class DestroyOracleBMCSServerGroupAtomicOperationConverterUnitSpec extends Specification {

private static final SERVER_GROUP_NAME = "spinnaker-test-v000"
private static final ZONE = "us-central1-b"
private static final ACCOUNT_NAME = "auto"

@Shared
ObjectMapper mapper = new ObjectMapper()

@Shared
DestroyOracleBMCSServerGroupAtomicOperationConverter converter

def setupSpec() {
this.converter = new DestroyOracleBMCSServerGroupAtomicOperationConverter(objectMapper: mapper)
def accountCredentialsProvider = Mock(AccountCredentialsProvider)
def mockCredentials = Mock(OracleBMCSNamedAccountCredentials)
accountCredentialsProvider.getCredentials(_) >> mockCredentials
converter.accountCredentialsProvider = accountCredentialsProvider
}

def "return correct description and operation"() {
setup:
def input = [serverGroupName: SERVER_GROUP_NAME,
zone : ZONE,
accountName : ACCOUNT_NAME]

when:
def description = converter.convertDescription(input)

then:
description instanceof DestroyOracleBMCSServerGroupDescription

when:
def operation = converter.convertOperation(input)

then:
operation instanceof DestroyOracleBMCSServerGroupAtomicOperation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ResizeOracleBMCSServerGroupAtomicOperationConverterUnitSpec extends Specif

then:
operation instanceof ResizeOracleBMCSServerGroupAtomicOperation

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2017 Oracle America, Inc.
*
* The contents of this file are subject to the Apache License Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* If a copy of the Apache License Version 2.0 was not distributed with this file,
* You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.html
*/
package com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.op

import com.netflix.spinnaker.clouddriver.data.task.Task
import com.netflix.spinnaker.clouddriver.data.task.TaskRepository
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.description.DestroyOracleBMCSServerGroupDescription
import com.netflix.spinnaker.clouddriver.oraclebmcs.service.servergroup.OracleBMCSServerGroupService
import spock.lang.Specification

class DestroyOracleBMCSServerGroupAtomicOperationSpec extends Specification {

def "Triggers destroying of a server group"() {
setup:
def destroyDesc = new DestroyOracleBMCSServerGroupDescription()
destroyDesc.serverGroupName = "sg1"

TaskRepository.threadLocalTask.set(Mock(Task))
def sgService = Mock(OracleBMCSServerGroupService)
DestroyOracleBMCSServerGroupAtomicOperation op = new DestroyOracleBMCSServerGroupAtomicOperation(destroyDesc)
op.oracleBMCSServerGroupService = sgService

when:
op.operate(null)

then:
1 * sgService.destroyServerGroup(_, _, "sg1")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2017 Oracle America, Inc.
*
* The contents of this file are subject to the Apache License Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* If a copy of the Apache License Version 2.0 was not distributed with this file,
* You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.html
*/
package com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.validator

import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.description.DestroyOracleBMCSServerGroupDescription
import org.springframework.validation.Errors
import spock.lang.Shared
import spock.lang.Specification

class DestroyOracleBMCSServerGroupDescriptionValidatorSpec extends Specification {

@Shared
DestroyOracleBMCSServerGroupDescriptionValidator validator

void setupSpec() {
validator = new DestroyOracleBMCSServerGroupDescriptionValidator()
}

void "invalid description fails validation"() {
setup:
def description = new DestroyOracleBMCSServerGroupDescription()
def errors = Mock(Errors)

when:
validator.validate([], description, errors)

then:
1 * errors.rejectValue("accountName", "destroyServerGroupDescription.accountName.empty")
1 * errors.rejectValue("region", "destroyServerGroupDescription.region.empty")
1 * errors.rejectValue("serverGroupName", "destroyServerGroupDescription.serverGroupName.empty")
}

void "valid description passes validation"() {
setup:
def description = new DestroyOracleBMCSServerGroupDescription(
accountName: "DEFAULT",
region: "us-phoenix-1",
serverGroupName: "my-group-01"
)

def errors = Mock(Errors)

when:
validator.validate([], description, errors)

then:
0 * errors._
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ class ResizeOracleBMCSServerGroupDescriptionValidatorSpec extends Specification
0 * errors._
}
}

0 comments on commit 3e8faeb

Please sign in to comment.