use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsSetup method prerequisites.
@Override
public void prerequisites(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier persistenceNotifier) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String region = ac.getCloudContext().getLocation().getRegion().value();
verifySpotInstances(stack);
if (awsNetworkView.isExistingVPC()) {
try {
AmazonEc2Client amazonEC2Client = new AuthenticatedContextView(ac).getAmazonEC2Client();
validateExistingIGW(awsNetworkView, amazonEC2Client);
validateExistingSubnet(awsNetworkView, amazonEC2Client);
} catch (AmazonServiceException e) {
throw new CloudConnectorException(e.getErrorMessage());
} catch (AmazonClientException e) {
throw new CloudConnectorException(e.getMessage());
}
}
validateRegionAndZone(ac.getCloudCredential(), ac.getCloudContext().getLocation());
validateExistingKeyPair(stack.getInstanceAuthentication(), credentialView, region, ac);
LOGGER.debug("setup has been executed");
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsLaunchTemplateUpdateService method updateFields.
public void updateFields(AuthenticatedContext authenticatedContext, String stackName, Map<LaunchTemplateField, String> updatableFields, boolean dryRun) {
AwsCredentialView credentialView = new AwsCredentialView(authenticatedContext.getCloudCredential());
String regionName = authenticatedContext.getCloudContext().getLocation().getRegion().getRegionName();
AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName);
AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(credentialView, regionName);
AmazonEc2Client ec2Client = awsClient.createEc2Client(credentialView, regionName);
Map<AutoScalingGroup, String> autoScalingGroups = autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, stackName);
autoScalingGroups = filterGroupsForDryRun(autoScalingGroups, dryRun);
LOGGER.debug("Modifying the {} fields for the [{}] autoscaling groups' launchtemplates [dryrun: {}]", updatableFields, autoScalingGroups.values(), dryRun);
for (Map.Entry<AutoScalingGroup, String> asgEntry : autoScalingGroups.entrySet()) {
AutoScalingGroup autoScalingGroup = asgEntry.getKey();
LOGGER.debug("Creating new launchtemplate version for [{}] autoscale group...", autoScalingGroup.getAutoScalingGroupName());
LaunchTemplateSpecification launchTemplateSpecification = getLaunchTemplateSpecification(autoScalingGroup);
CreateLaunchTemplateVersionResult createLaunchTemplateVersionResult = getCreateLaunchTemplateVersionRequest(ec2Client, updatableFields, launchTemplateSpecification);
modifyLaunchTemplate(ec2Client, launchTemplateSpecification, createLaunchTemplateVersionResult, !dryRun);
if (dryRun) {
LOGGER.debug("Autoscale group update will be skipped because of dryrun, which just test the permissions for modifiying the launch template.");
} else {
updateAutoScalingGroup(updatableFields, autoScalingClient, autoScalingGroup, launchTemplateSpecification, createLaunchTemplateVersionResult);
}
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsMetadataCollector method collectCloudVmMetaDataStatuses.
private List<CloudVmMetaDataStatus> collectCloudVmMetaDataStatuses(AuthenticatedContext ac, List<CloudInstance> vms, List<CloudResource> resources, List<String> knownInstanceIdList) {
LOGGER.debug("Collect Cloud VM metadata statuses");
List<CloudVmMetaDataStatus> collectedCloudVmMetaDataStatuses = new ArrayList<>();
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient amazonCFClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), region);
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), region);
AmazonEc2Client amazonEC2Client = new AuthenticatedContextView(ac).getAmazonEC2Client();
Multimap<String, CloudInstance> instanceGroupMap = getInstanceGroupMap(vms);
Set<String> subnetIds = new HashSet<>();
Multimap<String, Instance> instancesOnAWSForGroup = ArrayListMultimap.create();
for (String group : instanceGroupMap.keySet()) {
List<Instance> instancesForGroup = collectInstancesForGroup(ac, amazonASClient, amazonEC2Client, amazonCFClient, group);
LOGGER.info("Collected instances for group: {}", instancesForGroup.stream().map(Instance::getInstanceId).collect(Collectors.joining(",")));
instancesOnAWSForGroup.putAll(group, instancesForGroup);
subnetIds.addAll(getSubnetIdsForInstances(instancesForGroup));
}
LOGGER.info("Collected subnet IDs: {}", subnetIds);
Map<String, String> subnetIdToAvailabilityZoneMap = buildSubnetIdToAvailabilityZoneMap(subnetIds, amazonEC2Client);
LOGGER.info("Subnet id to availability zone map: {}", subnetIdToAvailabilityZoneMap);
Multimap<String, Instance> unknownInstancesForGroup = getUnknownInstancesForGroup(knownInstanceIdList, instancesOnAWSForGroup);
for (CloudInstance vm : vms) {
if (vm.getInstanceId() == null) {
addFromUnknownMap(vm, resources, unknownInstancesForGroup, collectedCloudVmMetaDataStatuses, subnetIdToAvailabilityZoneMap);
} else {
addKnownInstance(vm, instancesOnAWSForGroup, collectedCloudVmMetaDataStatuses, subnetIdToAvailabilityZoneMap);
}
}
LOGGER.info("Collected cloud VM metadata and statuses: {}", collectedCloudVmMetaDataStatuses);
return collectedCloudVmMetaDataStatuses;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNetworkConnector method getCloudSubNets.
private List<SubnetRequest> getCloudSubNets(NetworkCreationRequest networkRequest) {
AwsCredentialView awsCredential = new AwsCredentialView(networkRequest.getCloudCredential());
AmazonEc2Client awsClientAccess = awsClient.createEc2Client(awsCredential, networkRequest.getRegion().value());
return awsSubnetRequestProvider.provide(awsClientAccess, new ArrayList<>(networkRequest.getPublicSubnets()), new ArrayList<>(networkRequest.getPrivateSubnets()));
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsStackRequestHelper method getRootDeviceName.
private String getRootDeviceName(AuthenticatedContext ac, CloudStack cloudStack) {
AmazonEc2Client ec2Client = new AuthenticatedContextView(ac).getAmazonEC2Client();
DescribeImagesResult images = ec2Client.describeImages(new DescribeImagesRequest().withImageIds(cloudStack.getImage().getImageName()));
if (images.getImages().isEmpty()) {
throw new CloudConnectorException(String.format("AMI is not available: '%s'.", cloudStack.getImage().getImageName()));
}
Image image = images.getImages().get(0);
if (image == null) {
throw new CloudConnectorException(String.format("Couldn't describe AMI '%s'.", cloudStack.getImage().getImageName()));
}
return image.getRootDeviceName();
}
Aggregations