Skip to content

Commit

Permalink
fix(source resolver): prefer older servergroup when copying capacity (#…
Browse files Browse the repository at this point in the history
…3161)

If there are multiple possible server groups to choose as the source,
and all are of the same size, prefer the older server group.

This supports a use case where multiple simultaneous clone operations
are performed against a single source (the intention is to have
multiple active server groups in the region). Because a server group
can have its capacity manipulated during the deploy lifecycle, we
don't want the second deploy to choose the first deploy as its source
and result in snapshotting a capacity that may have had the min
size pinned high
  • Loading branch information
cfieber authored Sep 17, 2019
1 parent 725db2b commit b36a248
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ class SourceResolver {
regionalAsgs = onlyEnabled
}

def instanceSize = { Map asg -> (asg.instances as Collection)?.size() ?: 0 }
def created = { Map asg -> asg.createdTime as Long ?: 0 }
if (stageData.useSourceCapacity) {
regionalAsgs = regionalAsgs.sort { a1, a2 -> instanceSize(a1) <=> instanceSize(a2) ?: created(a2) <=> created(a1) }
}
//with useSourceCapacity prefer the largest ASG over the newest ASG
def latestAsg = stageData.useSourceCapacity ? regionalAsgs.sort { (it.instances as Collection)?.size() ?: 0 }.last() : regionalAsgs.last()
def latestAsg = regionalAsgs.last()
return new StageData.Source(
account: stageData.account, region: latestAsg["region"] as String, asgName: latestAsg["name"] as String, serverGroupName: latestAsg["name"] as String
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,64 @@ class SourceResolverSpec extends Specification {
existing*.name == ['foo-test-v999', 'foo-test-v000', 'foo-test-v000', 'foo-test-v001']
}

void 'should prefer the largest oldest enabled server group'() {
given:
OortService oort = Mock(OortService)
SourceResolver resolver = new SourceResolver(oortService: oort, mapper: new ObjectMapper(), resolver: Mock(TargetServerGroupResolver))

when:
def source = resolver.getSource(stage)

then:
1 * oort.getCluster('foo', 'test', 'foo-test', 'aws') >> new Response('http://oort.com', 200, 'Okay', [], new TypedString(serverGroups))
source != null

source.serverGroupName == "foo-test-v000"
source.account == 'test'
source.region == "us-west-1"

where:
stage = new Stage(
Execution.newPipeline("orca"),
"test",
[
application: "foo",
stack: "test",
credentials: "test",
region: "us-west-1",
useSourceCapacity: true
]
)

serverGroups = '''\
{
"serverGroups": [{
"name": "foo-test-v001",
"region": "us-west-1",
"createdTime": 4,
"disabled": false,
"instances": [ 1, 2, 3 ]
},{
"name": "foo-test-v000",
"region": "us-west-1",
"disabled": false,
"instances": [ 1, 2, 3 ],
"createdTime": 3
},{
"name": "foo-test-v000",
"region": "us-east-1",
"disabled": false,
"instances": [ 1, 2, 3 ],
"createdTime": 2
},{
"name": "foo-test-v999",
"region": "us-east-1",
"disabled": false,
"instances": [ 1, 2, 3 ],
"createdTime": 1
}]
}'''.stripIndent()

}

}

0 comments on commit b36a248

Please sign in to comment.