-
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): Resize server group operation (#1590)
- Loading branch information
Showing
12 changed files
with
343 additions
and
9 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
...er/oraclebmcs/deploy/converter/ResizeOracleBMCSServerGroupAtomicOperationConverter.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,32 @@ | ||
/* | ||
* 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.ResizeOracleBMCSServerGroupDescription | ||
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.op.ResizeOracleBMCSServerGroupAtomicOperation | ||
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation | ||
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperations | ||
import com.netflix.spinnaker.clouddriver.security.AbstractAtomicOperationsCredentialsSupport | ||
import org.springframework.stereotype.Component | ||
|
||
@OracleBMCSOperation(AtomicOperations.RESIZE_SERVER_GROUP) | ||
@Component("resizeOracleBMCSServerGroupDescription") | ||
class ResizeOracleBMCSServerGroupAtomicOperationConverter extends AbstractAtomicOperationsCredentialsSupport { | ||
|
||
@Override | ||
AtomicOperation convertOperation(Map input) { | ||
new ResizeOracleBMCSServerGroupAtomicOperation(convertDescription(input)) | ||
} | ||
|
||
@Override | ||
ResizeOracleBMCSServerGroupDescription convertDescription(Map input) { | ||
OracleBMCSAtomicOperationConverterHelper.convertDescription(input, this, ResizeOracleBMCSServerGroupDescription) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...r/clouddriver/oraclebmcs/deploy/description/ResizeOracleBMCSServerGroupDescription.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,21 @@ | ||
/* | ||
* 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 com.netflix.spinnaker.clouddriver.model.ServerGroup | ||
import groovy.transform.ToString | ||
|
||
@ToString(includeNames = true) | ||
class ResizeOracleBMCSServerGroupDescription extends AbstractOracleBMCSCredentialsDescription { | ||
|
||
String accountName | ||
String region | ||
String serverGroupName | ||
ServerGroup.Capacity capacity = new ServerGroup.Capacity() | ||
} |
42 changes: 42 additions & 0 deletions
42
...nnaker/clouddriver/oraclebmcs/deploy/op/ResizeOracleBMCSServerGroupAtomicOperation.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.ResizeOracleBMCSServerGroupDescription | ||
import com.netflix.spinnaker.clouddriver.oraclebmcs.service.servergroup.OracleBMCSServerGroupService | ||
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
class ResizeOracleBMCSServerGroupAtomicOperation implements AtomicOperation<Void> { | ||
|
||
private final ResizeOracleBMCSServerGroupDescription description | ||
|
||
private static final String BASE_PHASE = "RESIZE_SERVER_GROUP" | ||
|
||
private static Task getTask() { | ||
TaskRepository.threadLocalTask.get() | ||
} | ||
|
||
@Autowired | ||
OracleBMCSServerGroupService oracleBMCSServerGroupService | ||
|
||
ResizeOracleBMCSServerGroupAtomicOperation(ResizeOracleBMCSServerGroupDescription description) { | ||
this.description = description | ||
} | ||
|
||
@Override | ||
Void operate(List priorOutputs) { | ||
task.updateStatus BASE_PHASE, "Resizing server group: " + description.serverGroupName | ||
oracleBMCSServerGroupService.resizeServerGroup(task, description.credentials, description.serverGroupName, description.capacity.desired) | ||
task.updateStatus BASE_PHASE, "Completed server group resize" | ||
return null | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...driver/oraclebmcs/deploy/validator/ResizeOracleBMCSServerGroupDescriptionValidator.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,30 @@ | ||
/* | ||
* 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.ResizeOracleBMCSServerGroupDescription | ||
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperations | ||
import org.springframework.stereotype.Component | ||
import org.springframework.validation.Errors | ||
|
||
@OracleBMCSOperation(AtomicOperations.RESIZE_SERVER_GROUP) | ||
@Component("resizeOracleBMCSServerGroupDescriptionValidator") | ||
class ResizeOracleBMCSServerGroupDescriptionValidator extends DescriptionValidator<ResizeOracleBMCSServerGroupDescription> { | ||
|
||
@Override | ||
void validate(List priorDescriptions, ResizeOracleBMCSServerGroupDescription description, Errors errors) { | ||
def helper = new StandardOracleBMCSAttributeValidator("resizeServerGroupDescription", errors) | ||
|
||
helper.validateNotEmptyString(description.serverGroupName, "serverGroupName") | ||
helper.validateNotEmptyString(description.region, "region") | ||
helper.validateNotEmptyString(description.accountName, "accountName") | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...naker/clouddriver/oraclebmcs/deploy/validator/StandardOracleBMCSAttributeValidator.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,30 @@ | ||
/* | ||
* 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 org.springframework.validation.Errors | ||
|
||
class StandardOracleBMCSAttributeValidator { | ||
|
||
String context | ||
Errors errors | ||
|
||
StandardOracleBMCSAttributeValidator(String context, Errors errors) { | ||
this.context = context | ||
this.errors = errors | ||
} | ||
|
||
def validateNotEmptyString(String value, String attribute) { | ||
if (!value) { | ||
errors.rejectValue(attribute, "${context}.${attribute}.empty") | ||
return false | ||
} | ||
return true | ||
} | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
...ebmcs/deploy/converter/ResizeOracleBMCSServerGroupAtomicOperationConverterUnitSpec.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,60 @@ | ||
/* | ||
* 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.ResizeOracleBMCSServerGroupDescription | ||
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.op.ResizeOracleBMCSServerGroupAtomicOperation | ||
import com.netflix.spinnaker.clouddriver.oraclebmcs.security.OracleBMCSNamedAccountCredentials | ||
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsProvider | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
class ResizeOracleBMCSServerGroupAtomicOperationConverterUnitSpec extends Specification { | ||
|
||
private static final SERVER_GROUP_NAME = "spinnaker-test-v000" | ||
private static final TARGET_SIZE = 5 | ||
private static final REGION = "us-central1" | ||
private static final ZONE = "us-central1-b" | ||
private static final ACCOUNT_NAME = "auto" | ||
|
||
@Shared | ||
ObjectMapper mapper = new ObjectMapper() | ||
|
||
void "resizeOracleBMCSServerGroupDescription type returns ResizeOracleBMCSServerGroupDescription and ResizeOracleBMCSServerGroupAtomicOperation"() { | ||
setup: | ||
def input = [serverGroupName: SERVER_GROUP_NAME, | ||
targetSize : TARGET_SIZE, | ||
region : REGION, | ||
zone : ZONE, | ||
accountName : ACCOUNT_NAME] | ||
|
||
ResizeOracleBMCSServerGroupAtomicOperationConverter converter = | ||
new ResizeOracleBMCSServerGroupAtomicOperationConverter(objectMapper: mapper) | ||
|
||
def accountCredentialsProvider = Mock(AccountCredentialsProvider) | ||
def mockCredentials = Mock(OracleBMCSNamedAccountCredentials) | ||
accountCredentialsProvider.getCredentials(_) >> mockCredentials | ||
converter.accountCredentialsProvider = accountCredentialsProvider | ||
|
||
when: | ||
def description = converter.convertDescription(input) | ||
|
||
then: | ||
description instanceof ResizeOracleBMCSServerGroupDescription | ||
|
||
when: | ||
def operation = converter.convertOperation(input) | ||
|
||
then: | ||
operation instanceof ResizeOracleBMCSServerGroupAtomicOperation | ||
|
||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...er/clouddriver/oraclebmcs/deploy/op/ResizeOracleBMCSServerGroupAtomicOperationSpec.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,37 @@ | ||
/* | ||
* 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.model.ServerGroup | ||
import com.netflix.spinnaker.clouddriver.oraclebmcs.deploy.description.ResizeOracleBMCSServerGroupDescription | ||
import com.netflix.spinnaker.clouddriver.oraclebmcs.service.servergroup.OracleBMCSServerGroupService | ||
import spock.lang.Specification | ||
|
||
class ResizeOracleBMCSServerGroupAtomicOperationSpec extends Specification { | ||
|
||
def "Resize server group"() { | ||
setup: | ||
def resizeDesc = new ResizeOracleBMCSServerGroupDescription() | ||
resizeDesc.serverGroupName = "sg1" | ||
resizeDesc.capacity = new ServerGroup.Capacity(desired: 3) | ||
|
||
TaskRepository.threadLocalTask.set(Mock(Task)) | ||
def sgService = Mock(OracleBMCSServerGroupService) | ||
ResizeOracleBMCSServerGroupAtomicOperation op = new ResizeOracleBMCSServerGroupAtomicOperation(resizeDesc) | ||
op.oracleBMCSServerGroupService = sgService | ||
|
||
when: | ||
op.operate(null) | ||
|
||
then: | ||
1 * sgService.resizeServerGroup(_, _, "sg1", 3) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...er/oraclebmcs/deploy/validator/ResizeOracleBMCSServerGroupDescriptionValidatorSpec.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.ResizeOracleBMCSServerGroupDescription | ||
import org.springframework.validation.Errors | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
class ResizeOracleBMCSServerGroupDescriptionValidatorSpec extends Specification { | ||
|
||
@Shared ResizeOracleBMCSServerGroupDescriptionValidator validator | ||
|
||
void setupSpec() { | ||
validator = new ResizeOracleBMCSServerGroupDescriptionValidator() | ||
} | ||
|
||
void "invalid description fails validation"() { | ||
setup: | ||
def description = new ResizeOracleBMCSServerGroupDescription() | ||
def errors = Mock(Errors) | ||
|
||
when: | ||
validator.validate([], description, errors) | ||
|
||
then: | ||
1 * errors.rejectValue("serverGroupName", "resizeServerGroupDescription.serverGroupName.empty") | ||
1 * errors.rejectValue("region", "resizeServerGroupDescription.region.empty") | ||
1 * errors.rejectValue("accountName", "resizeServerGroupDescription.accountName.empty") | ||
} | ||
|
||
void "pass validation with proper description inputs"() { | ||
setup: | ||
def description = new ResizeOracleBMCSServerGroupDescription( | ||
serverGroupName: "spinnaker-test-v000", | ||
region: "us-phoenix-1", | ||
accountName: "DEFAULT" | ||
) | ||
|
||
def errors = Mock(Errors) | ||
|
||
when: | ||
validator.validate([], description, errors) | ||
|
||
then: | ||
0 * errors._ | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
...r/clouddriver/oraclebmcs/deploy/validator/StandardOracleBMCSAttributeValidatorSpec.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,36 @@ | ||
/* | ||
* 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 org.springframework.validation.Errors | ||
import spock.lang.Specification | ||
|
||
class StandardOracleBMCSAttributeValidatorSpec extends Specification { | ||
|
||
void "validateNotEmptyString ok"() { | ||
setup: | ||
def errors = Mock(Errors) | ||
def validator = new StandardOracleBMCSAttributeValidator("context", errors) | ||
|
||
when: | ||
validator.validateNotEmptyString("DEFAULT", "accountName") | ||
then: | ||
0 * errors._ | ||
|
||
when: | ||
validator.validateNotEmptyString("", "accountName") | ||
then: | ||
1 * errors._ | ||
|
||
when: | ||
validator.validateNotEmptyString(null, "accountName") | ||
then: | ||
1 * errors._ | ||
} | ||
} |