use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient in project cloudbreak by hortonworks.
the class AwsAutoScalingService method scheduleStatusChecks.
public void scheduleStatusChecks(List<Group> groups, AuthenticatedContext ac, AmazonCloudFormationClient cloudFormationClient, Date timeBeforeASUpdate, List<String> knownInstances) throws AmazonAutoscalingFailed {
AmazonEc2Client amClient = awsClient.createEc2Client(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
AmazonAutoScalingClient asClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
for (Group group : groups) {
String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, cloudFormationClient, group.getName());
checkLastScalingActivity(asClient, asGroupName, timeBeforeASUpdate, group);
LOGGER.debug("Polling Auto Scaling group until new instances are ready. [stack: {}, asGroup: {}]", ac.getCloudContext().getId(), asGroupName);
waitForGroup(amClient, asClient, asGroupName, group.getInstancesSize(), ac.getCloudContext().getId(), knownInstances);
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient in project cloudbreak by hortonworks.
the class AwsDownscaleService method downscale.
public List<CloudResourceStatus> downscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vmsToDownscale) {
if (!vmsToDownscale.isEmpty()) {
List<String> instanceIdsToDownscale = new ArrayList<>();
for (CloudInstance vm : vmsToDownscale) {
instanceIdsToDownscale.add(vm.getInstanceId());
}
AwsCredentialView credentialView = new AwsCredentialView(auth.getCloudCredential());
AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(auth);
String regionName = authenticatedContextView.getRegion();
LOGGER.debug("Calling deleteCloudWatchAlarmsForSystemFailures from AwsDownscaleService");
awsCloudWatchService.deleteCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView, instanceIdsToDownscale);
List<CloudResource> resourcesToDownscale = resources.stream().filter(resource -> instanceIdsToDownscale.contains(resource.getInstanceId())).collect(Collectors.toList());
awsComputeResourceService.deleteComputeResources(auth, stack, resourcesToDownscale);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(credentialView, auth.getCloudContext().getLocation().getRegion().value());
AmazonEc2Client amazonEC2Client = awsClient.createEc2Client(credentialView, auth.getCloudContext().getLocation().getRegion().value());
Map<String, List<CloudInstance>> downscaledGroupsWithCloudInstances = vmsToDownscale.stream().collect(Collectors.groupingBy(cloudInstance -> cloudInstance.getTemplate().getGroupName()));
Long stackId = auth.getCloudContext().getId();
List<String> terminatedInstances = terminateInstances(auth, amazonASClient, amazonEC2Client, downscaledGroupsWithCloudInstances, stackId);
if (!terminatedInstances.isEmpty()) {
waitForTerminateInstances(stackId, terminatedInstances, amazonEC2Client);
}
updateAutoscalingGroups(auth, amazonASClient, downscaledGroupsWithCloudInstances);
List<String> targetGroupArns = getTargetGroupArns(stack.getLoadBalancers(), auth);
loadBalancerService.removeLoadBalancerTargets(auth, targetGroupArns, resourcesToDownscale);
}
return awsResourceConnector.check(auth, resources);
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient in project cloudbreak by hortonworks.
the class AwsLoadBalancerLaunchService method updateCloudformationWithLoadBalancers.
public List<CloudResourceStatus> updateCloudformationWithLoadBalancers(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier resourceNotifier, ModelContext modelContext) {
List<CloudResourceStatus> statuses = new ArrayList<>();
List<CloudLoadBalancer> cloudLoadBalancers = stack.getLoadBalancers();
String cFStackName = cfStackUtil.getCfStackName(ac);
if (!cloudLoadBalancers.isEmpty()) {
LOGGER.debug("Creating load balancers of types " + cloudLoadBalancers.stream().map(CloudLoadBalancer::getType).map(LoadBalancerType::name).collect(Collectors.joining(",")));
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient cfRetryClient = awsClient.createCloudFormationClient(credentialView, regionName);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(credentialView, regionName);
List<CloudResource> instances = cfStackUtil.getInstanceCloudResources(ac, cfRetryClient, amazonASClient, stack.getGroups());
Network network = stack.getNetwork();
AwsNetworkView awsNetworkView = new AwsNetworkView(network);
if (modelContext == null) {
LOGGER.debug("Creating default model context");
modelContext = awsModelService.buildDefaultModelContext(ac, stack, resourceNotifier);
}
Map<String, List<String>> instanceIdsByGroupName = instances.stream().collect(Collectors.groupingBy(CloudResource::getGroup, mapping(CloudResource::getInstanceId, toList())));
List<AwsLoadBalancer> awsLoadBalancers = loadBalancerCommonService.getAwsLoadBalancers(cloudLoadBalancers, instanceIdsByGroupName, awsNetworkView);
modelContext.withLoadBalancers(awsLoadBalancers);
LOGGER.debug("Starting CloudFormation update to create load balancer and target groups.");
ListStackResourcesResult result;
if (checkForLoadBalancerAndTargetGroupResources(cfRetryClient, cFStackName, awsLoadBalancers)) {
LOGGER.debug("Load balancer and target group resources already exist, skipping creation");
result = cfRetryClient.listStackResources(awsStackRequestHelper.createListStackResourcesRequest(cFStackName));
} else {
result = updateCloudFormationStack(ac, stack, modelContext);
}
setLoadBalancerMetadata(awsLoadBalancers, result);
LOGGER.debug("Starting CloudFormation update to create listeners.");
if (checkForListenerResources(cfRetryClient, cFStackName, awsLoadBalancers)) {
LOGGER.debug("Listener resources already exist, skipping creation");
result = cfRetryClient.listStackResources(awsStackRequestHelper.createListStackResourcesRequest(cFStackName));
} else {
result = updateCloudFormationStack(ac, stack, modelContext);
}
ListStackResourcesResult finalResult = result;
awsLoadBalancers.forEach(lb -> statuses.add(createLoadBalancerStatus(ac, lb, finalResult)));
} else {
LOGGER.debug("No load balancers in stack");
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient in project cloudbreak by hortonworks.
the class AwsMetadataCollector method collectInstancesForGroup.
public List<Instance> collectInstancesForGroup(AuthenticatedContext ac, AmazonAutoScalingClient amazonASClient, AmazonEc2Client amazonEC2Client, AmazonCloudFormationClient amazonCFClient, String group) {
LOGGER.debug("Collect aws instances for group: {}", group);
String asGroupName = cloudFormationStackUtil.getAutoscalingGroupName(ac, amazonCFClient, group);
List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(amazonASClient, asGroupName);
DescribeInstancesRequest instancesRequest = cloudFormationStackUtil.createDescribeInstancesRequest(instanceIds);
DescribeInstancesResult instancesResult = amazonEC2Client.describeInstances(instancesRequest);
return instancesResult.getReservations().stream().flatMap(reservation -> reservation.getInstances().stream()).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient in project cloudbreak by hortonworks.
the class AwsTerminateService method deleteLaunchConfiguration.
private void deleteLaunchConfiguration(List<CloudResource> resources, AuthenticatedContext ac) {
if (resources == null) {
return;
}
AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
resources.stream().filter(cloudResource -> cloudResource.getType() == ResourceType.AWS_LAUNCHCONFIGURATION).forEach(cloudResource -> autoScalingClient.deleteLaunchConfiguration(new DeleteLaunchConfigurationRequest().withLaunchConfigurationName(cloudResource.getName())));
}
Aggregations