com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest Java Examples
The following examples show how to use
com.amazonaws.services.elasticloadbalancing.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: Ec2Utils.java From pacbot with Apache License 2.0 | 6 votes |
/** * 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: AwsCommonProcess.java From primecloud-controller with GNU General Public License v2.0 | 6 votes |
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 #3
Source File: ElbResource.java From Baragon with Apache License 2.0 | 6 votes |
@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 #4
Source File: AwsAutoScalingDeployUtils.java From vertx-deploy-tools with Apache License 2.0 | 5 votes |
private List<ListenerDescription> describeMatchingElbListeners(String loadbalancerName, List<Integer> ports) { DescribeLoadBalancersResult loadbalancer = awsElbClient.describeLoadBalancers(new DescribeLoadBalancersRequest().withLoadBalancerNames(loadbalancerName)); LoadBalancerDescription description = loadbalancer.getLoadBalancerDescriptions().get(0); return description.getListenerDescriptions().stream() .filter(d -> ports.contains(d.getListener().getLoadBalancerPort())) .filter(d -> d.getListener().getProtocol().startsWith("HTTP")) .collect(Collectors.toList()); }
Example #5
Source File: ClassicLoadBalancer.java From Baragon with Apache License 2.0 | 5 votes |
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 #6
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
/** * Fetch elb info. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @param accountName the account name * @return the map */ public static Map<String,List<LoadBalancerVH>> fetchElbInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing elbClient ; Map<String,List<LoadBalancerVH>> elbMap = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Application ELB\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ elbClient = com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); String nextMarker = null; DescribeLoadBalancersResult descElbRslt ; List<LoadBalancer> elbList = new ArrayList<>(); do{ descElbRslt = elbClient.describeLoadBalancers(new com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancersRequest().withMarker(nextMarker)); elbList.addAll(descElbRslt.getLoadBalancers()); nextMarker = descElbRslt.getNextMarker(); }while(nextMarker!=null); if(! elbList.isEmpty() ) { List<LoadBalancerVH> elbListTemp = new ArrayList<>(); List<String> elbArns = elbList.stream().map(LoadBalancer::getLoadBalancerArn).collect(Collectors.toList()); List<com.amazonaws.services.elasticloadbalancingv2.model.TagDescription> tagDescriptions = new ArrayList<>(); int i = 0; List<String> elbArnsTemp = new ArrayList<>(); for(String elbArn : elbArns){ i++; elbArnsTemp.add(elbArn); if(i%20 == 0){ tagDescriptions.addAll(elbClient.describeTags(new com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsRequest().withResourceArns(elbArnsTemp)).getTagDescriptions()); elbArnsTemp = new ArrayList<>(); } } if(!elbArnsTemp.isEmpty()) tagDescriptions.addAll(elbClient.describeTags(new com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsRequest().withResourceArns(elbArnsTemp)).getTagDescriptions()); elbList.parallelStream().forEach(elb-> { List<List<com.amazonaws.services.elasticloadbalancingv2.model.Tag>> tagsInfo = tagDescriptions.stream().filter(tag -> tag.getResourceArn().equals( elb.getLoadBalancerArn())).map(x-> x.getTags()).collect(Collectors.toList()); List<com.amazonaws.services.elasticloadbalancingv2.model.Tag> tags = new ArrayList<>(); //****** Changes For Federated Rules Start ****** String name = elb.getLoadBalancerArn(); String accessLogBucketName = ""; boolean accessLog = false; if (name != null) { com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing appElbClient = com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder .standard() .withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)) .withRegion(region.getName()).build(); com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancerAttributesRequest request1 = new com.amazonaws.services.elasticloadbalancingv2.model.DescribeLoadBalancerAttributesRequest() .withLoadBalancerArn(name); List<LoadBalancerAttribute> listAccessLogBucketAttri = appElbClient .describeLoadBalancerAttributes(request1).getAttributes(); for (LoadBalancerAttribute help : listAccessLogBucketAttri) { String attributeBucketKey = help.getKey(); String attributeBucketValue = help.getValue(); if (attributeBucketKey.equalsIgnoreCase("access_logs.s3.enabled") && attributeBucketValue.equalsIgnoreCase("true")) { accessLog = true; } if ((attributeBucketKey.equalsIgnoreCase("access_logs.s3.bucket") && attributeBucketValue != null)) { accessLogBucketName = attributeBucketValue; } } //****** Changes For Federated Rules End ****** if(!tagsInfo.isEmpty()) tags = tagsInfo.get(0); LoadBalancerVH elbTemp = new LoadBalancerVH(elb, tags, accessLogBucketName, accessLog); synchronized(elbListTemp){ elbListTemp.add(elbTemp); } } }); log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Application ELB " +region.getName() + " >> "+elbListTemp.size()); elbMap.put(accountId+delimiter+accountName+delimiter+region.getName(),elbListTemp); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"appelb",e.getMessage()); } } return elbMap; }
Example #7
Source File: FetchElasticLoadBalancersJobTest.java From fullstop with Apache License 2.0 | 4 votes |
@Test public void testCheck() throws Exception { when(accountIdSupplierMock.get()).thenReturn(newHashSet(ACCOUNT_ID)); when(jobsPropertiesMock.getWhitelistedRegions()).thenReturn(regions); when(portsChecker.check(any(LoadBalancerDescription.class))).thenReturn(Collections.<Integer>emptyList()); when(securityGroupsChecker.check(any(), any(), any())).thenReturn(emptyMap()); when(mockAwsELBClient.describeLoadBalancers(any(DescribeLoadBalancersRequest.class))).thenReturn(mockDescribeELBResult); when(mockAwsELBClient.describeTags(any(DescribeTagsRequest.class))).thenReturn(mockDescribeTagsResult); when(mockAwsApplications.isPubliclyAccessible(anyString(), anyString(), anyListOf(String.class))) .thenReturn(Optional.of(false)); final FetchElasticLoadBalancersJob fetchELBJob = new FetchElasticLoadBalancersJob( violationSinkMock, clientProviderMock, accountIdSupplierMock, jobsPropertiesMock, securityGroupsChecker, portsChecker, mockAwsApplications, mockViolationService, fetchTaupageYamlMock, mockAmiDetailsProvider, mockEC2InstanceProvider, mock(CloseableHttpClient.class), mock(JobExceptionHandler.class)); fetchELBJob.run(); verify(accountIdSupplierMock).get(); verify(jobsPropertiesMock, atLeast(1)).getWhitelistedRegions(); verify(jobsPropertiesMock).getElbAllowedPorts(); verify(securityGroupsChecker, atLeast(1)).check(any(), any(), any()); verify(portsChecker, atLeast(1)).check(any()); verify(mockAwsELBClient).describeLoadBalancers(any(DescribeLoadBalancersRequest.class)); // maximum 20 ELB names can be requested at once. So this needs to be split into two calls. verify(mockAwsELBClient, times(2)).describeTags(any(DescribeTagsRequest.class)); verify(clientProviderMock).getClient(any(), any(String.class), any(Region.class)); verify(mockAwsApplications).isPubliclyAccessible(eq(ACCOUNT_ID), eq(REGION1), eq(asList("i1", "i2"))); verify(mockEC2InstanceProvider).getById(eq(ACCOUNT_ID), eq(getRegion(fromName(REGION1))), eq("i1")); verify(mockAmiDetailsProvider).getAmiDetails(eq(ACCOUNT_ID), eq(getRegion(fromName(REGION1))), eq("bar")); }