use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsRetryInterceptorBeanDefinitionParserTest method parseInternal_customRegionProviderConfigured_createAmazonRdsClientWithCustomRegionConfigured.
@Test
void parseInternal_customRegionProviderConfigured_createAmazonRdsClientWithCustomRegionConfigured() throws Exception {
// Arrange
ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-customRegionProvider.xml", getClass());
// Act
AmazonRDS amazonRDS = classPathXmlApplicationContext.getBean(AmazonRDS.class);
// Assert
assertThat(ReflectionTestUtils.getField(amazonRDS, "endpoint").toString()).isEqualTo("https://rds.eu-west-1.amazonaws.com");
}
use of com.amazonaws.services.rds.AmazonRDS in project cs-actions by CloudSlang.
the class CreateDBInstance method execute.
@Action(name = CREATE_DB_INSTANCE, description = CREATE_DB_INSTANCE_DESC, outputs = { @Output(value = Outputs.RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = Outputs.RETURN_RESULT, description = RETURN_RESULT_DESC), @Output(value = Outputs.EXCEPTION, description = EXCEPTION_DESC) }, responses = { @Response(text = Outputs.SUCCESS, field = Outputs.RETURN_CODE, value = Outputs.SUCCESS_RETURN_CODE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = SUCCESS_DESC), @Response(text = Outputs.FAILURE, field = Outputs.RETURN_CODE, value = Outputs.FAILURE_RETURN_CODE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, description = FAILURE_DESC) })
public Map<String, String> execute(@Param(value = ACCESS_KEY_ID, required = true, description = ACCESS_KEY_ID_DESC) final String accessKeyID, @Param(value = ACCESS_KEY, required = true, encrypted = true, description = ACCESS_KEY_DESC) final String accessKey, @Param(value = REGION, required = true, description = REGION_DESC) String region, @Param(value = DB_INSTANCE_IDENTIFIER, required = true, description = DB_INSTANCE_IDENTIFIER_DESC) String dbInstanceIdentifier, @Param(value = DB_ENGINE_NAME, required = true, description = DB_ENGINE_NAME_DESC) final String dbEngineName, @Param(value = DB_ENGINE_VERSION, required = true, description = DB_ENGINE_VERSION_DESC) final String dbEngineVersion, @Param(value = DB_INSTANCE_SIZE, required = true, description = DB_INSTANCE_SIZE_DESC) String dbInstanceSize, @Param(value = DB_USERNAME, required = true, description = DB_USERNAME_DESC) String dbUsername, @Param(value = DB_PASSWORD, required = true, encrypted = true, description = DB_PASSWORD_DESC) final String dbPassword, @Param(value = DB_STORAGE_SIZE, required = true, encrypted = true, description = DB_STORAGE_SIZE_DESC) final String dbStorageSize, @Param(value = LICENSE_MODEL, description = LICENSE_MODEL_DESC) final String licenseModel, @Param(value = AVAILABILITY_ZONE, description = AVAILABILITY_ZONE_DESC) final String availabilityZone, @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) final String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) final String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) final String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) final String proxyPassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESC) String execTimeout, @Param(value = ASYNC, description = ASYNC_DESC) String async) {
final String proxyPortVal = defaultIfEmpty(proxyPort, DefaultValues.PROXY_PORT);
final String connectTimeoutVal = defaultIfEmpty(connectTimeout, DefaultValues.CONNECT_TIMEOUT);
final String execTimeoutVal = defaultIfEmpty(execTimeout, DefaultValues.EXEC_TIMEOUT);
final String asyncVal = defaultIfEmpty(async, DefaultValues.ASYNC);
Validator validator = new Validator().validatePort(proxyPortVal, PROXY_PORT).validateInt(connectTimeoutVal, CONNECT_TIMEOUT).validateInt(execTimeoutVal, EXECUTION_TIMEOUT).validateInt(dbStorageSize, dbStorageSize).validateBoolean(asyncVal, ASYNC);
if (validator.hasErrors()) {
return getFailureResultsMap(validator.getErrors());
}
final Integer proxyPortImp = Integer.valueOf(proxyPortVal);
final Integer connectTimeoutImp = Integer.valueOf(connectTimeoutVal);
final Integer execTimeoutImp = Integer.valueOf(execTimeoutVal);
final boolean asyncImp = Boolean.parseBoolean(asyncVal);
final int dbStorageSizeImp = Integer.parseInt(dbStorageSize);
try {
final AmazonRDS amazonRDS = RDSClientBuilder.getRDSClientBuilder(accessKeyID, accessKey, proxyHost, proxyPortImp, proxyUsername, proxyPassword, connectTimeoutImp, execTimeoutImp, region, asyncImp);
final DBInstance result = AmazonRDSService.createRDSInstance(dbEngineName, dbEngineVersion, dbUsername, dbPassword, dbInstanceIdentifier, dbInstanceSize, dbStorageSizeImp, licenseModel, availabilityZone, amazonRDS);
return getSuccessResultMapDBInstance(result);
} catch (Exception e) {
return getFailureResultsMap(e);
}
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsDataSourceFactoryBeanTest method afterPropertiesSet_customUserNameSet_createsInstanceWithCustomUserNameAndIgnoresMetaDataUserName.
@Test
void afterPropertiesSet_customUserNameSet_createsInstanceWithCustomUserNameAndIgnoresMetaDataUserName() throws Exception {
AmazonRDS amazonRDS = mock(AmazonRDS.class);
DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))).thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available").withDBName("test").withDBInstanceIdentifier("test").withEngine("mysql").withMasterUsername("admin").withEndpoint(new Endpoint().withAddress("localhost").withPort(3306))));
AmazonRdsDataSourceFactoryBean amazonRdsDataSourceFactoryBean = new AmazonRdsDataSourceFactoryBean(amazonRDS, "test", "secret");
amazonRdsDataSourceFactoryBean.setUsername("superAdmin");
amazonRdsDataSourceFactoryBean.setDataSourceFactory(dataSourceFactory);
amazonRdsDataSourceFactoryBean.afterPropertiesSet();
amazonRdsDataSourceFactoryBean.getObject();
verify(dataSourceFactory, times(1)).createDataSource(new DataSourceInformation(DatabaseType.MYSQL, "localhost", 3306, "test", "superAdmin", "secret"));
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsDataSourceFactoryBeanTest method newInstance_withResourceIdResolver_createsInstanceWithResolvedName.
@Test
void newInstance_withResourceIdResolver_createsInstanceWithResolvedName() throws Exception {
// Arrange
AmazonRDS amazonRDS = mock(AmazonRDS.class);
DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
DataSource dataSource = mock(DataSource.class);
when(resourceIdResolver.resolveToPhysicalResourceId("test")).thenReturn("bar");
when(amazonRDS.describeDBInstances(new DescribeDBInstancesRequest().withDBInstanceIdentifier("bar"))).thenReturn(new DescribeDBInstancesResult().withDBInstances(new DBInstance().withDBInstanceStatus("available").withDBName("test").withDBInstanceIdentifier("bar").withEngine("mysql").withMasterUsername("admin").withEndpoint(new Endpoint().withAddress("localhost").withPort(3306))));
when(dataSourceFactory.createDataSource(new DataSourceInformation(DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"))).thenReturn(dataSource);
AmazonRdsDataSourceFactoryBean amazonRdsDataSourceFactoryBean = new AmazonRdsDataSourceFactoryBean(amazonRDS, "test", "secret");
amazonRdsDataSourceFactoryBean.setDataSourceFactory(dataSourceFactory);
amazonRdsDataSourceFactoryBean.setResourceIdResolver(resourceIdResolver);
// Act
amazonRdsDataSourceFactoryBean.afterPropertiesSet();
// Assert
assertThat(amazonRdsDataSourceFactoryBean.getObject()).isNotNull();
verify(dataSourceFactory, times(1)).createDataSource(new DataSourceInformation(DatabaseType.MYSQL, "localhost", 3306, "test", "admin", "secret"));
}
use of com.amazonaws.services.rds.AmazonRDS in project spring-cloud-aws by awspring.
the class AmazonRdsDataSourceUserTagsFactoryBeanTest method getObject_instanceWithTagsConfiguredWithCustomResourceResolverAndCustomRegion_mapWithTagsReturned.
@Test
void getObject_instanceWithTagsConfiguredWithCustomResourceResolverAndCustomRegion_mapWithTagsReturned() throws Exception {
// Arrange
AmazonRDS amazonRds = mock(AmazonRDS.class);
ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
AmazonIdentityManagement amazonIdentityManagement = mock(AmazonIdentityManagement.class);
AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean(amazonRds, "test", amazonIdentityManagement);
factoryBean.setResourceIdResolver(resourceIdResolver);
factoryBean.setRegion(Region.getRegion(Regions.EU_WEST_1));
when(resourceIdResolver.resolveToPhysicalResourceId("test")).thenReturn("stack-test");
when(amazonIdentityManagement.getUser()).thenReturn(new GetUserResult().withUser(new User("/", "aemruli", "123456789012", "arn:aws:iam::1234567890:user/aemruli", new Date())));
when(amazonRds.listTagsForResource(new ListTagsForResourceRequest().withResourceName("arn:aws:rds:eu-west-1:1234567890:db:stack-test"))).thenReturn(new ListTagsForResourceResult().withTagList(new Tag().withKey("key1").withValue("value1"), new Tag().withKey("key2").withValue("value2")));
// Act
factoryBean.afterPropertiesSet();
Map<String, String> userTagMap = factoryBean.getObject();
// Assert
assertThat(userTagMap.get("key1")).isEqualTo("value1");
assertThat(userTagMap.get("key2")).isEqualTo("value2");
}
Aggregations