-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider/oraclebmcs): Destroy server group operation (#1591)
- Loading branch information
Showing
9 changed files
with
274 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...r/oraclebmcs/deploy/converter/DestroyOracleBMCSServerGroupAtomicOperationConverter.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../clouddriver/oraclebmcs/deploy/description/DestroyOracleBMCSServerGroupDescription.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
42 changes: 42 additions & 0 deletions
42
...naker/clouddriver/oraclebmcs/deploy/op/DestroyOracleBMCSServerGroupAtomicOperation.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...river/oraclebmcs/deploy/validator/DestroyOracleBMCSServerGroupDescriptionValidator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...bmcs/deploy/converter/DestroyOracleBMCSServerGroupAtomicOperationConverterUnitSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...r/clouddriver/oraclebmcs/deploy/op/DestroyOracleBMCSServerGroupAtomicOperationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...r/oraclebmcs/deploy/validator/DestroyOracleBMCSServerGroupDescriptionValidatorSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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._ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,4 +52,3 @@ class ResizeOracleBMCSServerGroupDescriptionValidatorSpec extends Specification | |
0 * errors._ | ||
} | ||
} | ||
|