use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsMetadataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) {
List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
try {
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 = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region);
// contains all instances
ListMultimap<String, CloudInstance> groupByInstanceGroup = groupByInstanceGroup(vms);
for (String key : groupByInstanceGroup.keySet()) {
List<CloudInstance> cloudInstances = groupByInstanceGroup.get(key);
cloudVmMetaDataStatuses.addAll(collectGroupMetaData(ac, amazonASClient, amazonEC2Client, amazonCFClient, key, cloudInstances));
}
return cloudVmMetaDataStatuses;
} catch (RuntimeException e) {
throw new CloudConnectorException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView in project cloudbreak by hortonworks.
the class EncryptedSnapshotPreparator method createSnapshotIfNeeded.
public Optional<String> createSnapshotIfNeeded(AuthenticatedContext ac, Group group) {
InstanceTemplate instanceTemplate = group.getReferenceInstanceConfiguration().getTemplate();
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AwsInstanceView awsInstanceView = new AwsInstanceView(instanceTemplate);
AwsCredentialView awsCredentialView = new AwsCredentialView(ac.getCloudCredential());
AmazonEC2Client client = awsClient.createAccess(awsCredentialView, regionName);
Optional<String> snapshotId = checkThatSnapshotIsAvailable(awsInstanceView, client);
return snapshotId.isPresent() ? snapshotId : prepareSnapshotForEncryptionBecauseThatDoesNotExist(ac, awsInstanceView, client);
}
use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView in project cloudbreak by hortonworks.
the class ASGroupStatusCheckerTask method doCall.
@Override
protected Boolean doCall() {
LOGGER.info("Checking status of Auto Scaling group '{}'", autoScalingGroupName);
AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(getAuthenticatedContext().getCloudCredential()), getAuthenticatedContext().getCloudContext().getLocation().getRegion().value());
List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(autoScalingClient, autoScalingGroupName);
if (instanceIds.size() < requiredInstances) {
LOGGER.debug("Instances in AS group: {}, needed: {}", instanceIds.size(), requiredInstances);
List<Activity> activities = getAutoScalingActivities();
if (latestActivity.isPresent()) {
checkForSpotRequest(latestActivity.get(), amazonEC2Client);
activities = activities.stream().filter(activity -> activity.getStartTime().after(latestActivity.get().getStartTime())).collect(Collectors.toList());
}
updateLatestActivity(activities);
checkFailedActivities(activities);
return false;
}
Collection<DescribeInstanceStatusResult> describeInstanceStatusResultList = new ArrayList<>();
List<List<String>> partitionedInstanceIdsList = Lists.partition(instanceIds, MAX_INSTANCE_ID_SIZE);
for (List<String> partitionedInstanceIds : partitionedInstanceIdsList) {
DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withInstanceIds(partitionedInstanceIds);
DescribeInstanceStatusResult describeResult = amazonEC2Client.describeInstanceStatus(describeInstanceStatusRequest);
describeInstanceStatusResultList.add(describeResult);
}
List<InstanceStatus> instanceStatusList = describeInstanceStatusResultList.stream().flatMap(describeInstanceStatusResult -> describeInstanceStatusResult.getInstanceStatuses().stream()).collect(Collectors.toList());
if (instanceStatusList.size() < requiredInstances) {
LOGGER.debug("Instances up: {}, needed: {}", instanceStatusList.size(), requiredInstances);
return false;
}
for (InstanceStatus status : instanceStatusList) {
if (INSTANCE_RUNNING != status.getInstanceState().getCode()) {
LOGGER.debug("Instances are up but not all of them are in running state.");
return false;
}
}
return true;
}
Aggregations