Example usage for com.amazonaws.services.applicationautoscaling.model ScalingPolicy setResourceId

List of usage examples for com.amazonaws.services.applicationautoscaling.model ScalingPolicy setResourceId

Introduction

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

Prototype


public void setResourceId(String resourceId) 

Source Link

Document

The identifier of the resource associated with the scaling policy.

Usage

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();
    }//from  ww w  . j  ava  2  s  .  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;
}