com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription Java Examples

The following examples show how to use com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Ec2Utils.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the all elbs desc.
 *
 * @param elbClient the elb client
 * @param region the region
 * @param balancersRequest the balancers request
 * @return the all elbs desc
 */
public static List<LoadBalancerDescription> getAllElbsDesc(AmazonElasticLoadBalancing elbClient,
		Region region, DescribeLoadBalancersRequest balancersRequest) {

	List<LoadBalancerDescription> loadDescriptionList = new ArrayList<LoadBalancerDescription>();
	DescribeLoadBalancersResult balancersResult;
	String marker;
	do {
		balancersResult = elbClient.describeLoadBalancers(balancersRequest);
		
		marker = balancersResult.getNextMarker();
		balancersRequest.setMarker(marker);
		loadDescriptionList.addAll(balancersResult.getLoadBalancerDescriptions());

	} while (null != marker);
	
	return loadDescriptionList;
}
 
Example #2
Source File: ElbResource.java    From Baragon with Apache License 2.0 6 votes vote down vote up
@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");
  }
}
 
Example #3
Source File: ServerInstanceContext.java    From chassis with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: ZookeeperElbFilter.java    From chassis with Apache License 2.0 6 votes vote down vote up
@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;

}
 
Example #5
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public AgentCheckInResponse registerInstance(Instance instance, String id, 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);
}
 
Example #6
Source File: AwsCommonProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
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());
  }
}
 
Example #8
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
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());
  }
}
 
Example #10
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #11
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
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, RegisterBy.INSTANCE_ID))) {
      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;
}
 
Example #12
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private void enableAZ(BaragonAgentMetadata agent, String availabilityZone, LoadBalancerDescription elb) {
  LOG.info("Enabling availability zone {} in preparation for agent {}", availabilityZone, agent.getAgentId());
  List<String> availabilityZones = elb.getAvailabilityZones();
  availabilityZones.add(availabilityZone);
  EnableAvailabilityZonesForLoadBalancerRequest request = new EnableAvailabilityZonesForLoadBalancerRequest();
  request.setAvailabilityZones(availabilityZones);
  request.setLoadBalancerName(elb.getLoadBalancerName());
  elbClient.enableAvailabilityZonesForLoadBalancer(request);
}
 
Example #13
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private void addSubnet(BaragonAgentMetadata agent, LoadBalancerDescription elb) {
  LOG.info("Enabling subnet {} in preparation for agent {}", agent.getEc2().getSubnetId().get(), agent.getAgentId());
  AttachLoadBalancerToSubnetsRequest request = new AttachLoadBalancerToSubnetsRequest();
  request.setLoadBalancerName(elb.getLoadBalancerName());
  List<String> subnets = elb.getSubnets();
  subnets.add(agent.getEc2().getSubnetId().get());
  request.setSubnets(subnets);
  elbClient.attachLoadBalancerToSubnets(request);
}
 
Example #14
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private boolean isVpcOk(BaragonAgentMetadata agent, LoadBalancerDescription elb) {
  if (agent.getEc2().getVpcId().isPresent()) {
    return agent.getEc2().getVpcId().get().equals(elb.getVPCId()) || !configuration.get().isCheckForCorrectVpc();
  } else {
    return !configuration.get().isCheckForCorrectVpc();
  }
}
 
Example #15
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private List<RegisterInstancesWithLoadBalancerRequest> registerRequests(BaragonGroup group, Collection<BaragonAgentMetadata> agents, List<LoadBalancerDescription> elbs) {
  List<RegisterInstancesWithLoadBalancerRequest> requests = new ArrayList<>();
  for (BaragonAgentMetadata agent : agents) {
    try {
      for (TrafficSource source : group.getTrafficSources()) {
        if (source.getType() != TrafficSourceType.CLASSIC) {
          continue;
        }
        if (agent.getEc2().getInstanceId().isPresent()) {
          if (shouldRegister(agent, source.getName(), elbs)) {
            Instance instance = new Instance(agent.getEc2().getInstanceId().get());
            requests.add(new RegisterInstancesWithLoadBalancerRequest(source.getName(), Arrays.asList(instance)));
            checkAZEnabled(agent, source.getName(), elbs);
            LOG.info("Will register {}-{} with ELB {}", agent.getAgentId(), agent.getEc2().getInstanceId().get(), source.getName());
          } else {
            LOG.debug("Agent {} is already registered", agent);
          }
        } else {
          throw new IllegalArgumentException(String.format("Agent Instance Id must be present to register with an ELB (agent: %s)", agent.getAgentId()));
        }
      }
    } catch (Exception e) {
      LOG.error("Could not create request for BaragonAgent {} due to error: {}", agent, e);
    }
  }
  return requests;
}
 
