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