Search in sources :

Example 1 with LoadBalancerDescription

use of com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription in project photon-model by vmware.

the class AWSLoadBalancerServiceTest method testCreateUpdateDeleteLoadBalancer.

@Test
public void testCreateUpdateDeleteLoadBalancer() throws Throwable {
    // set name with invalid characters and more than 32 characters
    this.lbName = generateLbName() + "-1234567890-1234567890-1234567890_;.,/";
    LoadBalancerState lb = createLoadBalancerState(this.lbName);
    // Provision load balancer
    kickOffLoadBalancerProvision(InstanceRequestType.CREATE, lb.documentSelfLink, TaskStage.FINISHED);
    lb = getServiceSynchronously(lb.documentSelfLink, LoadBalancerState.class);
    this.lbName = lb.name;
    if (!this.isMock) {
        assertNotNull(lb.securityGroupLinks);
        String securityGroupDocumentSelfLink = lb.securityGroupLinks.iterator().next();
        assertNotNull(securityGroupDocumentSelfLink);
        SecurityGroupState sgs = getServiceSynchronously(securityGroupDocumentSelfLink, SecurityGroupState.class);
        this.sgId = sgs.id;
        LoadBalancerDescription awsLoadBalancer = getAwsLoadBalancer(this.lbName);
        assertNotNull(awsLoadBalancer);
        assertEquals(awsLoadBalancer.getDNSName(), lb.address);
        assertEquals("internet-facing", awsLoadBalancer.getScheme());
        assertEquals(1, awsLoadBalancer.getInstances().size());
        List<ListenerDescription> listeners = awsLoadBalancer.getListenerDescriptions();
        assertEquals(2, listeners.size());
        verifyListeners(lb.routes, listeners);
        verifyHealthCheckConfiguration(lb.routes.get(0), awsLoadBalancer.getHealthCheck());
        SecurityGroup securityGroup = getAwsSecurityGroup(sgs.id);
        assertNotNull(securityGroup);
        String lbSecGroupId = awsLoadBalancer.getSecurityGroups().stream().findFirst().orElse(null);
        assertEquals(securityGroup.getGroupId(), lbSecGroupId);
    }
    // Update load balancer from 1 machines to 2 to simulate scale-out
    if (!this.isMock) {
        lb.computeLinks = new HashSet<>(Arrays.asList(this.cs1.documentSelfLink, this.cs2.documentSelfLink));
        putServiceSynchronously(lb.documentSelfLink, lb);
    }
    kickOffLoadBalancerProvision(InstanceRequestType.UPDATE, lb.documentSelfLink, TaskStage.FINISHED);
    if (!this.isMock) {
        LoadBalancerDescription awsLoadBalancer = getAwsLoadBalancer(this.lbName);
        assertNotNull(awsLoadBalancer);
        assertEquals(2, awsLoadBalancer.getInstances().size());
        // Update load balancer from 2 machines to 1 to simulate scale-in
        lb.computeLinks = Collections.singleton(this.cs1.documentSelfLink);
        putServiceSynchronously(lb.documentSelfLink, lb);
        kickOffLoadBalancerProvision(InstanceRequestType.UPDATE, lb.documentSelfLink, TaskStage.FINISHED);
        awsLoadBalancer = getAwsLoadBalancer(this.lbName);
        assertNotNull(awsLoadBalancer);
        assertEquals(1, awsLoadBalancer.getInstances().size());
    }
    kickOffLoadBalancerProvision(InstanceRequestType.DELETE, lb.documentSelfLink, TaskStage.FINISHED);
    if (!this.isMock) {
        assertNull(getAwsLoadBalancer(this.lbName));
        assertNull(getAwsSecurityGroup(this.sgId));
    }
    this.lbName = null;
    this.sgId = null;
}
Also used : ListenerDescription(com.amazonaws.services.elasticloadbalancing.model.ListenerDescription) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 2 with LoadBalancerDescription

use of com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription in project photon-model by vmware.

the class AWSLoadBalancerServiceTest method getAwsLoadBalancer.

private LoadBalancerDescription getAwsLoadBalancer(String name) {
    DescribeLoadBalancersRequest describeRequest = new DescribeLoadBalancersRequest().withLoadBalancerNames(name);
    DescribeLoadBalancersResult describeResult = null;
    try {
        describeResult = this.client.describeLoadBalancers(describeRequest);
    } catch (Exception e) {
        this.host.log("Exception describing load balancers with name '%s': %s", name, e.toString());
    }
    Collection<LoadBalancerDescription> lbs = describeResult != null ? describeResult.getLoadBalancerDescriptions() : null;
    if (lbs == null || lbs.isEmpty()) {
        return null;
    }
    if (lbs.size() > 1) {
        throw new IllegalStateException("More than one load balancers found with name '" + name + "'.");
    }
    return lbs.iterator().next();
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) CompletionException(java.util.concurrent.CompletionException)

Example 3 with LoadBalancerDescription

use of com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription in project chassis by Kixeye.

the class ZookeeperElbFilterTest method foundInternalExhibitor.

@Test
public void foundInternalExhibitor() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    List<ListenerDescription> listenerDescriptions = new ArrayList<>();
    listenerDescriptions.add(new ListenerDescription());
    loadBalancer.setListenerDescriptions(listenerDescriptions);
    loadBalancer.setLoadBalancerName("exhibitor-" + ENVIRONMENT + "-internal");
    Assert.assertTrue(filter.accept(loadBalancer));
}
Also used : ListenerDescription(com.amazonaws.services.elasticloadbalancing.model.ListenerDescription) ArrayList(java.util.ArrayList) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) Test(org.junit.Test)

Example 4 with LoadBalancerDescription

use of com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription in project chassis by Kixeye.

the class ZookeeperElbFilterTest method randomUnmatchedELB.

@Test
public void randomUnmatchedELB() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    List<ListenerDescription> listenerDescriptions = new ArrayList<>();
    listenerDescriptions.add(new ListenerDescription());
    loadBalancer.setListenerDescriptions(listenerDescriptions);
    loadBalancer.setLoadBalancerName(RandomStringUtils.random(5, "abcd"));
    Assert.assertFalse(filter.accept(loadBalancer));
}
Also used : ListenerDescription(com.amazonaws.services.elasticloadbalancing.model.ListenerDescription) ArrayList(java.util.ArrayList) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) Test(org.junit.Test)

Example 5 with LoadBalancerDescription

use of com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription in project chassis by Kixeye.

the class ZookeeperElbFilterTest method noMatchingEnvironment.

@Test
public void noMatchingEnvironment() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    loadBalancer.setLoadBalancerName("foo-Zookeeper-whatever");
    Assert.assertFalse(filter.accept(loadBalancer));
}
Also used : LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) Test(org.junit.Test)

Aggregations

LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)20 Test (org.junit.Test)8 ListenerDescription (com.amazonaws.services.elasticloadbalancing.model.ListenerDescription)7 ArrayList (java.util.ArrayList)7 Resource (com.netflix.simianarmy.Resource)6 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)6 Test (org.testng.annotations.Test)5 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)3 Instance (com.amazonaws.services.elasticloadbalancing.model.Instance)3 DescribeLoadBalancersRequest (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)2 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult)2 Regions (com.amazonaws.regions.Regions)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)1 DescribeTagsRequest (com.amazonaws.services.ec2.model.DescribeTagsRequest)1 DescribeTagsResult (com.amazonaws.services.ec2.model.DescribeTagsResult)1 Region (com.amazonaws.services.ec2.model.Region)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1