Search in sources :

Example 1 with DescribeEnvironmentResourcesRequest

use of com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentResourcesRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class ElbAlarmSetup method getLoadBalancerFromEnvironmentName.

public LoadBalancer getLoadBalancerFromEnvironmentName(String envName) throws InterruptedException {
    if (envName == null)
        throw new IllegalArgumentException("Environment name cannot be null.");
    DescribeEnvironmentResourcesRequest req = new DescribeEnvironmentResourcesRequest();
    req.setEnvironmentName(envName);
    DescribeEnvironmentResourcesResult res = beanstalkClient.describeEnvironmentResources(req);
    EnvironmentResourceDescription erd = res.getEnvironmentResources();
    List<LoadBalancer> loadBalancers = erd.getLoadBalancers();
    int count = 0;
    while ((loadBalancers != null) && (loadBalancers.size() == 0)) {
        count += 1;
        if (count == 10) {
            throw new IllegalStateException("Load balancer for environment " + envName + " did not come up within 5 minutes");
        }
        sleeper.sleep(30000L);
        loadBalancers = erd.getLoadBalancers();
    }
    // In case loadBalancers was null to start with, should not happen
    if ((loadBalancers != null) && (loadBalancers.size() != 1)) {
        throw new IllegalStateException("Should only be one load balancer for environment " + envName);
    }
    return loadBalancers.get(0);
}
Also used : DescribeEnvironmentResourcesResult(com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentResourcesResult) DescribeEnvironmentResourcesRequest(com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentResourcesRequest) LoadBalancer(com.amazonaws.services.elasticbeanstalk.model.LoadBalancer) EnvironmentResourceDescription(com.amazonaws.services.elasticbeanstalk.model.EnvironmentResourceDescription)

Aggregations

DescribeEnvironmentResourcesRequest (com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentResourcesRequest)1 DescribeEnvironmentResourcesResult (com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentResourcesResult)1 EnvironmentResourceDescription (com.amazonaws.services.elasticbeanstalk.model.EnvironmentResourceDescription)1 LoadBalancer (com.amazonaws.services.elasticbeanstalk.model.LoadBalancer)1