Example usage for com.amazonaws.services.ecs.model LoadBalancer setTargetGroupArn

List of usage examples for com.amazonaws.services.ecs.model LoadBalancer setTargetGroupArn

Introduction

In this page you can find the example usage for com.amazonaws.services.ecs.model LoadBalancer setTargetGroupArn.

Prototype


public void setTargetGroupArn(String targetGroupArn) 

Source Link

Document

The full Amazon Resource Name (ARN) of the Elastic Load Balancing target group or groups associated with a service or task set.

Usage

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

License:Apache License

private LoadBalancer retrieveLoadBalancer(String version) {
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setContainerName(version);
    loadBalancer.setContainerPort(description.getContainerPort());

    if (description.getTargetGroup() != null) {
        AmazonElasticLoadBalancing loadBalancingV2 = getAmazonElasticLoadBalancingClient();

        DescribeTargetGroupsRequest request = new DescribeTargetGroupsRequest()
                .withNames(description.getTargetGroup());
        DescribeTargetGroupsResult describeTargetGroupsResult = loadBalancingV2.describeTargetGroups(request);

        if (describeTargetGroupsResult.getTargetGroups().size() == 1) {
            loadBalancer
                    .setTargetGroupArn(describeTargetGroupsResult.getTargetGroups().get(0).getTargetGroupArn());
        } else if (describeTargetGroupsResult.getTargetGroups().size() > 1) {
            throw new IllegalArgumentException(
                    "There are multiple target groups with the name " + description.getTargetGroup() + ".");
        } else {/*from w ww  .  j ava  2  s. c om*/
            throw new IllegalArgumentException(
                    "There is no target group with the name " + description.getTargetGroup() + ".");
        }

    }
    return loadBalancer;
}