use of com.sequenceiq.cloudbreak.cloud.model.CloudResource.INSTANCE_TYPE 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