use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method getResourceArnByLogicalId.
public String getResourceArnByLogicalId(AuthenticatedContext ac, String logicalId, String region) {
String cFStackName = getCfStackName(ac);
AmazonCloudFormationClient amazonCfClient = awsClient.createCloudFormationClient(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeStackResourceResult result = amazonCfClient.describeStackResource(new DescribeStackResourceRequest().withStackName(cFStackName).withLogicalResourceId(logicalId));
return result.getStackResourceDetail().getPhysicalResourceId();
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method getLoadBalancerByLogicalId.
public LoadBalancer getLoadBalancerByLogicalId(AuthenticatedContext ac, String logicalId) {
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonElasticLoadBalancingClient amazonElbClient = awsClient.createElasticLoadBalancingClient(new AwsCredentialView(ac.getCloudCredential()), region);
String loadBalancerArn = getResourceArnByLogicalId(ac, logicalId, region);
DescribeLoadBalancersResult loadBalancersResult = amazonElbClient.describeLoadBalancers(new DescribeLoadBalancersRequest().withLoadBalancerArns(Collections.singletonList(loadBalancerArn)));
return loadBalancersResult.getLoadBalancers().get(0);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method getEfsByFileSystemId.
public FileSystemDescription getEfsByFileSystemId(AuthenticatedContext ac, String fileSystemId) {
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonEfsClient amazonEfsClient = awsClient.createElasticFileSystemClient(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeFileSystemsResult efsResult = amazonEfsClient.describeFileSystems(new DescribeFileSystemsRequest().withFileSystemId(fileSystemId));
return efsResult.getFileSystems().get(0);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView 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.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsCloudWatchService method addCloudWatchAlarmsForSystemFailures.
public void addCloudWatchAlarmsForSystemFailures(List<CloudResource> instances, String regionName, AwsCredentialView credentialView) {
AmazonCloudWatchClient amazonCloudWatchClient = awsClient.createCloudWatchClient(credentialView, regionName);
instances.stream().filter(instance -> {
String instanceType = instance.getStringParameter(INSTANCE_TYPE);
if (instanceType == null) {
LOGGER.debug("Cannot determine if recovery is supported by instance type, attempting to set it up.");
return true;
}
String family = instanceType.contains(".") ? instanceType.split("\\.")[0] : instanceType;
return RECOVERABLE_INSTANCE_TYPES.contains(family);
}).forEach(instance -> {
try {
PutMetricAlarmRequest metricAlarmRequest = new PutMetricAlarmRequest();
String segment = credentialView.isGovernmentCloudEnabled() ? "aws-us-gov" : "aws";
metricAlarmRequest.setAlarmActions(Arrays.asList("arn:" + segment + ":automate:" + regionName + ":ec2:recover"));
metricAlarmRequest.setAlarmName(instance.getInstanceId() + alarmSuffix);
metricAlarmRequest.setMetricName("StatusCheckFailed_System");
metricAlarmRequest.setStatistic("Maximum");
metricAlarmRequest.setNamespace("AWS/EC2");
metricAlarmRequest.setDimensions(Arrays.asList(new Dimension().withName("InstanceId").withValue(instance.getInstanceId())));
metricAlarmRequest.setPeriod(cloudwatchPeriod);
metricAlarmRequest.setEvaluationPeriods(cloudwatchEvaluationPeriods);
metricAlarmRequest.setThreshold(cloudwatchThreshhold);
metricAlarmRequest.setComparisonOperator("GreaterThanOrEqualToThreshold");
amazonCloudWatchClient.putMetricAlarm(metricAlarmRequest);
LOGGER.debug("Created cloudwatch alarm for instanceId {}.", instance.getInstanceId());
} catch (AmazonCloudWatchException acwe) {
LOGGER.info("Unable to create cloudwatch alarm for instanceId {} (instance type: {}): {}", instance.getInstanceId(), instance.getStringParameter(INSTANCE_TYPE), acwe.getLocalizedMessage());
}
});
}
Aggregations