Search in sources :

Example 71 with AwsCredentialView

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();
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) DescribeStackResourceRequest(com.amazonaws.services.cloudformation.model.DescribeStackResourceRequest) DescribeStackResourceResult(com.amazonaws.services.cloudformation.model.DescribeStackResourceResult)

Example 72 with AwsCredentialView

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);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersResult) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest)

Example 73 with AwsCredentialView

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);
}
Also used : AmazonEfsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) DescribeFileSystemsResult(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult) DescribeFileSystemsRequest(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsRequest)

Example 74 with AwsCredentialView

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);
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)

Example 75 with AwsCredentialView

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());
        }
    });
}
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

AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)94 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)32 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)32 List (java.util.List)25 AmazonServiceException (com.amazonaws.AmazonServiceException)22 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)21 Logger (org.slf4j.Logger)21 Inject (javax.inject.Inject)20 ArrayList (java.util.ArrayList)19 Collectors (java.util.stream.Collectors)19 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)18 Group (com.sequenceiq.cloudbreak.cloud.model.Group)18 Set (java.util.Set)18 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)17 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)17 Map (java.util.Map)16 LoggerFactory (org.slf4j.LoggerFactory)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)15 Service (org.springframework.stereotype.Service)15 AmazonAutoScalingClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient)14