com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest Java Examples

The following examples show how to use com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest. 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: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public Collection<LoadBalancer> getAllLoadBalancers() {
  Collection<LoadBalancer> loadBalancers = new HashSet<>();
  DescribeLoadBalancersRequest loadBalancersRequest = new DescribeLoadBalancersRequest();
  DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(loadBalancersRequest);
  String nextPage = result.getNextMarker();
  loadBalancers.addAll(result.getLoadBalancers());

  while (!Strings.isNullOrEmpty(nextPage)) {
    loadBalancersRequest = new DescribeLoadBalancersRequest()
        .withMarker(nextPage);
    result = elbClient.describeLoadBalancers(loadBalancersRequest);
    nextPage = result.getNextMarker();
    loadBalancers.addAll(result.getLoadBalancers());
  }

  return loadBalancers;
}
 
Example #2
Source File: ApplicationLoadBalancer.java    From Baragon with Apache License 2.0 6 votes vote down vote up
public Optional<LoadBalancer> getLoadBalancer(String loadBalancer) {
  DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest()
      .withNames(loadBalancer);

  try {
    List<LoadBalancer> maybeLoadBalancer = elbClient
        .describeLoadBalancers(request)
        .getLoadBalancers();

    if (maybeLoadBalancer.size() > 0) {
      return Optional.of(maybeLoadBalancer.get(0));
    } else {
      return Optional.absent();
    }
  } catch (LoadBalancerNotFoundException notFound) {
    LOG.warn("Could not find load balancer with name {}", loadBalancer);
    return Optional.absent();
  }
}
 
Example #3
Source File: PublicAccessAutoFix.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the sg list for app elb resource.
 *
 * @param clientMap the client map
 * @param resourceId the resource id
 * @return the sg list for app elb resource
 * @throws Exception the exception
 */
public static List<String> getSgListForAppElbResource(Map<String,Object> clientMap,String resourceId) throws Exception {
    com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing amazonApplicationElasticLoadBalancing = (com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing) clientMap.get("client");
    DescribeLoadBalancersRequest describeLoadBalancersRequest = new DescribeLoadBalancersRequest();
    describeLoadBalancersRequest.setLoadBalancerArns(Arrays.asList(resourceId));
    DescribeLoadBalancersResult balancersResult = amazonApplicationElasticLoadBalancing.describeLoadBalancers(describeLoadBalancersRequest);
    List<LoadBalancer> balancers = balancersResult.getLoadBalancers();
    return balancers.get(0).getSecurityGroups();
}
 
Example #4
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();
}