com.amazonaws.services.rds.AmazonRDSClientBuilder Java Examples
The following examples show how to use
com.amazonaws.services.rds.AmazonRDSClientBuilder.
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: InventoryUtilTest.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch RDSDB snapshots test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchRDSDBSnapshotsTest() throws Exception { mockStatic(AmazonRDSClientBuilder.class); AmazonRDS rdsClient = PowerMockito.mock(AmazonRDS.class); AmazonRDSClientBuilder amazonRDSClientBuilder = PowerMockito.mock(AmazonRDSClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonRDSClientBuilder.standard()).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.withCredentials(anyObject())).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.withRegion(anyString())).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.build()).thenReturn(rdsClient); DescribeDBSnapshotsResult describeDBSnapshotsResult = new DescribeDBSnapshotsResult(); List<DBSnapshot> snapshots = new ArrayList<>(); snapshots.add(new DBSnapshot()); describeDBSnapshotsResult.setDBSnapshots(snapshots); when(rdsClient.describeDBSnapshots(anyObject())).thenReturn(describeDBSnapshotsResult); assertThat(inventoryUtil.fetchRDSDBSnapshots(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #2
Source File: TableProviderFactory.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
public TableProviderFactory() { this(AmazonEC2ClientBuilder.standard().build(), AmazonElasticMapReduceClientBuilder.standard().build(), AmazonRDSClientBuilder.standard().build(), AmazonS3ClientBuilder.standard().build()); }
Example #3
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch RDS cluster 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<DBClusterVH>> fetchRDSClusterInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<DBClusterVH>> rdsMap = new LinkedHashMap<>(); AmazonRDS rdsClient ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"RDS Cluster\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ rdsClient = AmazonRDSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeDBClustersResult rslt ; String nextMarker = null; List<DBClusterVH> rdsList = new ArrayList<>(); do{ rslt = rdsClient.describeDBClusters( new DescribeDBClustersRequest().withMarker(nextMarker)); List<DBCluster> rdsListTemp = rslt.getDBClusters(); for(DBCluster cluster : rdsListTemp){ DBClusterVH vh = new DBClusterVH(cluster,rdsClient.listTagsForResource(new ListTagsForResourceRequest(). withResourceName(cluster.getDBClusterArn())). getTagList()); rdsList.add(vh); } nextMarker = rslt.getMarker(); }while(nextMarker!=null); if( !rdsList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : RDS Cluster "+region.getName() + " >> "+rdsList.size()); rdsMap.put(accountId+delimiter+accountName+delimiter+region.getName(), rdsList); } } }catch(Exception e){ if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"rdscluster",e.getMessage()); } } } return rdsMap; }
Example #4
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 #5
Source File: InventoryUtilTest.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch RDS cluster info test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchRDSClusterInfoTest() throws Exception { mockStatic(AmazonRDSClientBuilder.class); AmazonRDS rdsClient = PowerMockito.mock(AmazonRDS.class); AmazonRDSClientBuilder amazonRDSClientBuilder = PowerMockito.mock(AmazonRDSClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonRDSClientBuilder.standard()).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.withCredentials(anyObject())).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.withRegion(anyString())).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.build()).thenReturn(rdsClient); DescribeDBClustersResult describeDBClustersResult = new DescribeDBClustersResult(); List<DBCluster> rdsList = new ArrayList<>(); DBCluster dBCluster = new DBCluster(); dBCluster.setDBClusterArn("dBClusterArn");; rdsList.add(dBCluster); describeDBClustersResult.setDBClusters(rdsList); when(rdsClient.describeDBClusters(anyObject())).thenReturn(describeDBClustersResult); ListTagsForResourceResult listTagsForResourceResult = new ListTagsForResourceResult(); listTagsForResourceResult.setTagList(new ArrayList<>()); when(rdsClient.listTagsForResource(anyObject())).thenReturn(listTagsForResourceResult); assertThat(inventoryUtil.fetchRDSClusterInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #6
Source File: InventoryUtilTest.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch RDS instance info test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchRDSInstanceInfoTest() throws Exception { mockStatic(AmazonRDSClientBuilder.class); AmazonRDS rdsClient = PowerMockito.mock(AmazonRDS.class); AmazonRDSClientBuilder amazonRDSClientBuilder = PowerMockito.mock(AmazonRDSClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonRDSClientBuilder.standard()).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.withCredentials(anyObject())).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.withRegion(anyString())).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.build()).thenReturn(rdsClient); DescribeDBInstancesResult describeDBInstancesResult = new DescribeDBInstancesResult(); List<DBInstance> rdsList = new ArrayList<>(); DBInstance dBInstance = new DBInstance(); dBInstance.setDBInstanceArn("dBInstanceArn"); rdsList.add(dBInstance); describeDBInstancesResult.setDBInstances(rdsList); when(rdsClient.describeDBInstances(anyObject())).thenReturn(describeDBInstancesResult); ListTagsForResourceResult listTagsForResourceResult = new ListTagsForResourceResult(); listTagsForResourceResult.setTagList(new ArrayList<>()); when(rdsClient.listTagsForResource(anyObject())).thenReturn(listTagsForResourceResult); assertThat(inventoryUtil.fetchRDSInstanceInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #7
Source File: AwsClient.java From cloudbreak with Apache License 2.0 | 5 votes |
public AmazonRDS createRdsClient(AwsCredentialView awsCredentialView, String region) { return AmazonRDSClientBuilder.standard() .withCredentials(getCredentialProvider(awsCredentialView)) .withClientConfiguration(getDefaultClientConfiguration()) .withRegion(region) .build(); }
Example #8
Source File: AWSRDSService.java From tutorials with MIT License | 5 votes |
public AWSRDSService() throws IOException { //Init RDS client with credentials and region. credentials = new AWSStaticCredentialsProvider(new BasicAWSCredentials("<ACCESS_KEY>", "<SECRET_KEY>")); amazonRDS = AmazonRDSClientBuilder.standard().withCredentials(credentials) .withRegion(Regions.AP_SOUTHEAST_2).build(); Properties prop = new Properties(); InputStream input = AWSRDSService.class.getClassLoader().getResourceAsStream("db.properties"); prop.load(input); db_username = prop.getProperty("db_username"); db_password = prop.getProperty("db_password"); db_database = prop.getProperty("db_database"); }
Example #9
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
/** * Fetch RDS instance 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<DBInstanceVH>> fetchRDSInstanceInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<DBInstanceVH>> dbInstMap = new LinkedHashMap<>(); AmazonRDS rdsClient ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"RDS Instance\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ rdsClient = AmazonRDSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); String nextMarker = null; DescribeDBInstancesResult rslt; List<DBInstanceVH> dbInstList = new ArrayList<>(); do{ rslt = rdsClient.describeDBInstances(new DescribeDBInstancesRequest().withMarker(nextMarker)); List<DBInstance> dbInstListTemp = rslt.getDBInstances(); for(DBInstance db : dbInstListTemp){ DBInstanceVH vh = new DBInstanceVH(db, rdsClient.listTagsForResource(new ListTagsForResourceRequest(). withResourceName(db.getDBInstanceArn())). getTagList(), db.getDBSubnetGroup().getSubnets().stream().map(subnet -> subnet.getSubnetIdentifier()).collect(Collectors.joining(",")), db.getVpcSecurityGroups().stream().map(group->group.getVpcSecurityGroupId()+":"+group.getStatus()).collect(Collectors.joining(",")) ); dbInstList.add(vh); } nextMarker = rslt.getMarker(); }while(nextMarker!=null); if(! dbInstList.isEmpty() ){ log.debug(InventoryConstants.ACCOUNT + accountId +" Type : RDS Instance" +region.getName() + " >> "+dbInstList.size()); dbInstMap.put(accountId+delimiter+accountName+delimiter+region.getName(), dbInstList); } } }catch(Exception e){ if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"rdsdb",e.getMessage()); } } } return dbInstMap; }