Example #16
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
public AgentCheckInResponse removeInstance(Instance instance, String id, String elbName, String agentId) {
  Optional<LoadBalancerDescription> elb = getElb(elbName);
  if (elb.isPresent()) {
    if (elb.get().getInstances().contains(instance)) {
      DeregisterInstancesFromLoadBalancerRequest request = new DeregisterInstancesFromLoadBalancerRequest(elbName, Arrays.asList(instance));
      elbClient.deregisterInstancesFromLoadBalancer(request);
      LOG.info("Deregistered instance {} from ELB {}", request.getInstances(), request.getLoadBalancerName());
    } else {
      LOG.debug("Agent {} already de-registered from ELB {}", agentId, elbName);
    }
  }
  return new AgentCheckInResponse(TrafficSourceState.DONE, Optional.absent(), 0L);
}
 
Example #17
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 5 votes vote down vote up
private Optional<LoadBalancerDescription> getElb(String elbName) {
  DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest(Arrays.asList(elbName));
  DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(request);
  if (!result.getLoadBalancerDescriptions().isEmpty()) {
    return Optional.of(result.getLoadBalancerDescriptions().get(0));
  } else {
    return Optional.absent();
  }
}
 
Example #18
Source File: PublicAccessAutoFix.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the sg list for classic elb resource.
 *
 * @param clientMap the client map
 * @param resourceId the resource id
 * @return the sg list for classic elb resource
 * @throws Exception the exception
 */
public static List<String> getSgListForClassicElbResource(Map<String,Object> clientMap,String resourceId) throws Exception {
    AmazonElasticLoadBalancing amazonApplicationElasticLoadBalancing = (AmazonElasticLoadBalancing) clientMap.get("client");
    com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest describeLoadBalancersRequest = new com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest();
    describeLoadBalancersRequest.setLoadBalancerNames(Arrays.asList(resourceId));
    com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult balancersResult = amazonApplicationElasticLoadBalancing.describeLoadBalancers(describeLoadBalancersRequest);
    List<LoadBalancerDescription> balancers = balancersResult.getLoadBalancerDescriptions();
    return balancers.get(0).getSecurityGroups();
}
 
Example #19
Source File: ElbResource.java    From Baragon with Apache License 2.0 5 votes vote down vote up
@GET
@NoAuth
public List<LoadBalancerDescription> getAllElbs() {
  if (config.isPresent()) {
    return elbClient.describeLoadBalancers().getLoadBalancerDescriptions();
  } else {
    throw new BaragonWebException("ElbSync and related actions are not currently enabled");
  }
}
 
Example #20
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #21
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #22
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #23
Source File: ClassicELBVH.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new classic ELBVH.
 *
 * @param elb the elb
 * @param tags the tags
 */
public ClassicELBVH(LoadBalancerDescription elb,List<Tag> tags, String accessLogBucketName, boolean accessLog){
	this.elb = elb;
	this.tags = tags;
	this.accessLogBucketName = accessLogBucketName;
	this.accessLog = accessLog;
}
 
Example #24
Source File: InventoryUtilTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch classic elb info test.
 *
 * @throws Exception the exception
 */
