use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView 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.view.AuthenticatedContextView 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.view.AuthenticatedContextView 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();
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView in project cloudbreak by hortonworks.
the class AwsTerminateService method terminate.
public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) {
LOGGER.debug("Deleting stack: {}", ac.getCloudContext().getId());
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(ac);
String regionName = authenticatedContextView.getRegion();
AmazonEc2Client amazonEC2Client = authenticatedContextView.getAmazonEC2Client();
AmazonCloudFormationClient amazonCloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName);
LOGGER.debug("Calling deleteCloudWatchAlarmsForSystemFailures from AwsTerminateService");
awsCloudWatchService.deleteAllCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView);
waitAndDeleteCloudformationStack(ac, stack, resources, amazonCloudFormationClient);
awsComputeResourceService.deleteComputeResources(ac, stack, resources);
deleteKeyPair(ac, stack, amazonEC2Client, credentialView, regionName);
deleteLaunchConfiguration(resources, ac);
LOGGER.debug("Deleting stack finished");
return awsResourceConnector.check(ac, resources);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AuthenticatedContextView in project cloudbreak by hortonworks.
the class AwsInstanceConnector method checkWithoutRetry.
@Override
public List<CloudVmInstanceStatus> checkWithoutRetry(AuthenticatedContext ac, List<CloudInstance> vms) {
LOGGER.debug("Check instances on aws side: {}", vms);
List<CloudInstance> cloudInstancesWithInstanceId = vms.stream().filter(cloudInstance -> cloudInstance.getInstanceId() != null).collect(Collectors.toList());
LOGGER.debug("Instances with instanceId: {}", cloudInstancesWithInstanceId);
List<String> instanceIds = cloudInstancesWithInstanceId.stream().map(CloudInstance::getInstanceId).collect(Collectors.toList());
String region = ac.getCloudContext().getLocation().getRegion().value();
try {
DescribeInstancesResult result = new AuthenticatedContextView(ac).getAmazonEC2Client().describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds));
LOGGER.debug("Result from AWS: {}", result);
return fillCloudVmInstanceStatuses(ac, cloudInstancesWithInstanceId, region, result);
} catch (AmazonEC2Exception e) {
handleEC2Exception(vms, e);
} catch (SdkClientException e) {
LOGGER.warn("Failed to send request to AWS: ", e);
throw e;
}
return Collections.emptyList();
}
Aggregations