@Test public void testGetElbDnsName() { final LoadBalancerDescription description = new LoadBalancerDescription(); description.setDNSName("testDnsName"); final List<LoadBalancerDescription> descriptions = new ArrayList<>(); descriptions.add(description); final DescribeLoadBalancersResult result = mock(DescribeLoadBalancersResult.class); when(result.getLoadBalancerDescriptions()).thenReturn(descriptions); when(amazonElbClient.describeLoadBalancers(any(DescribeLoadBalancersRequest.class))).thenReturn(result); final String elbName = "testElbName"; assertThat(awsHelperService.getElbDnsName(elbName), equalTo(description.getDNSName())); final ArgumentCaptor<DescribeLoadBalancersRequest> argumentCaptor = ArgumentCaptor.forClass(DescribeLoadBalancersRequest.class); verify(amazonElbClient).describeLoadBalancers(argumentCaptor.capture()); assertThat(argumentCaptor.getValue().getLoadBalancerNames().get(0), equalTo(elbName)); }
/** * Sanity checks the LB description, and checks for done-ness. */ private void checkInstanceRemoval(LoadBalancerDescription loadBalancerDescription) { if (!StringUtils.equals(elbName, loadBalancerDescription.getLoadBalancerName())) { throw new IllegalStateException(logContext + "We requested description of ELB '" + elbName + "' but response is for '" + loadBalancerDescription.getLoadBalancerName() + "'"); } if (CollectionUtils.isEmpty(loadBalancerDescription.getInstances())) { throw new IllegalStateException("ELB '" + elbName + "' has zero instances"); } if (instanceIsGoneFromList(loadBalancerDescription.getInstances())) { LOGGER.info("ELB '" + elbName + "' list of instances shows '" + ec2InstanceId + "' is gone"); done = true; result = true; } }
/** * Test helper - makes a fake LB description. */ private LoadBalancerDescription makeLoadBalancerDescription(String elbName, String... instanceIds) { LoadBalancerDescription loadBalancerDescription = new LoadBalancerDescription(); loadBalancerDescription.setLoadBalancerName(elbName); List<Instance> instances = new ArrayList<Instance>(); if (instanceIds != null) { for (String instanceId : instanceIds) { Instance instance = new Instance(); instance.setInstanceId(instanceId); instances.add(instance); } } loadBalancerDescription.setInstances(instances); return loadBalancerDescription; }
/** * Test helper - makes describe result with one or more named LBs. */ private DescribeLoadBalancersResult makeDescribeLoadBalancersResult(String... loadBalancerNames) { DescribeLoadBalancersResult result = new DescribeLoadBalancersResult(); if (ArrayUtils.isNotEmpty(loadBalancerNames)) { List<LoadBalancerDescription> list = new ArrayList<LoadBalancerDescription>(); for (String loadBalancerName : loadBalancerNames) { LoadBalancerDescription loadBalancerDescription = new LoadBalancerDescription(); loadBalancerDescription.setLoadBalancerName(loadBalancerName); list.add(loadBalancerDescription); } result.setLoadBalancerDescriptions(list); } return result; }
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(); }
public static String getLoadBalancerDNS(String name) { if (name == null || name.trim().length() == 0) throw new RuntimeException( "The name of the load balancer cannot be empty!"); connect(); ArrayList<String> names = new ArrayList<String>(); names.add(name); DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest( names); DescribeLoadBalancersResult res = client.describeLoadBalancers(req); List<LoadBalancerDescription> descs = res.getLoadBalancerDescriptions(); if (descs.size() == 0 || descs.get(0) == null) return null; return descs.get(0).getDNSName(); }
public LoadBalancerDescription describeLoadBalancer(AwsProcessClient awsProcessClient, String loadBalancerName) { // 単一ロードバランサの参照 DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest(); request.withLoadBalancerNames(loadBalancerName); DescribeLoadBalancersResult result = awsProcessClient.getElbClient().describeLoadBalancers(request); List<LoadBalancerDescription> descriptions = result.getLoadBalancerDescriptions(); // API実行結果チェック if (descriptions.size() == 0) { // アドレスが存在しない場合 throw new AutoException("EPROCESS-000131", loadBalancerName); } else if (descriptions.size() > 1) { // アドレスを複数参照できた場合 AutoException exception = new AutoException("EPROCESS-000132", loadBalancerName); exception.addDetailInfo("result=" + descriptions); throw exception; } return descriptions.get(0); }
@Override public boolean accept(LoadBalancerDescription loadBalancer) { String[] pieces = loadBalancer.getLoadBalancerName().split("-"); if (pieces.length < 2) { return false; } // match ENV-Zoo* (Cloud Formation naming scheme) if (pieces[0].equalsIgnoreCase(environment) && pieces[1].startsWith("Zoo")) { return true; } // match exhibitor-ENV-internal (Original naming scheme) if (pieces.length == 3 && pieces[0].equalsIgnoreCase("exhibitor") && pieces[1].equalsIgnoreCase(environment) && pieces[2].equalsIgnoreCase("internal")) { return true; } return false; }
private void initExhibitor() { LOGGER.info("Initializing exhibitor info..."); List<LoadBalancerDescription> loadBalancers = AwsUtils.findLoadBalancers(amazonElasticLoadBalancing, new ZookeeperElbFilter(environment)); if(loadBalancers.size() == 0) { LOGGER.info("No Zookeeper ELBs for environment " + environment); return; } else if(loadBalancers.size() != 1){ throw new BootstrapException("Found multiple Zookeeper ELBs for environment " + environment); } LoadBalancerDescription loadBalancer = loadBalancers.get(0); ListenerDescription exhibitorListenerDescription = getExhibitorListenerDescription(loadBalancer); this.exhibitorHost = loadBalancer.getDNSName(); this.exhibitorPort = exhibitorListenerDescription.getListener().getLoadBalancerPort(); LOGGER.info("Initialized exhibitor info with: exhibitorHost: {}, exhibitorPort: {}", exhibitorHost, exhibitorPort); }
private LoadBalancerDescription checkForMatchingTag( List<LoadBalancerDescription> descriptions, String vpcID, String type) throws TooManyELBException { List<LoadBalancerDescription> found = new LinkedList<LoadBalancerDescription>(); for(LoadBalancerDescription desc : descriptions) { String loadBalancerName = desc.getLoadBalancerName(); logger.info(String.format("Checking LB for tag %s:%s, ELB name is %s", AwsFacade.TYPE_TAG, type, loadBalancerName)); List<Tag> tags = elbClient.getTagsFor(loadBalancerName); if (containsCorrectTag(tags, type)) { logger.info("LB matched " + loadBalancerName); found.add(desc); } } if (found.size()==1) { return found.get(0); } throw new TooManyELBException(found.size(), String.format("Found too many elbs for vpc (%s) that matched tag %s", vpcID, AwsFacade.TYPE_TAG)); }
private List<Instance> addInstancesThatMatchBuildAndType(ProjectAndEnv projAndEnv, String typeTag) throws CfnAssistException { if (!projAndEnv.hasBuildNumber()) { throw new MustHaveBuildNumber(); } LoadBalancerDescription elb = findELBFor(projAndEnv, typeTag); List<Instance> currentInstances = elb.getInstances(); String lbName = elb.getLoadBalancerName(); SearchCriteria criteria = new SearchCriteria(projAndEnv); List<Instance> allMatchingInstances = cfnRepository.getAllInstancesMatchingType(criteria, typeTag); List<Instance> instancesToAdd = filterBy(currentInstances, allMatchingInstances); if (allMatchingInstances.size()==0) { logger.warn(String.format("No instances matched %s and type tag %s (%s)", projAndEnv, typeTag, AwsFacade.TYPE_TAG)); } else { logger.info(String.format("Regsister matching %s instances with the LB %s ", instancesToAdd.size(),lbName)); elbClient.registerInstances(instancesToAdd, lbName); } return instancesToAdd; }
private List<Instance> removeInstancesNotMatching(ProjectAndEnv projAndEnv, List<Instance> matchingInstances, String typeTag) throws MustHaveBuildNumber, TooManyELBException { LoadBalancerDescription elb = findELBFor(projAndEnv, typeTag); logger.info("Checking if instances should be removed from ELB " + elb.getLoadBalancerName()); List<Instance> currentInstances = elb.getInstances(); List<Instance> toRemove = new LinkedList<Instance>(); for(Instance current : currentInstances) { String instanceId = current.getInstanceId(); if (matchingInstances.contains(current)) { logger.info("Instance matched project/env/build/type, will not be removed " + instanceId); } else { logger.info("Instance did not match, will be removed from ELB " +instanceId); toRemove.add(new Instance(instanceId)); } } if (toRemove.isEmpty()) { logger.info("No instances to remove from ELB " + elb.getLoadBalancerName()); return new LinkedList<Instance>(); } return removeInstances(elb,toRemove); }
@Test public void ShouldUseTagIfMoreThanOneELB() throws TooManyELBException { String typeTag = "expectedType"; List<Tag> lb1Tags = new LinkedList<>(); lb1Tags.add(new Tag().withKey(AwsFacade.TYPE_TAG).withValue("someNonMatchingTag")); List<Tag> lb2Tags = new LinkedList<>(); lb2Tags.add(new Tag().withKey(AwsFacade.TYPE_TAG).withValue(typeTag)); List<LoadBalancerDescription> lbs = new LinkedList<>(); lbs.add(new LoadBalancerDescription().withLoadBalancerName("lb1Name").withVPCId("vpcId")); lbs.add(new LoadBalancerDescription().withLoadBalancerName("lb2Name").withVPCId("vpcId")); Vpc vpc = new Vpc().withVpcId("vpcId"); EasyMock.expect(vpcRepository.getCopyOfVpc(projAndEnv)).andReturn(vpc); EasyMock.expect(elbClient.describeLoadBalancers()).andReturn(lbs); EasyMock.expect(elbClient.getTagsFor("lb1Name")).andReturn(lb1Tags); EasyMock.expect(elbClient.getTagsFor("lb2Name")).andReturn(lb2Tags); replayAll(); LoadBalancerDescription result = elbRepository.findELBFor(projAndEnv, typeTag); verifyAll(); assertEquals("lb2Name", result.getLoadBalancerName()); }
@Test public void ShouldThrowIfMoreThanOneELBAndNoMatchingTags() { List<Tag> tags = new LinkedList<>(); tags.add(new Tag().withKey("someOtherTag").withValue("someOtherValue")); List<LoadBalancerDescription> lbs = new LinkedList<>(); lbs.add(new LoadBalancerDescription().withLoadBalancerName("lb1Name").withVPCId("vpcId")); lbs.add(new LoadBalancerDescription().withLoadBalancerName("lb2Name").withVPCId("vpcId")); Vpc vpc = new Vpc().withVpcId("vpcId"); EasyMock.expect(vpcRepository.getCopyOfVpc(projAndEnv)).andReturn(vpc); EasyMock.expect(elbClient.describeLoadBalancers()).andReturn(lbs); EasyMock.expect(elbClient.getTagsFor("lb1Name")).andReturn(new LinkedList<>()); EasyMock.expect(elbClient.getTagsFor("lb2Name")).andReturn(tags); replayAll(); try { elbRepository.findELBFor(projAndEnv,"notMatchingAnLB"); fail("should have thrown"); } catch(TooManyELBException expectedException) { // no op } verifyAll(); }
@Test public void shouldGetInstancesForTheLB() throws TooManyELBException { String vpcId = "myVPC"; Instance insA = new Instance().withInstanceId("instanceA"); // associated List<LoadBalancerDescription> theLB = new LinkedList<>(); theLB.add(new LoadBalancerDescription().withVPCId(vpcId). withInstances(insA). withLoadBalancerName("lbName").withDNSName("dnsName")); EasyMock.expect(vpcRepository.getCopyOfVpc(projAndEnv)).andStubReturn(new Vpc().withVpcId(vpcId)); EasyMock.expect(elbClient.describeLoadBalancers()).andReturn(theLB); replayAll(); List<Instance> result = elbRepository.findInstancesAssociatedWithLB(projAndEnv,"typeNotUsedWhenOneMatchingLB"); verifyAll(); assertEquals(1, result.size()); assertEquals("instanceA", result.get(0).getInstanceId()); }
@Test public void testAddsIpAndPortToELBSecGroup() throws CfnAssistException, UnknownHostException { String type = "elbTypeTag"; LoadBalancerDescription elbDescription = new LoadBalancerDescription(). withLoadBalancerName("elbName"). withDNSName("dNSName").withSecurityGroups("elbSecGroupId"); Integer port = 8080; InetAddress address = Inet4Address.getByName("192.168.0.1"); EasyMock.expect(elbRepository.findELBFor(projectAndEnv, type)).andReturn(elbDescription); cloudRepository.updateAddIpAndPortToSecGroup("elbSecGroupId", address, port); EasyMock.expectLastCall(); EasyMock.expect(providesCurrentIp.getCurrentIp()).andReturn(address); replayAll(); aws.whitelistCurrentIpForPortToElb(projectAndEnv, type, providesCurrentIp, port); verifyAll(); }
@Test public void testRemovesIpAndPortToELBSecGroup() throws CfnAssistException, UnknownHostException { String type = "elbTypeTag"; LoadBalancerDescription elbDescription = new LoadBalancerDescription(). withLoadBalancerName("elbName"). withDNSName("dNSName"). withSecurityGroups("elbSecGroupId"); Integer port = 8090; InetAddress address = Inet4Address.getByName("192.168.0.2"); EasyMock.expect(elbRepository.findELBFor(projectAndEnv, type)).andReturn(elbDescription); cloudRepository.updateRemoveIpAndPortFromSecGroup("elbSecGroupId", address, port); EasyMock.expectLastCall(); EasyMock.expect(providesCurrentIp.getCurrentIp()).andReturn(address); replayAll(); aws.blacklistCurrentIpForPortToElb(projectAndEnv, type, providesCurrentIp, port); verifyAll(); }
@GET @NoAuth @Path("/{elbName}") public LoadBalancerDescription getElb(@PathParam("elbName") String elbName) { if (config.isPresent()) { try { DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest(Arrays.asList(elbName)); DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(request); for (LoadBalancerDescription elb : result.getLoadBalancerDescriptions()) { if (elb.getLoadBalancerName().equals(elbName)) { return elb; } } } catch (AmazonClientException e) { throw new BaragonWebException(String.format("AWS Client Error: %s", e)); } throw new BaragonNotFoundException(String.format("ELB with name %s not found", elbName)); } else { throw new BaragonWebException("ElbSync and related actions are not currently enabled"); } }
public AgentCheckInResponse registerInstance(Instance instance, String elbName, BaragonAgentMetadata agent) { Optional<String> maybeException = Optional.absent(); Optional<LoadBalancerDescription> elb = getElb(elbName); if (elb.isPresent()) { if (isVpcOk(agent, elb.get())) { if (!elb.get().getInstances().contains(instance)) { checkAZEnabled(agent, elbName, elb.get()); RegisterInstancesWithLoadBalancerRequest request = new RegisterInstancesWithLoadBalancerRequest(elbName, Arrays.asList(instance)); elbClient.registerInstancesWithLoadBalancer(request); LOG.info("Registered instances {} with ELB {}", request.getInstances(), request.getLoadBalancerName()); } else { LOG.debug("Agent {} already registered with ELB {}", agent.getAgentId(), elbName); } } else { maybeException = Optional.of(String.format("No ELB found for vpc %s", agent.getEc2().getVpcId())); } } return new AgentCheckInResponse(TrafficSourceState.DONE, maybeException, 0L); }
private void checkAZEnabled(BaragonAgentMetadata agent, String elbName,LoadBalancerDescription elb) { if (agent.getEc2().getAvailabilityZone().isPresent()) { String availabilityZone = agent.getEc2().getAvailabilityZone().get(); if (elb.getLoadBalancerName().equals(elbName) && !elb.getAvailabilityZones().contains(availabilityZone)) { try { if (agent.getEc2().getSubnetId().isPresent()) { addSubnet(agent, elb); } else { enableAZ(agent, availabilityZone, elb); } } catch (AmazonClientException e) { LOG.error("Could not enable availability zone {} for elb {} due to error", availabilityZone, elb.getLoadBalancerName(), e); exceptionNotifier.notify(e, ImmutableMap.of("elb", elbName, "subnet", agent.getEc2().getSubnetId().toString(), "availabilityZone", availabilityZone)); } } } else { LOG.warn("No availability zone specified for agent {}", agent.getAgentId()); } }
private List<LoadBalancerDescription> getElbsForGroup(List<LoadBalancerDescription> elbs, BaragonGroup group) { List<LoadBalancerDescription> elbsForGroup = new ArrayList<>(); for (LoadBalancerDescription elb : elbs) { List<String> trafficSourceNames = new ArrayList<>(); for (TrafficSource trafficSource : group.getTrafficSources()) { if (trafficSource.getType() == TrafficSourceType.CLASSIC) { trafficSourceNames.add(trafficSource.getName()); } } if (trafficSourceNames.contains(elb.getLoadBalancerName())) { elbsForGroup.add(elb); } } return elbsForGroup; }
private void registerNewInstances(List<LoadBalancerDescription> elbs, BaragonGroup group) { Collection<BaragonAgentMetadata> agents = loadBalancerDatastore.getAgentMetadata(group.getName()); List<RegisterInstancesWithLoadBalancerRequest> requests = registerRequests(group, agents, elbs); if (!requests.isEmpty()) { for (RegisterInstancesWithLoadBalancerRequest request : requests) { try { elbClient.registerInstancesWithLoadBalancer(request); LOG.info("Registered instances {} with ELB {}", request.getInstances(), request.getLoadBalancerName()); } catch (AmazonClientException e) { LOG.error("Could not register {} with elb {} due to error", request.getInstances(), request.getLoadBalancerName(), e); exceptionNotifier.notify(e, ImmutableMap.of("elb", request.getLoadBalancerName(), "toAdd", request.getInstances().toString())); } } } else { LOG.debug("No new instances to register for group {}", group.getName()); } }
private boolean shouldRegister(BaragonAgentMetadata agent, String elbName, List<LoadBalancerDescription> elbs) { Optional<LoadBalancerDescription> matchingElb = Optional.absent(); for (LoadBalancerDescription elb : elbs) { if (elbName.equals(elb.getLoadBalancerName())) { matchingElb = Optional.of(elb); } } if (!matchingElb.isPresent()) { return false; } boolean alreadyRegistered = false; for (Instance instance : matchingElb.get().getInstances()) { if (agent.getEc2().getInstanceId().get().equals(instance.getInstanceId())) { alreadyRegistered = true; } } return !alreadyRegistered && (isVpcOk(agent, matchingElb.get()) || !configuration.get().isCheckForCorrectVpc()); }
private List<DeregisterInstancesFromLoadBalancerRequest> deregisterRequests(BaragonGroup group, Collection<BaragonAgentMetadata> agents, List<LoadBalancerDescription> elbs) { List<String> agentInstanceIds = agentInstanceIds(agents); List<DeregisterInstancesFromLoadBalancerRequest> requests = new ArrayList<>(); for (LoadBalancerDescription elb : elbs) { if (group.getTrafficSources().contains(new TrafficSource(elb.getLoadBalancerName(), TrafficSourceType.CLASSIC))) { for (Instance instance : elb.getInstances()) { if (!agentInstanceIds.contains(instance.getInstanceId()) && canDeregisterAgent(group, instance.getInstanceId())) { List<Instance> instanceList = new ArrayList<>(1); instanceList.add(instance); requests.add(new DeregisterInstancesFromLoadBalancerRequest(elb.getLoadBalancerName(), instanceList)); LOG.info("Will deregister instance {} from ELB {}", instance.getInstanceId(), elb.getLoadBalancerName()); } } } } return requests; }
/** * Initial check calls elbClient to describe the ELB, same as the followup checks, because the initial * deregistration call does not return an ELB description. */ @Override public void initialCheck() { LoadBalancerDescription loadBalancerDescription = elbClient.describeLoadBalancer(elbName); checkInstanceRemoval(loadBalancerDescription); LOGGER.debug(logContext + "Initial ELB instance list: " + summarizeInstances(loadBalancerDescription.getInstances())); }
@Override public void followupCheck(int waitNum) { LoadBalancerDescription loadBalancerDescription = elbClient.describeLoadBalancer(elbName); checkInstanceRemoval(loadBalancerDescription); LOGGER.debug(logContext + "ELB instance list after wait#" + waitNum + ": " + summarizeInstances(loadBalancerDescription.getInstances())); }
/** * Returns a description of the named ELB. */ public LoadBalancerDescription describeLoadBalancer(String elbName) { LOGGER.debug("describeLoadBalancers(elbName: " + elbName + ")"); if (StringUtils.isBlank(elbName)) { throw new IllegalArgumentException("Blank elbName"); } StopWatch stopWatch = new StopWatch(); try { stopWatch.start(); DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest(); request.setLoadBalancerNames(Arrays.asList(elbName)); DescribeLoadBalancersResult result = awsElbClient.describeLoadBalancers(request); if (result == null || CollectionUtils.isEmpty(result.getLoadBalancerDescriptions())) { throw new RuntimeException("ELB '" + elbName + "' was not found"); } else if (result.getLoadBalancerDescriptions().size() > 1) { LOGGER.warn("Expected 1 ELB description for elb name '" + elbName + "', found " + result.getLoadBalancerDescriptions().size()); } return result.getLoadBalancerDescriptions().get(0); } finally { stopWatch.stop(); LOGGER.debug("describeLoadBalancers time elapsed " + stopWatch); } }
@Override public List<Integer> check(final LoadBalancerDescription loadBalancerDescription) { return loadBalancerDescription.getListenerDescriptions() .stream() .map(ListenerDescription::getListener) .map(Listener::getLoadBalancerPort) .filter(p -> !jobsProperties.getElbAllowedPorts().contains(p)) .collect(Collectors.toList()); }
public Collection<String> getLoadBalancerList(){ DescribeLoadBalancersResult loadBalancers = this.loadBalanceClient.describeLoadBalancers(); System.out.println(loadBalancers.toString()); Collection returnList = new ArrayList<String>(); List<LoadBalancerDescription> loadBalancerDescriptions = loadBalancers.getLoadBalancerDescriptions(); for( LoadBalancerDescription desc : loadBalancerDescriptions){ returnList.add(desc.getDNSName()); } return returnList; }
public LoadBalancerDescription createELB(final CreateLoadBalancerRequest request) throws Exception { new Runner<>() .retryInterval(Duration.ofSeconds(20)) .maxAttempts(5) .retryOn(e -> e instanceof AmazonServiceException) .run(() -> { logger.info("create elb, request={}", request); elb.createLoadBalancer(request); return null; }); return describeELB(request.getLoadBalancerName()); }
@Test void httpsCertChangedWithNewLocalCert() { elb.listenHTTPS = true; elb.remoteELB = new LoadBalancerDescription() .withListenerDescriptions(new ListenerDescription().withListener(new Listener("HTTPS", 443, 80))); elb.cert = new ServerCert("cert"); elb.cert.foundInLocal(); assertTrue(elb.httpsCertChanged()); }
/** * Fetches and filters a Region's ELBs * @param amazonElasticLoadBalancing * @param filter * @return */ public static List<LoadBalancerDescription> findLoadBalancers(AmazonElasticLoadBalancing amazonElasticLoadBalancing, ELBFilter filter) { List<LoadBalancerDescription> loadBalancers = amazonElasticLoadBalancing.describeLoadBalancers().getLoadBalancerDescriptions(); List<LoadBalancerDescription> result = new ArrayList<>(loadBalancers.size()); for(LoadBalancerDescription loadBalancer:loadBalancers){ if(filter.accept(loadBalancer)){ result.add(loadBalancer); } } return result; }
private ListenerDescription getExhibitorListenerDescription(LoadBalancerDescription loadBalancer) { for(ListenerDescription listenerDescription:loadBalancer.getListenerDescriptions()){ if(listenerDescription.getListener().getProtocol().toLowerCase().equals("http")){ return listenerDescription; } } throw new BootstrapException("Unable to find any listeners which supports http on ELB " + loadBalancer.getLoadBalancerName()); }
@Test public void foundCloudformationZookeeper() { LoadBalancerDescription loadBalancer = new LoadBalancerDescription(); List<ListenerDescription> listenerDescriptions = new ArrayList<>(); listenerDescriptions.add(new ListenerDescription()); loadBalancer.setListenerDescriptions(listenerDescriptions); loadBalancer.setLoadBalancerName(ENVIRONMENT + "-Zookeeper-whatever"); Assert.assertTrue(filter.accept(loadBalancer)); }
@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)); }
@Test public void externalExhibitor() { LoadBalancerDescription loadBalancer = new LoadBalancerDescription(); List<ListenerDescription> listenerDescriptions = new ArrayList<>(); listenerDescriptions.add(new ListenerDescription()); loadBalancer.setListenerDescriptions(listenerDescriptions); loadBalancer.setLoadBalancerName("exhibitor-" + ENVIRONMENT); Assert.assertFalse(filter.accept(loadBalancer)); }
@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)); }
public List<AbstractResource<?>> toLoadBalancers(List<LoadBalancerDescription> loadBalancerDescriptions, String accountId, Region region, DateTime dt) { List<AbstractResource<?>> resources = new ArrayList<>(); for (LoadBalancerDescription loadBalancerDescription : loadBalancerDescriptions) { Ec2LoadBalancer ec2LoadBalancer = new Ec2LoadBalancer(); conf(ec2LoadBalancer, accountId, region, dt); ec2LoadBalancer.setResource(loadBalancerDescription); resources.add(ec2LoadBalancer); } log.debug("{} load balancers found via api and converted to Ec2LoadBalancer", resources.size()); return resources; }
@Override @SuppressWarnings("rawtypes") protected boolean isEqual(AbstractResource newResource) { LoadBalancerDescription oldLoadBalancer = this.getResource(); Ec2LoadBalancer newEc2LoadBalancer = (Ec2LoadBalancer) newResource; LoadBalancerDescription newLoadBalancer = newEc2LoadBalancer.getResource(); if (notEqual(oldLoadBalancer.getLoadBalancerName(), newLoadBalancer.getLoadBalancerName())) return false; if (notEqual(oldLoadBalancer.getDNSName(), newLoadBalancer.getDNSName())) return false; if (notEqual(oldLoadBalancer.getCanonicalHostedZoneName(), newLoadBalancer.getCanonicalHostedZoneName())) return false; if (notEqual(oldLoadBalancer.getCanonicalHostedZoneNameID(), newLoadBalancer.getCanonicalHostedZoneNameID())) return false; if (notEqualListenerDescriptions(oldLoadBalancer.getListenerDescriptions(), newLoadBalancer.getListenerDescriptions())) return false; Policies oldPolicies = oldLoadBalancer.getPolicies(); Policies newPolicies = newLoadBalancer.getPolicies(); if (notEqualCollection(oldPolicies.getAppCookieStickinessPolicies(), newPolicies.getAppCookieStickinessPolicies())) return false; if (notEqualCollection(oldPolicies.getLBCookieStickinessPolicies(), newPolicies.getLBCookieStickinessPolicies())) return false; if (notEqualCollection(oldPolicies.getOtherPolicies(), newPolicies.getOtherPolicies())) return false; if (notBackendServerDescriptions(oldLoadBalancer.getBackendServerDescriptions(), newLoadBalancer.getBackendServerDescriptions())) return false; if (notEqualCollection(oldLoadBalancer.getAvailabilityZones(), newLoadBalancer.getAvailabilityZones())) return false; if (notEqualCollection(oldLoadBalancer.getSubnets(), newLoadBalancer.getSubnets())) return false; if (notEqual(oldLoadBalancer.getVPCId(), newLoadBalancer.getVPCId())) return false; if (notEqualCollection(oldLoadBalancer.getInstances(), newLoadBalancer.getInstances())) return false; if (notEqual(oldLoadBalancer.getHealthCheck(), newLoadBalancer.getHealthCheck())) return false; if (notEqual(oldLoadBalancer.getSourceSecurityGroup(), newLoadBalancer.getSourceSecurityGroup())) return false; if (notEqualCollection(oldLoadBalancer.getSecurityGroups(), newLoadBalancer.getSecurityGroups())) return false; if (notEqual(oldLoadBalancer.getCreatedTime(), newLoadBalancer.getCreatedTime())) return false; if (notEqual(oldLoadBalancer.getScheme(), newLoadBalancer.getScheme())) return false; return true; }
public List<LoadBalancerDescription> describeLoadBalancers() { DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest(); DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(request); List<LoadBalancerDescription> descriptions = result.getLoadBalancerDescriptions(); logger.info(String.format("Found %s load balancers %s", descriptions.size(), descriptions)); return descriptions; }