Search in sources :

Example 1 with ListenerDescription

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

the class AWSLoadBalancerServiceTest method getListenerByPort.

private Listener getListenerByPort(Integer port, List<ListenerDescription> descriptions) {
    ListenerDescription listenerDescription = descriptions.stream().filter(ld -> ld.getListener().getLoadBalancerPort().equals(port)).findFirst().orElse(null);
    assertNotNull(listenerDescription);
    return listenerDescription.getListener();
}
Also used : ListenerDescription(com.amazonaws.services.elasticloadbalancing.model.ListenerDescription)

Example 2 with ListenerDescription

use of com.amazonaws.services.elasticloadbalancing.model.ListenerDescription 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 3 with ListenerDescription

use of com.amazonaws.services.elasticloadbalancing.model.ListenerDescription 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 ListenerDescription

use of com.amazonaws.services.elasticloadbalancing.model.ListenerDescription 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 ListenerDescription

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

the class ServerInstanceContextTest method testValidContext.

@Test
public void testValidContext() {
    final String region = Regions.US_WEST_2.getName();
    final String instanceId = RandomStringUtils.random(20, "abcdefghi");
    final String availabilityZone = region + RandomStringUtils.random(20, "abcdefghi");
    final String environment = RandomStringUtils.random(20, "abcdefghi");
    final String userData = new UserData(environment).toString();
    final String elbName = environment + "-Zookeeper";
    final String exhibitorUrl = "http://" + elbName + "-" + region + ".aws.amazon.com";
    final int exhibitorPort = 80;
    final String version = "1.0.0";
    Ec2MetadataClient ec2MetadataClient = EasyMock.createMock(Ec2MetadataClient.class);
    EasyMock.expect(ec2MetadataClient.getAvailabilityZone()).andAnswer(new IAnswer<String>() {

        @Override
        public String answer() throws Throwable {
            return availabilityZone;
        }
    });
    EasyMock.expect(ec2MetadataClient.getInstanceId()).andAnswer(new IAnswer<String>() {

        @Override
        public String answer() throws Throwable {
            return instanceId;
        }
    });
    EasyMock.expect(ec2MetadataClient.getUserData()).andAnswer(new IAnswer<String>() {

        @Override
        public String answer() throws Throwable {
            return userData;
        }
    });
    EasyMock.expect(ec2MetadataClient.getPrivateIpAddress()).andAnswer(new IAnswer<String>() {

        @Override
        public String answer() throws Throwable {
            return "127.0.0.1";
        }
    });
    EasyMock.expect(ec2MetadataClient.getPublicIpAddress()).andAnswer(new IAnswer<String>() {

        @Override
        public String answer() throws Throwable {
            return "127.0.0.1";
        }
    });
    AmazonEC2 amazonEC2 = EasyMock.createMock(AmazonEC2.class);
    EasyMock.expect(amazonEC2.describeRegions()).andAnswer(new IAnswer<DescribeRegionsResult>() {

        @Override
        public DescribeRegionsResult answer() throws Throwable {
            DescribeRegionsResult result = new DescribeRegionsResult();
            List<Region> regions = new ArrayList<>();
            for (Regions region : Regions.values()) {
                Region r = new Region();
                r.setRegionName(region.getName());
                regions.add(r);
            }
            result.setRegions(regions);
            return result;
        }
    });
    EasyMock.expect(amazonEC2.describeTags(EasyMock.anyObject(DescribeTagsRequest.class))).andAnswer(new IAnswer<DescribeTagsResult>() {

        @Override
        public DescribeTagsResult answer() throws Throwable {
            return new DescribeTagsResult();
        }
    });
    com.amazonaws.regions.Region r = com.amazonaws.regions.Region.getRegion(Regions.fromName(region));
    amazonEC2.setRegion(eqRegion(r));
    EasyMock.expectLastCall();
    AmazonElasticLoadBalancing amazonElasticLoadBalancing = EasyMock.createMock(AmazonElasticLoadBalancing.class);
    EasyMock.expect(amazonElasticLoadBalancing.describeLoadBalancers()).andAnswer(new IAnswer<DescribeLoadBalancersResult>() {

        @Override
        public DescribeLoadBalancersResult answer() throws Throwable {
            DescribeLoadBalancersResult result = new DescribeLoadBalancersResult();
            List<LoadBalancerDescription> loadBalancers = new ArrayList<>();
            LoadBalancerDescription lb1 = new LoadBalancerDescription();
            lb1.setDNSName(exhibitorUrl);
            lb1.setLoadBalancerName(elbName);
            List<ListenerDescription> listenerDescriptions = new ArrayList<>();
            ListenerDescription httpListenerDescription = new ListenerDescription();
            Listener httpListener = new Listener();
            httpListener.setProtocol("HTTP");
            httpListener.setLoadBalancerPort(exhibitorPort);
            httpListener.setInstancePort(8080);
            httpListenerDescription.setListener(httpListener);
            ListenerDescription httpsListenerDescription = new ListenerDescription();
            Listener httpsListener = new Listener();
            httpsListener.setProtocol("HTTPS");
            httpsListener.setLoadBalancerPort(443);
            httpsListener.setInstancePort(8080);
            httpsListenerDescription.setListener(httpListener);
            listenerDescriptions.add(httpListenerDescription);
            listenerDescriptions.add(httpsListenerDescription);
            lb1.setListenerDescriptions(listenerDescriptions);
            loadBalancers.add(lb1);
            result.setLoadBalancerDescriptions(loadBalancers);
            return result;
        }
    });
    amazonElasticLoadBalancing.setRegion(eqRegion(r));
    EasyMock.expectLastCall();
    EasyMock.replay(ec2MetadataClient, amazonEC2, amazonElasticLoadBalancing);
    ServerInstanceContext context = new ServerInstanceContext(ec2MetadataClient, amazonEC2, amazonElasticLoadBalancing);
    Assert.assertEquals(region, context.getRegion());
    Assert.assertEquals(instanceId, context.getInstanceId());
    Assert.assertEquals(availabilityZone, context.getAvailabilityZone());
    Assert.assertEquals(environment, context.getEnvironment());
    Assert.assertEquals(exhibitorUrl, context.getExhibitorHost());
    Assert.assertEquals(exhibitorPort, context.getExhibitorPort());
    Assert.assertNull(context.getAppName());
    EasyMock.verify(ec2MetadataClient, amazonEC2, amazonElasticLoadBalancing);
    EasyMock.reset(amazonEC2, amazonElasticLoadBalancing);
    amazonEC2.shutdown();
    EasyMock.expectLastCall();
    amazonElasticLoadBalancing.shutdown();
    EasyMock.expectLastCall();
    String name = RandomStringUtils.random(20, "abcdefghi");
    EasyMock.replay(amazonEC2, amazonElasticLoadBalancing);
    context.setAppName(name);
    context.setVersion(version);
    Assert.assertEquals(name, context.getAppName());
    context.shutdown();
    EasyMock.verify(ec2MetadataClient, amazonEC2, amazonElasticLoadBalancing);
}
Also used : DescribeTagsRequest(com.amazonaws.services.ec2.model.DescribeTagsRequest) DescribeTagsResult(com.amazonaws.services.ec2.model.DescribeTagsResult) Listener(com.amazonaws.services.elasticloadbalancing.model.Listener) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) ListenerDescription(com.amazonaws.services.elasticloadbalancing.model.ListenerDescription) ArrayList(java.util.ArrayList) List(java.util.List) LoadBalancerDescription(com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription) Regions(com.amazonaws.regions.Regions) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) DescribeRegionsResult(com.amazonaws.services.ec2.model.DescribeRegionsResult) Region(com.amazonaws.services.ec2.model.Region) AmazonElasticLoadBalancing(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancing) Test(org.junit.Test)

Aggregations

ListenerDescription (com.amazonaws.services.elasticloadbalancing.model.ListenerDescription)8 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 Regions (com.amazonaws.regions.Regions)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)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 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1 AmazonElasticLoadBalancing (com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancing)1 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult)1 Listener (com.amazonaws.services.elasticloadbalancing.model.Listener)1 BootstrapException (com.kixeye.chassis.bootstrap.BootstrapException)1 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)1 LoadBalancerState (com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState)1 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)1 List (java.util.List)1