Java Code Examples for com.amazonaws.regions.RegionUtils#getRegions()
The following examples show how to use
com.amazonaws.regions.RegionUtils#getRegions() .
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: DirectConnectionInventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch direct connections. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<Connection>> fetchDirectConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<Connection>> connectionMap = new LinkedHashMap<>(); String expPrefix = "{\"errcode\": \"NO_RES_REG\" ,\"accountId\": \""+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Direct Connections\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ AmazonDirectConnectClient directConnectClient = (AmazonDirectConnectClient) AmazonDirectConnectClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<Connection> connectionList = directConnectClient.describeConnections().getConnections(); if(!connectionList.isEmpty() ) { log.debug("Account : " + accountId + " Type : Direct Connections "+ region.getName()+" >> " + connectionList.size()); connectionMap.put(accountId+delimiter+accountName+delimiter+region.getName(), connectionList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+"\", \"cause\":\"" +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"directconnect",e.getMessage()); } } return connectionMap; }
Example 2
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch snapshots. * * @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<Snapshot>> fetchSnapshots(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<Snapshot>> snapShots = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Snapshot\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<Snapshot> snapShotsList = ec2Client.describeSnapshots(new DescribeSnapshotsRequest().withOwnerIds(accountId)).getSnapshots();// No need to paginate as all results will be returned if( !snapShotsList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Snapshot " +region.getName() + " >> "+snapShotsList.size()); snapShots.put(accountId+delimiter+accountName+delimiter+region.getName(),snapShotsList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"snapshot",e.getMessage()); } } return snapShots; }
Example 3
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch NAT gateway 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<NatGateway>> fetchNATGatewayInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<NatGateway>> natGatwayMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Nat Gateway\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeNatGatewaysResult rslt = ec2Client.describeNatGateways(new DescribeNatGatewaysRequest()); List<NatGateway> natGatwayList =rslt.getNatGateways(); if(! natGatwayList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId + " Type : Nat Gateway "+region.getName() + " >> "+natGatwayList.size()); natGatwayMap.put(accountId+delimiter+accountName+delimiter+region.getName(), natGatwayList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"nat",e.getMessage()); } } return natGatwayMap; }
Example 4
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch network intefaces. * * @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<NetworkInterface>> fetchNetworkIntefaces(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<NetworkInterface>> niMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Network Interface\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeNetworkInterfacesResult descNIRslt = ec2Client.describeNetworkInterfaces(); List<NetworkInterface> niList = descNIRslt.getNetworkInterfaces(); if(!niList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : Network Interface " +region.getName()+" >> " + niList.size()); niMap.put(accountId+delimiter+accountName+delimiter+region.getName(),niList); } } }catch(Exception e){ log.error("Exception fetching Network Interfaces for "+region.getName() + e); log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"eni",e.getMessage()); } } return niMap; }
Example 5
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch peering connections. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<VpcPeeringConnection>> fetchPeeringConnections(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<VpcPeeringConnection>> peeringConnectionMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"peeringconnection\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<VpcPeeringConnection> peeringConnectionList = ec2Client.describeVpcPeeringConnections().getVpcPeeringConnections(); if(!peeringConnectionList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Peering Connections "+ region.getName()+" >> " + peeringConnectionList.size()); peeringConnectionMap.put(accountId+delimiter+accountName+delimiter+region.getName(), peeringConnectionList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"peeringconnection",e.getMessage()); } } return peeringConnectionMap; }
Example 6
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch security groups. * * @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<SecurityGroup>> fetchSecurityGroups(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ log.info("skipRegionseee" + skipRegions); Map<String,List<SecurityGroup>> secGrpList = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Security Group\" , \"region\":\"" ; log.info("sgregion" + RegionUtils.getRegions().toString()); for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeSecurityGroupsResult rslt = ec2Client.describeSecurityGroups(); List<SecurityGroup> secGrpListTemp = rslt.getSecurityGroups(); if( !secGrpListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Security Group "+region.getName()+" >> " + secGrpListTemp.size()); secGrpList.put(accountId+delimiter+accountName+delimiter+region.getName(),secGrpListTemp); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"sg",e.getMessage()); } } return secGrpList; }
Example 7
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch egress gateway. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<EgressOnlyInternetGateway>> fetchEgressGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<EgressOnlyInternetGateway>> egressGatewayMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"egressgateway\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<EgressOnlyInternetGateway> egressGatewayList = ec2Client.describeEgressOnlyInternetGateways(new DescribeEgressOnlyInternetGatewaysRequest()).getEgressOnlyInternetGateways(); if(!egressGatewayList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Egress Gateway "+ region.getName()+" >> " + egressGatewayList.size()); egressGatewayMap.put(accountId+delimiter+accountName+delimiter+region.getName(), egressGatewayList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"egressgateway",e.getMessage()); } } return egressGatewayMap; }
Example 8
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch internet gateway. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<InternetGateway>> fetchInternetGateway(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<InternetGateway>> internetGatewayMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"internetgateway\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<InternetGateway> internetGatewayList = ec2Client.describeInternetGateways().getInternetGateways(); if(!internetGatewayList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Internet Gateway "+ region.getName()+" >> " + internetGatewayList.size()); internetGatewayMap.put(accountId+delimiter+accountName+delimiter+region.getName(), internetGatewayList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"internetgateway",e.getMessage()); } } return internetGatewayMap; }
Example 9
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch elastic IP addresses. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<Address>> fetchElasticIPAddresses(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<Address>> elasticIPMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + InventoryConstants.ERROR_PREFIX_EC2 ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<Address> elasticIPList = ec2Client.describeAddresses().getAddresses(); if(!elasticIPList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Elastic IP "+ region.getName()+" >> " + elasticIPList.size()); elasticIPMap.put(accountId+delimiter+accountName+delimiter+region.getName(), elasticIPList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"elasticip",e.getMessage()); } } return elasticIPMap; }
Example 10
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch route tables. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<RouteTable>> fetchRouteTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<RouteTable>> routeTableMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + InventoryConstants.ERROR_PREFIX_EC2 ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<RouteTable> routeTableList = ec2Client.describeRouteTables().getRouteTables(); if(!routeTableList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Route table "+ region.getName()+" >> " + routeTableList.size()); routeTableMap.put(accountId+delimiter+accountName+delimiter+region.getName(), routeTableList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"routetable",e.getMessage()); } } return routeTableMap; }
Example 11
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch volumet 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<Volume>> fetchVolumetInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<Volume>> volumeList = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Volume\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeVolumesResult rslt = ec2Client.describeVolumes(); // No need to paginate as all volumes will be returned. List<Volume> volumeListTemp = rslt.getVolumes(); if( !volumeListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Volume "+region.getName() + " >> "+volumeListTemp.size()); volumeList.put(accountId+delimiter+accountName+delimiter+region.getName(),volumeListTemp); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"volume",e.getMessage()); } } return volumeList; }
Example 12
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch RDSDB snapshots. * * @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<DBSnapshot>> fetchRDSDBSnapshots(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<DBSnapshot>> snapshots = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"RDS Snapshot\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AmazonRDS rdsClient = AmazonRDSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeDBSnapshotsResult rslt ; List<DBSnapshot> snapshotsTemp = new ArrayList<>(); String marker = null; do{ rslt = rdsClient.describeDBSnapshots(new DescribeDBSnapshotsRequest().withIncludePublic(false).withIncludeShared(false).withMarker(marker)); snapshotsTemp.addAll(rslt.getDBSnapshots()); marker = rslt.getMarker(); }while(marker!=null); if(! snapshotsTemp.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : RDS Snapshot" +region.getName() + " >> "+snapshotsTemp.size()); snapshots.put(accountId+delimiter+accountName+delimiter+region.getName(), snapshotsTemp); } } }catch(Exception e){ if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"rdssnapshot",e.getMessage()); } } } return snapshots; }
Example 13
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch EMR 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<Cluster>> fetchEMRInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<Cluster>> clusterList = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"EMR\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ AmazonElasticMapReduce emrClient = AmazonElasticMapReduceClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<ClusterSummary> clusters = new ArrayList<>(); String marker = null; ListClustersResult clusterResult ; do{ clusterResult = emrClient.listClusters(new ListClustersRequest().withMarker(marker)); clusters.addAll(clusterResult.getClusters()); marker = clusterResult.getMarker(); }while(marker!=null); List<Cluster> clustersList = new ArrayList<>(); clusters.forEach(cluster -> { DescribeClusterResult descClstrRslt = emrClient.describeCluster(new DescribeClusterRequest().withClusterId(cluster.getId())); clustersList.add(descClstrRslt.getCluster()); }); if( !clustersList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : EMR "+region.getName() + " >> "+clustersList.size()); clusterList.put(accountId+delimiter+accountName+delimiter+region.getName(),clustersList); } } }catch(Exception e){ if(region.isServiceSupported(AmazonElasticMapReduce.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"emr",e.getMessage()); } } } return clusterList; }
Example 14
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch target groups. * * @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<TargetGroupVH>> fetchTargetGroups(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ com.amazonaws.services.elasticloadbalancingv2.AmazonElasticLoadBalancing elbClient ; Map<String,List<TargetGroupVH>> targetGrpMap = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Target Group\" , \"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; List<TargetGroupVH> targetGrpList = new ArrayList<>(); do{ DescribeTargetGroupsResult trgtGrpRslt = elbClient.describeTargetGroups(new DescribeTargetGroupsRequest().withMarker(nextMarker)); List<TargetGroup> targetGrpListTemp = trgtGrpRslt.getTargetGroups(); for(TargetGroup tg : targetGrpListTemp) { DescribeTargetHealthResult rslt = elbClient.describeTargetHealth(new DescribeTargetHealthRequest().withTargetGroupArn(tg.getTargetGroupArn())); targetGrpList.add(new TargetGroupVH(tg, rslt.getTargetHealthDescriptions())); } nextMarker = trgtGrpRslt.getNextMarker(); }while(nextMarker!=null); if( !targetGrpList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Target Group " +region.getName() + "-"+targetGrpList.size()); targetGrpMap.put(accountId+delimiter+accountName+delimiter+region.getName(), targetGrpList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"targetgroup",e.getMessage()); } } return targetGrpMap; }
Example 15
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch asg. * * @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<AutoScalingGroup>> fetchAsg(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ AmazonAutoScaling asgClient; Map<String,List<AutoScalingGroup>> asgList = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"ASG\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ List<AutoScalingGroup> asgListTemp = new ArrayList<>(); asgClient = AmazonAutoScalingClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); String nextToken = null; DescribeAutoScalingGroupsResult describeResult ; do{ describeResult = asgClient.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest().withNextToken(nextToken).withMaxRecords(asgMaxRecord)); asgListTemp.addAll(describeResult.getAutoScalingGroups()); nextToken = describeResult.getNextToken(); }while(nextToken!=null); if(!asgListTemp.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId + " Type : ASG "+region.getName()+" >> " + asgListTemp.size()); asgList.put(accountId+delimiter+accountName+delimiter+region.getName(), asgListTemp); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"asg",e.getMessage()); } } return asgList; }
Example 16
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch SSM info. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ 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; }
Example 17
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch cloud formation stack. * * @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<Stack>> fetchCloudFormationStack(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ AmazonCloudFormation cloudFormClient ; Map<String,List<Stack>> stacks = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Stack\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ List<Stack> stacksTemp = new ArrayList<>(); String nextToken = null; cloudFormClient = AmazonCloudFormationClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeStacksResult describeResult ; do{ describeResult = cloudFormClient.describeStacks(new DescribeStacksRequest().withNextToken(nextToken)); stacksTemp.addAll(describeResult.getStacks()); nextToken = describeResult.getNextToken(); }while(nextToken!=null); if(! stacksTemp.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Cloud Formation Stack "+region.getName() + " >> " + stacksTemp.size()); stacks.put(accountId+delimiter+accountName+delimiter+region.getName(), stacksTemp); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"stack",e.getMessage()); } } return stacks; }
Example 18
Source File: ECSCloud.java From amazon-ecs-plugin with MIT License | 5 votes |
public ListBoxModel doFillRegionNameItems() { final ListBoxModel options = new ListBoxModel(); for (Region region : RegionUtils.getRegions()) { options.add(region.getName()); } return options; }
Example 19
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch instances. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @param accountName the account name * @param ec2Filters the ec 2 filters * @return the map */ public static Map<String,List<Instance>> fetchInstances(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName,String ec2Filters){ Map<String,List<Instance>> instanceMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"EC2\" , \"region\":\"" ; List<String> stateNameFilters = Arrays.asList(ec2Filters.split(",")); for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<Instance> instanceList = new ArrayList<>(); DescribeInstancesResult descInstResult ; String nextToken = null; do{ descInstResult = ec2Client.describeInstances(new DescribeInstancesRequest().withNextToken(nextToken)); descInstResult.getReservations().forEach( reservation -> instanceList.addAll(reservation.getInstances().stream().filter(instance->stateNameFilters.contains(instance.getState().getName())).collect(Collectors.toList()))); nextToken = descInstResult.getNextToken(); }while(nextToken!=null); if(!instanceList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 "+ region.getName()+" >> " + instanceList.size()); instanceMap.put(accountId+delimiter+accountName+delimiter+region.getName(), instanceList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"ec2",e.getMessage()); } } return instanceMap; }
Example 20
Source File: KinesisInventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
public static Map<String,List<VideoStreamVH>> fetchVideoStreamInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<VideoStreamVH>> videoStream = new LinkedHashMap<>(); AmazonKinesisVideo amazonKinesisVideo; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource\" ,\"type\": \"videoStream\" " ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName()) && region.isServiceSupported(AmazonKinesisVideo.ENDPOINT_PREFIX)){ amazonKinesisVideo = AmazonKinesisVideoClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<StreamInfo> videoStreamListTemp = new ArrayList<>(); com.amazonaws.services.kinesisvideo.model.ListStreamsResult listStreamsResult; String nextToken = null; do{ listStreamsResult = amazonKinesisVideo.listStreams(new ListStreamsRequest().withNextToken(nextToken)); videoStreamListTemp.addAll(listStreamsResult.getStreamInfoList()); nextToken = listStreamsResult.getNextToken(); }while(nextToken!=null); List<VideoStreamVH> videoStreamList = new ArrayList<>(); for(StreamInfo streamInfo : videoStreamListTemp) { List<Attribute> tags = new ArrayList<>(); for(Entry<String, String> entry: amazonKinesisVideo.listTagsForStream(new com.amazonaws.services.kinesisvideo.model.ListTagsForStreamRequest() .withStreamARN(streamInfo.getStreamARN())).getTags().entrySet()) { tags.add(new Attribute(entry.getKey(), entry.getValue())); } videoStreamList.add(new VideoStreamVH(streamInfo,tags)); } if( !videoStreamList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : VideoStream "+region.getName() + " >> "+videoStreamList.size()); videoStream.put(accountId+delimiter+accountName+delimiter+region.getName(),videoStreamList); } } } catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId, region.getName(),"videoStream",e.getMessage()); } } return videoStream; }