Search in sources :

Example 16 with AmazonRDS

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");
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) Test(org.junit.jupiter.api.Test)

Example 17 with AmazonRDS

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);
    }
}
Also used : DBInstance(com.amazonaws.services.rds.model.DBInstance) OutputsUtil.getSuccessResultMapDBInstance(io.cloudslang.content.amazon.utils.OutputsUtil.getSuccessResultMapDBInstance) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) Validator(io.cloudslang.content.amazon.entities.validators.Validator) CreateDBInstanceAction(io.cloudslang.content.amazon.entities.constants.Descriptions.CreateDBInstanceAction) Action(com.hp.oo.sdk.content.annotations.Action) ProvisionProductAction(io.cloudslang.content.amazon.entities.constants.Descriptions.ProvisionProductAction)

Example 18 with AmazonRDS

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"));
}
Also used : DataSourceFactory(io.awspring.cloud.jdbc.datasource.DataSourceFactory) DBInstance(com.amazonaws.services.rds.model.DBInstance) Endpoint(com.amazonaws.services.rds.model.Endpoint) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) DataSourceInformation(io.awspring.cloud.jdbc.datasource.DataSourceInformation) DescribeDBInstancesResult(com.amazonaws.services.rds.model.DescribeDBInstancesResult) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.jupiter.api.Test)

Example 19 with AmazonRDS

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"));
}
Also used : DataSourceFactory(io.awspring.cloud.jdbc.datasource.DataSourceFactory) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) DBInstance(com.amazonaws.services.rds.model.DBInstance) Endpoint(com.amazonaws.services.rds.model.Endpoint) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) DataSourceInformation(io.awspring.cloud.jdbc.datasource.DataSourceInformation) DescribeDBInstancesResult(com.amazonaws.services.rds.model.DescribeDBInstancesResult) DataSource(javax.sql.DataSource) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.jupiter.api.Test)

Example 20 with AmazonRDS

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");
}
Also used : GetUserResult(com.amazonaws.services.identitymanagement.model.GetUserResult) User(com.amazonaws.services.identitymanagement.model.User) ResourceIdResolver(io.awspring.cloud.core.env.ResourceIdResolver) AmazonRDS(com.amazonaws.services.rds.AmazonRDS) ListTagsForResourceRequest(com.amazonaws.services.rds.model.ListTagsForResourceRequest) ListTagsForResourceResult(com.amazonaws.services.rds.model.ListTagsForResourceResult) Tag(com.amazonaws.services.rds.model.Tag) AmazonIdentityManagement(com.amazonaws.services.identitymanagement.AmazonIdentityManagement) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

AmazonRDS (com.amazonaws.services.rds.AmazonRDS)27 Test (org.junit.jupiter.api.Test)24 DBInstance (com.amazonaws.services.rds.model.DBInstance)15 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)15 DescribeDBInstancesResult (com.amazonaws.services.rds.model.DescribeDBInstancesResult)14 Endpoint (com.amazonaws.services.rds.model.Endpoint)10 DataSource (javax.sql.DataSource)9 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)7 ClassPathResource (org.springframework.core.io.ClassPathResource)7 DataSourceFactory (io.awspring.cloud.jdbc.datasource.DataSourceFactory)6 DataSourceInformation (io.awspring.cloud.jdbc.datasource.DataSourceInformation)6 AmazonIdentityManagement (com.amazonaws.services.identitymanagement.AmazonIdentityManagement)5 GetUserResult (com.amazonaws.services.identitymanagement.model.GetUserResult)5 User (com.amazonaws.services.identitymanagement.model.User)5 ListTagsForResourceRequest (com.amazonaws.services.rds.model.ListTagsForResourceRequest)5 ListTagsForResourceResult (com.amazonaws.services.rds.model.ListTagsForResourceResult)5 Date (java.util.Date)5 RetryContext (org.springframework.retry.RetryContext)5 RetryContextSupport (org.springframework.retry.context.RetryContextSupport)5