@SuppressWarnings("static-access") @Test public void fetchSSMInfoTest_Exception() throws Exception { PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenThrow(new Exception()); assertThat(ec2InventoryUtil.fetchSSMInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(0)); }
public static Map<String,List<InstanceInformation>> fetchSSMInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String accountId,String accountName) { Map<String,List<InstanceInformation>> ssmInstanceList = new LinkedHashMap<>(); AWSSimpleSystemsManagement ssmClient; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE + accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"SSM\" , \"region\":\""; List<InstanceInformation> ssmInstanceListTemp ; for (Region region : RegionUtils.getRegions()) { try { if (!skipRegions.contains(region.getName())) { ssmInstanceListTemp = new ArrayList<>(); ssmClient = AWSSimpleSystemsManagementClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)) .withRegion(region.getName()).build(); String nextToken = null; DescribeInstanceInformationResult describeInstanceInfoRslt; do { describeInstanceInfoRslt = ssmClient.describeInstanceInformation( new DescribeInstanceInformationRequest().withNextToken(nextToken)); nextToken = describeInstanceInfoRslt.getNextToken(); ssmInstanceListTemp.addAll(describeInstanceInfoRslt .getInstanceInformationList()); } while (nextToken != null); if(! ssmInstanceListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : SSM "+region.getName() + " >> "+ssmInstanceListTemp.size()); ssmInstanceList.put(accountId+delimiter+accountName+delimiter+region.getName(), ssmInstanceListTemp); } } } catch (Exception e) { log.warn(expPrefix + region.getName() + InventoryConstants.ERROR_CAUSE + e.getMessage() + "\"}"); ErrorManageUtil.uploadError(accountId, region.getName(), "SSM", e.getMessage()); } } return ssmInstanceList; }
EC2InventoryUtil { public static Map<String,List<InstanceInformation>> fetchSSMInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String accountId,String accountName) { Map<String,List<InstanceInformation>> ssmInstanceList = new LinkedHashMap<>(); AWSSimpleSystemsManagement ssmClient; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE + accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"SSM\" , \"region\":\""; List<InstanceInformation> ssmInstanceListTemp ; for (Region region : RegionUtils.getRegions()) { try { if (!skipRegions.contains(region.getName())) { ssmInstanceListTemp = new ArrayList<>(); ssmClient = AWSSimpleSystemsManagementClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)) .withRegion(region.getName()).build(); String nextToken = null; DescribeInstanceInformationResult describeInstanceInfoRslt; do { describeInstanceInfoRslt = ssmClient.describeInstanceInformation( new DescribeInstanceInformationRequest().withNextToken(nextToken)); nextToken = describeInstanceInfoRslt.getNextToken(); ssmInstanceListTemp.addAll(describeInstanceInfoRslt .getInstanceInformationList()); } while (nextToken != null); if(! ssmInstanceListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : SSM "+region.getName() + " >> "+ssmInstanceListTemp.size()); ssmInstanceList.put(accountId+delimiter+accountName+delimiter+region.getName(), ssmInstanceListTemp); } } } catch (Exception e) { log.warn(expPrefix + region.getName() + InventoryConstants.ERROR_CAUSE + e.getMessage() + "\"}"); ErrorManageUtil.uploadError(accountId, region.getName(), "SSM", e.getMessage()); } } return ssmInstanceList; } }
EC2InventoryUtil { public static Map<String,List<InstanceInformation>> fetchSSMInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String accountId,String accountName) { Map<String,List<InstanceInformation>> ssmInstanceList = new LinkedHashMap<>(); AWSSimpleSystemsManagement ssmClient; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE + accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"SSM\" , \"region\":\""; List<InstanceInformation> ssmInstanceListTemp ; for (Region region : RegionUtils.getRegions()) { try { if (!skipRegions.contains(region.getName())) { ssmInstanceListTemp = new ArrayList<>(); ssmClient = AWSSimpleSystemsManagementClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)) .withRegion(region.getName()).build(); String nextToken = null; DescribeInstanceInformationResult describeInstanceInfoRslt; do { describeInstanceInfoRslt = ssmClient.describeInstanceInformation( new DescribeInstanceInformationRequest().withNextToken(nextToken)); nextToken = describeInstanceInfoRslt.getNextToken(); ssmInstanceListTemp.addAll(describeInstanceInfoRslt .getInstanceInformationList()); } while (nextToken != null); if(! ssmInstanceListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : SSM "+region.getName() + " >> "+ssmInstanceListTemp.size()); ssmInstanceList.put(accountId+delimiter+accountName+delimiter+region.getName(), ssmInstanceListTemp); } } } catch (Exception e) { log.warn(expPrefix + region.getName() + InventoryConstants.ERROR_CAUSE + e.getMessage() + "\"}"); ErrorManageUtil.uploadError(accountId, region.getName(), "SSM", e.getMessage()); } } return ssmInstanceList; } private  EC2InventoryUtil(); }
EC2InventoryUtil { public static Map<String,List<InstanceInformation>> fetchSSMInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String accountId,String accountName) { Map<String,List<InstanceInformation>> ssmInstanceList = new LinkedHashMap<>(); AWSSimpleSystemsManagement ssmClient; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE + accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"SSM\" , \"region\":\""; List<InstanceInformation> ssmInstanceListTemp ; for (Region region : RegionUtils.getRegions()) { try { if (!skipRegions.contains(region.getName())) { ssmInstanceListTemp = new ArrayList<>(); ssmClient = AWSSimpleSystemsManagementClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)) .withRegion(region.getName()).build(); String nextToken = null; DescribeInstanceInformationResult describeInstanceInfoRslt; do { describeInstanceInfoRslt = ssmClient.describeInstanceInformation( new DescribeInstanceInformationRequest().withNextToken(nextToken)); nextToken = describeInstanceInfoRslt.getNextToken(); ssmInstanceListTemp.addAll(describeInstanceInfoRslt .getInstanceInformationList()); } while (nextToken != null); if(! ssmInstanceListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : SSM "+region.getName() + " >> "+ssmInstanceListTemp.size()); ssmInstanceList.put(accountId+delimiter+accountName+delimiter+region.getName(), ssmInstanceListTemp); } } } catch (Exception e) { log.warn(expPrefix + region.getName() + InventoryConstants.ERROR_CAUSE + e.getMessage() + "\"}"); ErrorManageUtil.uploadError(accountId, region.getName(), "SSM", e.getMessage()); } } return ssmInstanceList; } private  EC2InventoryUtil(); static Map<String,List<RouteTable>> fetchRouteTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<NetworkAcl>> fetchNetworkACL(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Address>> fetchElasticIPAddresses(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<InternetGateway>> fetchInternetGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<VpnGateway>> fetchVPNGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<EgressOnlyInternetGateway>> fetchEgressGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<DhcpOptions>> fetchDHCPOptions(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<VpcPeeringConnection>> fetchPeeringConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<CustomerGateway>> fetchCustomerGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<VpnConnection>> fetchVPNConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<ReservedInstances>> fetchReservedInstances(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<InstanceInformation>> fetchSSMInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String accountId,String accountName); }
EC2InventoryUtil { public static Map<String,List<InstanceInformation>> fetchSSMInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String accountId,String accountName) { Map<String,List<InstanceInformation>> ssmInstanceList = new LinkedHashMap<>(); AWSSimpleSystemsManagement ssmClient; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE + accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"SSM\" , \"region\":\""; List<InstanceInformation> ssmInstanceListTemp ; for (Region region : RegionUtils.getRegions()) { try { if (!skipRegions.contains(region.getName())) { ssmInstanceListTemp = new ArrayList<>(); ssmClient = AWSSimpleSystemsManagementClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)) .withRegion(region.getName()).build(); String nextToken = null; DescribeInstanceInformationResult describeInstanceInfoRslt; do { describeInstanceInfoRslt = ssmClient.describeInstanceInformation( new DescribeInstanceInformationRequest().withNextToken(nextToken)); nextToken = describeInstanceInfoRslt.getNextToken(); ssmInstanceListTemp.addAll(describeInstanceInfoRslt .getInstanceInformationList()); } while (nextToken != null); if(! ssmInstanceListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : SSM "+region.getName() + " >> "+ssmInstanceListTemp.size()); ssmInstanceList.put(accountId+delimiter+accountName+delimiter+region.getName(), ssmInstanceListTemp); } } } catch (Exception e) { log.warn(expPrefix + region.getName() + InventoryConstants.ERROR_CAUSE + e.getMessage() + "\"}"); ErrorManageUtil.uploadError(accountId, region.getName(), "SSM", e.getMessage()); } } return ssmInstanceList; } private  EC2InventoryUtil(); static Map<String,List<RouteTable>> fetchRouteTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<NetworkAcl>> fetchNetworkACL(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<Address>> fetchElasticIPAddresses(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<InternetGateway>> fetchInternetGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<VpnGateway>> fetchVPNGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<EgressOnlyInternetGateway>> fetchEgressGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<DhcpOptions>> fetchDHCPOptions(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<VpcPeeringConnection>> fetchPeeringConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<CustomerGateway>> fetchCustomerGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<VpnConnection>> fetchVPNConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<ReservedInstances>> fetchReservedInstances(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName); static Map<String,List<InstanceInformation>> fetchSSMInfo(BasicSessionCredentials temporaryCredentials, String skipRegions, String accountId,String accountName);  }