Example usage for com.amazonaws.services.applicationautoscaling.model ServiceNamespace Ecs

List of usage examples for com.amazonaws.services.applicationautoscaling.model ServiceNamespace Ecs

Introduction

In this page you can find the example usage for com.amazonaws.services.applicationautoscaling.model ServiceNamespace Ecs.

Prototype

ServiceNamespace Ecs

To view the source code for com.amazonaws.services.applicationautoscaling.model ServiceNamespace Ecs.

Click Source Link

Usage

From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.CreateServerGroupAtomicOperation.java

License:Apache License

private String registerAutoScalingGroup(AmazonCredentials credentials, Service service) {

    AWSApplicationAutoScaling autoScalingClient = getAmazonApplicationAutoScalingClient();
    String assumedRoleArn = inferAssumedRoleArn(credentials);

    RegisterScalableTargetRequest request = new RegisterScalableTargetRequest()
            .withServiceNamespace(ServiceNamespace.Ecs)
            .withScalableDimension(ScalableDimension.EcsServiceDesiredCount)
            .withResourceId(//from  www . jav  a 2s. com
                    String.format("service/%s/%s", description.getEcsClusterName(), service.getServiceName()))
            .withRoleARN(assumedRoleArn).withMinCapacity(description.getCapacity().getMin())
            .withMaxCapacity(description.getCapacity().getMax());

    updateTaskStatus("Creating Amazon Application Auto Scaling Scalable Target Definition...");
    autoScalingClient.registerScalableTarget(request);
    updateTaskStatus("Done creating Amazon Application Auto Scaling Scalable Target Definition.");

    return request.getResourceId();
}

From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.EnableServiceAtomicOperation.java

License:Apache License

private ScalableTarget getScalableTarget(String cluster) {
    AWSApplicationAutoScaling appASClient = getAmazonApplicationAutoScalingClient();

    List<String> resourceIds = new ArrayList<>();
    resourceIds.add(String.format("service/%s/%s", cluster, description.getServerGroupName()));

    DescribeScalableTargetsRequest request = new DescribeScalableTargetsRequest().withResourceIds(resourceIds)
            .withScalableDimension(ScalableDimension.EcsServiceDesiredCount)
            .withServiceNamespace(ServiceNamespace.Ecs);

    DescribeScalableTargetsResult result = appASClient.describeScalableTargets(request);

    if (result.getScalableTargets().isEmpty()) {
        return null;
    }//  w  w w.  j ava2  s  .c o m

    if (result.getScalableTargets().size() == 1) {
        return result.getScalableTargets().get(0);
    }

    throw new Error("Multiple Scalable Targets found");
}

From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.ResizeServiceAtomicOperation.java

License:Apache License

private void resizeAutoScalingGroup(Service service) {
    AWSApplicationAutoScaling autoScalingClient = getAmazonApplicationAutoScalingClient();

    Integer desiredCount = description.getCapacity().getDesired();
    String ecsClusterName = containerInformationService.getClusterName(service.getServiceName(),
            description.getAccount(), description.getRegion());

    RegisterScalableTargetRequest request = new RegisterScalableTargetRequest()
            .withServiceNamespace(ServiceNamespace.Ecs)
            .withScalableDimension(ScalableDimension.EcsServiceDesiredCount)
            .withResourceId(String.format("service/%s/%s", ecsClusterName, service.getServiceName()))
            .withRoleARN(service.getRoleArn()).withMinCapacity(description.getCapacity().getMin())
            .withMaxCapacity(description.getCapacity().getMax());

    updateTaskStatus(String.format("Resizing Scalable Target of %s to %s instances", service.getServiceName(),
            desiredCount));// w  w w . j  a  v a  2s.  c  o m
    autoScalingClient.registerScalableTarget(request);
    updateTaskStatus(String.format("Done resizing Scalable Target of %s to %s instances",
            service.getServiceName(), desiredCount));
}

From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.ScalableTargetsCachingAgent.java

License:Apache License

Set<ScalableTarget> fetchScalableTargets(AWSApplicationAutoScaling autoScalingClient) {
    Set<ScalableTarget> scalableTargets = new HashSet<>();
    String nextToken = null;//from   ww w . ja  v  a 2s  .c  o m
    do {
        DescribeScalableTargetsRequest request = new DescribeScalableTargetsRequest()
                .withServiceNamespace(ServiceNamespace.Ecs);
        if (nextToken != null) {
            request.setNextToken(nextToken);
        }

        DescribeScalableTargetsResult result = autoScalingClient.describeScalableTargets(request);
        scalableTargets.addAll(result.getScalableTargets());

        nextToken = result.getNextToken();
    } while (nextToken != null && nextToken.length() != 0);

    return scalableTargets;
}

From source file:com.netflix.spinnaker.clouddriver.ecs.services.EcsCloudMetricService.java

License:Apache License

private Set<String> putScalingPolicies(AWSApplicationAutoScaling autoScalingClient, List<String> actionArns,
        String serviceName, String resourceId, String type, String suffix) {
    if (actionArns.isEmpty()) {
        return Collections.emptySet();
    }/*w  ww  . ja v  a2s. c  o m*/

    Set<ScalingPolicy> scalingPolicies = new HashSet<>();

    String nextToken = null;
    do {
        DescribeScalingPoliciesRequest request = new DescribeScalingPoliciesRequest().withPolicyNames(
                actionArns.stream().map(arn -> StringUtils.substringAfterLast(arn, ":policyName/"))
                        .collect(Collectors.toSet()))
                .withServiceNamespace(ServiceNamespace.Ecs);
        if (nextToken != null) {
            request.setNextToken(nextToken);
        }

        DescribeScalingPoliciesResult result = autoScalingClient.describeScalingPolicies(request);
        scalingPolicies.addAll(result.getScalingPolicies());

        nextToken = result.getNextToken();
    } while (nextToken != null && nextToken.length() != 0);

    Set<String> policyArns = new HashSet<>();
    for (ScalingPolicy scalingPolicy : scalingPolicies) {
        String newPolicyName = serviceName + "-" + type + "-" + suffix;
        ScalingPolicy clone = scalingPolicy.clone();
        clone.setPolicyName(newPolicyName);
        clone.setResourceId(resourceId);

        PutScalingPolicyResult result = autoScalingClient.putScalingPolicy(buildPutScalingPolicyRequest(clone));
        policyArns.add(result.getPolicyARN());
    }

    return policyArns;
}