AwsTemplate awsTemplate = (AwsTemplate) stack.getTemplate();
AwsCredential awsCredential = (AwsCredential) stack.getCredential();
AmazonCloudFormationClient amazonCFClient = awsStackUtil.createCloudFormationClient(awsTemplate.getRegion(), awsCredential);
AmazonAutoScalingClient amazonASClient = awsStackUtil.createAutoScalingClient(awsTemplate.getRegion(), awsCredential);
AmazonEC2Client amazonEC2Client = awsStackUtil.createEC2Client(awsTemplate.getRegion(), awsCredential);
List<String> instanceIds = cfStackUtil.getInstanceIds(stack, amazonASClient, amazonCFClient);
// If spot priced instances are used, CloudFormation signals completion
// when the spot requests are made but the instances are not running
// yet, so we will have to wait until the spot requests are fulfilled
// (there are as many instances in the ASG as needed)
if (awsTemplate.getSpotPrice() != null) {
while (instanceIds.size() < stack.getNodeCount()) {
LOGGER.info("Spot requests for stack '{}' are not fulfilled yet. Trying to reach instances in the next polling interval.", stack.getId());
awsStackUtil.sleep(stack, POLLING_INTERVAL);
instanceIds = cfStackUtil.getInstanceIds(stack, amazonASClient, amazonCFClient);
}
}
DescribeInstancesRequest instancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceIds);
DescribeInstancesResult instancesResult = amazonEC2Client.describeInstances(instancesRequest);
for (Reservation reservation : instancesResult.getReservations()) {
for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) {
coreInstanceMetadata.add(new CoreInstanceMetaData(
instance.getInstanceId(),
instance.getPrivateIpAddress(),