@SuppressWarnings("static-access")
@Test
public void fetchClassicElbInfoTest() throws Exception {
    
    mockStatic(AmazonElasticLoadBalancingClientBuilder.class);
    AmazonElasticLoadBalancing elbClient = PowerMockito.mock(AmazonElasticLoadBalancing.class);
    AmazonElasticLoadBalancingClientBuilder amazonElasticLoadBalancingClientBuilder = PowerMockito.mock(AmazonElasticLoadBalancingClientBuilder.class);
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class);
    PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider);
    when(amazonElasticLoadBalancingClientBuilder.standard()).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.withCredentials(anyObject())).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.withRegion(anyString())).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.build()).thenReturn(elbClient);
    
    com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult elbDescResult = new com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult();
    List<LoadBalancerDescription> elbList = new ArrayList<>();
    LoadBalancerDescription loadBalancerDescription = new LoadBalancerDescription();
    loadBalancerDescription.setLoadBalancerName("loadBalancerName");
    elbList.add(loadBalancerDescription);
    elbDescResult.setLoadBalancerDescriptions(elbList);
    when(elbClient.describeLoadBalancers(anyObject())).thenReturn(elbDescResult);
    
    com.amazonaws.services.elasticloadbalancing.model.DescribeTagsResult describeTagsResult = new com.amazonaws.services.elasticloadbalancing.model.DescribeTagsResult();
    List<TagDescription> tagsList = new ArrayList<TagDescription>();
    TagDescription tagDescription = new TagDescription();
    tagDescription.setLoadBalancerName("loadBalancerName");
    tagDescription.setTags(new ArrayList<com.amazonaws.services.elasticloadbalancing.model.Tag>());
    tagsList.add(tagDescription);
    describeTagsResult.setTagDescriptions(tagsList);
    when(elbClient.describeTags(anyObject())).thenReturn(describeTagsResult);
    assertThat(inventoryUtil.fetchClassicElbInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(1));
    
}
 
Example #25
Source File: PortsCheckerImpl.java    From fullstop with Apache License 2.0 5 votes vote down vote up
@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());
    }
 
Example #26
Source File: AwsUtils.java    From chassis with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #27
Source File: ServerInstanceContext.java    From chassis with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #28
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #29
Source File: AwsLoadBalancerProcess.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
public void applySecurityGroups(AwsProcessClient awsProcessClient, Long loadBalancerNo) {
    // 非VPCの場合はスキップ
    if (BooleanUtils.isNotTrue(awsProcessClient.getPlatformAws().getVpc())) {
        return;
    }

    AwsLoadBalancer awsLoadBalancer = awsLoadBalancerDao.read(loadBalancerNo);

    // 現在設定されているSecurityGroup
    LoadBalancerDescription description = awsCommonProcess.describeLoadBalancer(awsProcessClient,
            awsLoadBalancer.getName());
    List<String> groupIds = description.getSecurityGroups();

    // 新しく設定するSecurityGroup
    List<String> newGroupIds = new ArrayList<String>();
    List<SecurityGroup> securityGroups = awsCommonProcess.describeSecurityGroupsByVpcId(awsProcessClient,
            awsProcessClient.getPlatformAws().getVpcId());
    for (String groupName : StringUtils.split(awsLoadBalancer.getSecurityGroups(), ",")) {
        groupName = groupName.trim();
        for (SecurityGroup securityGroup : securityGroups) {
            if (StringUtils.equals(groupName, securityGroup.getGroupName())) {
                newGroupIds.add(securityGroup.getGroupId());
                break;
            }
        }
    }

    // SecurityGroupに変更がない場合はスキップ
    if (groupIds.size() == newGroupIds.size() && groupIds.containsAll(newGroupIds)) {
        return;
    }

    // セキュリティグループを変更
    ApplySecurityGroupsToLoadBalancerRequest request = new ApplySecurityGroupsToLoadBalancerRequest();
    request.withLoadBalancerName(awsLoadBalancer.getName());
    request.withSecurityGroups(newGroupIds);
    awsProcessClient.getElbClient().applySecurityGroupsToLoadBalancer(request);

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-200225", awsLoadBalancer.getName()));
    }

    // イベントログ出力
    processLogger.debug(null, null, "AwsElbSecurityGroupsConfig",
            new Object[] { awsProcessClient.getPlatform().getPlatformName(), awsLoadBalancer.getName() });
}
 
Example #30
Source File: ClassicLoadBalancer.java    From Baragon with Apache License 2.0 4 votes vote down vote up
private void checkAZEnabled(BaragonAgentMetadata agent, String elbName, List<LoadBalancerDescription> elbs) {
  for (LoadBalancerDescription elb : elbs) {
    checkAZEnabled(agent, elbName, elb);
  }
}