Skip to content

Commit

Permalink
fix(resize): Support both 'asgName' and 'serverGroupName' (#2071)
Browse files Browse the repository at this point in the history
Noticed the inconsistency when investigating a recent `orca` issue.

It would be nice to standardize on `serverGroupName` but we still have
operations (like this one!) expecting `asgName`.
  • Loading branch information
ajordens committed Mar 22, 2018
1 parent 18a9b26 commit 50710ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ResizeServerGroupStage extends TargetServerGroupLinearStageSupport {
it.name = "resumeScalingProcesses"
it.type = ModifyAwsScalingProcessStage.TYPE
it.context = [
serverGroupName: descriptor.asgName,
serverGroupName: getServerGroupName(descriptor),
cloudProvider : descriptor.cloudProvider,
credentials : descriptor.credentials,
region : descriptor.region,
Expand All @@ -74,7 +74,7 @@ class ResizeServerGroupStage extends TargetServerGroupLinearStageSupport {
it.name = "suspendScalingProcesses"
it.type = ModifyAwsScalingProcessStage.TYPE
it.context = [
serverGroupName: descriptor.asgName,
serverGroupName: getServerGroupName(descriptor),
cloudProvider : descriptor.cloudProvider,
credentials : descriptor.credentials,
region : descriptor.region,
Expand All @@ -87,7 +87,7 @@ class ResizeServerGroupStage extends TargetServerGroupLinearStageSupport {
@Override
protected void preDynamic(Map<String, Object> context, StageGraphBuilder graph) {
if (context.cloudProvider == "aws") {
context.remove("asgName")
context = removeServerGroupName(context)
graph.add {
it.name = "resumeScalingProcesses"
it.type = ModifyAwsScalingProcessStage.TYPE
Expand All @@ -101,7 +101,7 @@ class ResizeServerGroupStage extends TargetServerGroupLinearStageSupport {
@Override
protected void postDynamic(Map<String, Object> context, StageGraphBuilder graph) {
if (context.cloudProvider == "aws") {
context.remove("asgName")
context = removeServerGroupName(context)
graph.add {
it.name = "suspendScalingProcesses"
it.type = ModifyAwsScalingProcessStage.TYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ abstract class TargetServerGroupLinearStageSupport implements StageDefinitionBui
return type
}

protected String getServerGroupName(Map<String, Object> context) {
return context.serverGroupName ?: context.asgName
}

public Map<String, Object> removeServerGroupName(Map<String, Object> context) {
def copyOfContext = new HashMap(context)

copyOfContext.remove("serverGroupName")
copyOfContext.remove("asgName")

return copyOfContext
}

@Override
final void taskGraph(Stage stage, TaskNode.Builder builder) {
if (!isTopLevel(stage)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ class TargetServerGroupLinearStageSupportSpec extends Specification {
"current_asg_dynamic" | ["preDynamic"] | ["postDynamic"]
}

def "should support 'asgName' and 'serverGroupName' when extracting server group name from context"() {
expect:
supportStage.getServerGroupName([:]) == null
supportStage.getServerGroupName([asgName: "asgName"]) == "asgName"
supportStage.getServerGroupName([serverGroupName: "serverGroupName"]) == "serverGroupName"

supportStage.getServerGroupName([asgName: "asgName", serverGroupName: "serverGroupName"]) == "serverGroupName"
}

def "should remove 'asgName' and 'serverGroupName' when removing server group name from context"() {
expect:
supportStage.removeServerGroupName([:]) == [:]
supportStage.removeServerGroupName([foo: "bar", asgName: "asgName"]) == [foo: "bar"]
supportStage.removeServerGroupName([foo: "bar", serverGroupName: "serverGroupName"]) == [foo: "bar"]
supportStage.removeServerGroupName([foo: "bar", asgName: "asgName", serverGroupName: "serverGroupName"]) == [foo: "bar"]
}

class TestSupport extends TargetServerGroupLinearStageSupport {
@Override
void preStatic(Map<String, Object> descriptor, StageGraphBuilder graph) {
Expand Down

0 comments on commit 50710ea

Please sign in to comment.