Search in sources :

Example 1 with INSTANCE_TYPE

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());
        }
    });
}
Also used : Arrays(java.util.Arrays) INSTANCE_TYPE(com.sequenceiq.cloudbreak.cloud.model.CloudResource.INSTANCE_TYPE) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AmazonCloudWatchClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonCloudWatchClient) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) Map(java.util.Map) DeleteAlarmsRequest(com.amazonaws.services.cloudwatch.model.DeleteAlarmsRequest) Logger(org.slf4j.Logger) DescribeAlarmsRequest(com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest) MetricAlarm(com.amazonaws.services.cloudwatch.model.MetricAlarm) AwsCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Collectors(java.util.stream.Collectors) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) Stream(java.util.stream.Stream) AmazonCloudWatchException(com.amazonaws.services.cloudwatch.model.AmazonCloudWatchException) AmazonCloudWatchClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonCloudWatchClient) PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) AmazonCloudWatchException(com.amazonaws.services.cloudwatch.model.AmazonCloudWatchException) Dimension(com.amazonaws.services.cloudwatch.model.Dimension)

Aggregations

AmazonCloudWatchException (com.amazonaws.services.cloudwatch.model.AmazonCloudWatchException)1 DeleteAlarmsRequest (com.amazonaws.services.cloudwatch.model.DeleteAlarmsRequest)1 DescribeAlarmsRequest (com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)1 Dimension (com.amazonaws.services.cloudwatch.model.Dimension)1 MetricAlarm (com.amazonaws.services.cloudwatch.model.MetricAlarm)1 PutMetricAlarmRequest (com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest)1 AwsCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient)1 AmazonCloudWatchClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonCloudWatchClient)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 INSTANCE_TYPE (com.sequenceiq.cloudbreak.cloud.model.CloudResource.INSTANCE_TYPE)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1