@SuppressWarnings("static-access") @Test public void fetchElbInfoTest() throws Exception { mockStatic(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder.class); com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing elbClient = PowerMockito.mock(com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing.class); com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancingClientBuilder amazonElasticLoadBalancingClientBuilder = PowerMockito.mock(com.amazonaws.services.elasticloadbalancingv2.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); DescribeLoadBalancersResult elbDescResult = new DescribeLoadBalancersResult(); List<LoadBalancer> elbList = new ArrayList<>(); LoadBalancer loadBalancer = new LoadBalancer(); loadBalancer.setLoadBalancerArn("loadBalancerArn"); elbList.add(loadBalancer); elbDescResult.setLoadBalancers(elbList); when(elbClient.describeLoadBalancers(anyObject())).thenReturn(elbDescResult); com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsResult describeTagsResult = new com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsResult(); List<com.amazonaws.services.elasticloadbalancingv2.model.TagDescription> tagsList = new ArrayList<>(); com.amazonaws.services.elasticloadbalancingv2.model.TagDescription tagDescription = new com.amazonaws.services.elasticloadbalancingv2.model.TagDescription(); tagDescription.setResourceArn("loadBalancerArn"); tagDescription.setTags(new ArrayList<com.amazonaws.services.elasticloadbalancingv2.model.Tag>()); tagsList.add(tagDescription); describeTagsResult.setTagDescriptions(tagsList); when(elbClient.describeTags(anyObject())).thenReturn(describeTagsResult); assertThat(inventoryUtil.fetchElbInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
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<>(); 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; } } 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; }
InventoryUtil { 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<>(); 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; } } 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; } }
InventoryUtil { 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<>(); 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; } } 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; } private  InventoryUtil(); }
InventoryUtil { 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<>(); 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; } } 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; } private  InventoryUtil(); static Map<String,List<Instance>> fetchInstances(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName,String ec2Filters); static Map<String,List<NetworkInterface>> fetchNetworkIntefaces(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<SecurityGroup>> fetchSecurityGroups(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<AutoScalingGroup>> fetchAsg(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Stack>> fetchCloudFormationStack(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<DynamoVH>> fetchDynamoDBTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<EfsVH>> fetchEFSInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Cluster>> fetchEMRInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<LambdaVH>> fetchLambdaInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<ClassicELBVH>> fetchClassicElbInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<LoadBalancerVH>> fetchElbInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<TargetGroupVH>> fetchTargetGroups(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<NatGateway>> fetchNATGatewayInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<DBClusterVH>> fetchRDSClusterInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<DBInstanceVH>> fetchRDSInstanceInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<BucketVH>> fetchS3Info(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Subnet>> fetchSubnets(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<CheckVH>> fetchTrusterdAdvisorsChecks(BasicSessionCredentials temporaryCredentials,String accountId,String accountName ); static Map<String,List<RedshiftVH>> fetchRedshiftInfo(BasicSessionCredentials temporaryCredentials,String skipRegions,String accountId,String accountName); static Map<String,List<Volume>> fetchVolumetInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Snapshot>> fetchSnapshots(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); @SuppressWarnings("rawtypes") static Map<String,List<VpcVH>> fetchVpcInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<RestApi>> fetchApiGateways(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<UserVH>> fetchIAMUsers(BasicSessionCredentials temporaryCredentials,String accountId,String accountName); static Map<String,List<Role>> fetchIAMRoles(BasicSessionCredentials temporaryCredentials,String accountId,String accountName); static Map<String,List<DBSnapshot>> fetchRDSDBSnapshots(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<KMSKeyVH>> fetchKMSKeys(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<CloudFrontVH>> fetchCloudFrontInfo(BasicSessionCredentials temporaryCredentials,String accountId,String accountName); static Map<String,List<EbsVH>> fetchEBSInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<PhdVH>> fetchPHDInfo(BasicSessionCredentials temporaryCredentials,String accountId,String accountName); static Map<String,List<SQSVH>> fetchSQSInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<SSLCertificateVH>> fetchACMCertficateInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String account, String accountName); static Map<String,List<IAMCertificateVH>> fetchIAMCertificateInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String account, String accountName); static Map<String,List<AccountVH>> fetchAccountsInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,
			String account, String accountName); static Map<String,List<GroupVH>> fetchIAMGroups(BasicSessionCredentials temporaryCredentials,String account, String accountName); static Map<String,List<Trail>> fetchCloudTrails(BasicSessionCredentials temporaryCredentials, String skipRegions,String account, String accountName); }
InventoryUtil { 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<>(); 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; } } 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; } private  InventoryUtil(); static Map<String,List<Instance>> fetchInstances(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName,String ec2Filters); static Map<String,List<NetworkInterface>> fetchNetworkIntefaces(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<SecurityGroup>> fetchSecurityGroups(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<AutoScalingGroup>> fetchAsg(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Stack>> fetchCloudFormationStack(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<DynamoVH>> fetchDynamoDBTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<EfsVH>> fetchEFSInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Cluster>> fetchEMRInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<LambdaVH>> fetchLambdaInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<ClassicELBVH>> fetchClassicElbInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<LoadBalancerVH>> fetchElbInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<TargetGroupVH>> fetchTargetGroups(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<NatGateway>> fetchNATGatewayInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<DBClusterVH>> fetchRDSClusterInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<DBInstanceVH>> fetchRDSInstanceInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<BucketVH>> fetchS3Info(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Subnet>> fetchSubnets(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<CheckVH>> fetchTrusterdAdvisorsChecks(BasicSessionCredentials temporaryCredentials,String accountId,String accountName ); static Map<String,List<RedshiftVH>> fetchRedshiftInfo(BasicSessionCredentials temporaryCredentials,String skipRegions,String accountId,String accountName); static Map<String,List<Volume>> fetchVolumetInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Snapshot>> fetchSnapshots(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); @SuppressWarnings("rawtypes") static Map<String,List<VpcVH>> fetchVpcInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<RestApi>> fetchApiGateways(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<UserVH>> fetchIAMUsers(BasicSessionCredentials temporaryCredentials,String accountId,String accountName); static Map<String,List<Role>> fetchIAMRoles(BasicSessionCredentials temporaryCredentials,String accountId,String accountName); static Map<String,List<DBSnapshot>> fetchRDSDBSnapshots(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<KMSKeyVH>> fetchKMSKeys(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<CloudFrontVH>> fetchCloudFrontInfo(BasicSessionCredentials temporaryCredentials,String accountId,String accountName); static Map<String,List<EbsVH>> fetchEBSInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<PhdVH>> fetchPHDInfo(BasicSessionCredentials temporaryCredentials,String accountId,String accountName); static Map<String,List<SQSVH>> fetchSQSInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<SSLCertificateVH>> fetchACMCertficateInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String account, String accountName); static Map<String,List<IAMCertificateVH>> fetchIAMCertificateInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String account, String accountName); static Map<String,List<AccountVH>> fetchAccountsInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,
			String account, String accountName); static Map<String,List<GroupVH>> fetchIAMGroups(BasicSessionCredentials temporaryCredentials,String account, String accountName); static Map<String,List<Trail>> fetchCloudTrails(BasicSessionCredentials temporaryCredentials, String skipRegions,String account, String accountName);  }