use of com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest in project cloudbreak by hortonworks.
the class AwsResourceConnector method resumeAutoScalingPolicies.
private void resumeAutoScalingPolicies(AuthenticatedContext ac, CloudStack stack) {
for (Group instanceGroup : stack.getGroups()) {
try {
String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, instanceGroup.getName(), ac.getCloudContext().getLocation().getRegion().value());
if (asGroupName != null) {
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
List<AutoScalingGroup> asGroups = amazonASClient.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asGroupName)).getAutoScalingGroups();
if (!asGroups.isEmpty()) {
if (!asGroups.get(0).getSuspendedProcesses().isEmpty()) {
amazonASClient.updateAutoScalingGroup(new UpdateAutoScalingGroupRequest().withAutoScalingGroupName(asGroupName).withMinSize(0).withDesiredCapacity(0));
amazonASClient.resumeProcesses(new ResumeProcessesRequest().withAutoScalingGroupName(asGroupName));
}
}
} else {
LOGGER.info("Autoscaling Group's physical id is null (the resource doesn't exist), it is not needed to resume scaling policies.");
}
} catch (AmazonServiceException e) {
if (e.getErrorMessage().matches("Resource.*does not exist for stack.*") || e.getErrorMessage().matches("Stack '.*' does not exist.*")) {
LOGGER.info(e.getMessage());
} else {
throw e;
}
}
}
}
use of com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest in project cloudbreak by hortonworks.
the class AwsResourceConnector method upscale.
@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) {
resumeAutoScaling(ac, stack);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
List<Group> scaledGroups = getScaledGroups(stack);
for (Group group : scaledGroups) {
String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, cloudFormationClient, group.getName());
amazonASClient.updateAutoScalingGroup(new UpdateAutoScalingGroupRequest().withAutoScalingGroupName(asGroupName).withMaxSize(group.getInstancesSize()).withDesiredCapacity(group.getInstancesSize()));
LOGGER.info("Updated Auto Scaling group's desiredCapacity: [stack: '{}', to: '{}']", ac.getCloudContext().getId(), resources.size());
}
scheduleStatusChecks(stack, ac, cloudFormationClient);
suspendAutoScaling(ac, stack);
boolean mapPublicIpOnLaunch = isMapPublicOnLaunch(new AwsNetworkView(stack.getNetwork()), amazonEC2Client);
List<Group> gateways = getGatewayGroups(scaledGroups);
if (mapPublicIpOnLaunch && !gateways.isEmpty()) {
String cFStackName = getCloudFormationStackResource(resources).getName();
Map<String, String> eipAllocationIds = getElasticIpAllocationIds(cFStackName, cloudFormationClient);
for (Group gateway : gateways) {
List<String> eips = getEipsForGatewayGroup(eipAllocationIds, gateway);
List<String> freeEips = getFreeIps(eips, amazonEC2Client);
List<String> instanceIds = getInstancesForGroup(ac, amazonASClient, cloudFormationClient, gateway);
List<String> newInstances = instanceIds.stream().filter(iid -> gateway.getInstances().stream().noneMatch(inst -> iid.equals(inst.getInstanceId()))).collect(Collectors.toList());
associateElasticIpsToInstances(amazonEC2Client, freeEips, newInstances);
}
}
return singletonList(new CloudResourceStatus(getCloudFormationStackResource(resources), ResourceStatus.UPDATED));
}
Aggregations