Search in sources :

Example 6 with LoadBalancer

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

the class ElbAlarmSetupTest method testGetLoadBalancerFromEnvironmentNameNoLoadBalancer.

@Test(expected = IllegalStateException.class)
public void testGetLoadBalancerFromEnvironmentNameNoLoadBalancer() throws Exception {
    // Return empty list
    EnvironmentResourceDescription erd = new EnvironmentResourceDescription().withLoadBalancers(new ArrayList<LoadBalancer>());
    DescribeEnvironmentResourcesResult expectedRes = new DescribeEnvironmentResourcesResult().withEnvironmentResources(erd);
    when(beanstalkClient.describeEnvironmentResources(any(DescribeEnvironmentResourcesRequest.class))).thenReturn(expectedRes);
    doNothing().when(mockSleeper).sleep(anyLong());
    setup.getLoadBalancerFromEnvironmentName("repoEnvName");
}
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) Test(org.junit.Test)

Example 7 with LoadBalancer

use of com.amazonaws.services.elasticbeanstalk.model.LoadBalancer 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

LoadBalancer (com.amazonaws.services.elasticbeanstalk.model.LoadBalancer)7 DescribeEnvironmentResourcesRequest (com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentResourcesRequest)5 DescribeEnvironmentResourcesResult (com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentResourcesResult)5 EnvironmentResourceDescription (com.amazonaws.services.elasticbeanstalk.model.EnvironmentResourceDescription)5 Test (org.junit.Test)4 PutMetricAlarmRequest (com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest)2 ArrayList (java.util.ArrayList)2 DescribeAlarmsRequest (com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)1 DescribeAlarmsResult (com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult)1