use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class GcpDatabaseServerTerminateServiceTest method testTerminateWhenDatabaseIsPresentedAndListThrowExceptionShouldDeleteDatabaseFails.
@Test
public void testTerminateWhenDatabaseIsPresentedAndListThrowExceptionShouldDeleteDatabaseFails() throws Exception {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
DatabaseStack databaseStack = mock(DatabaseStack.class);
DatabaseServer databaseServer = mock(DatabaseServer.class);
PersistenceNotifier persistenceNotifier = mock(PersistenceNotifier.class);
SQLAdmin sqlAdmin = mock(SQLAdmin.class);
SQLAdmin.Instances sqlAdminInstances = mock(SQLAdmin.Instances.class);
SQLAdmin.Instances.List sqlAdminInstancesList = mock(SQLAdmin.Instances.List.class);
GoogleJsonResponseException googleJsonResponseException = mock(GoogleJsonResponseException.class);
when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
when(cloudCredential.getName()).thenReturn("credential");
when(databaseStack.getDatabaseServer()).thenReturn(databaseServer);
when(databaseServer.getServerId()).thenReturn("server-1");
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location(region("region"), availabilityZone("az1")));
when(gcpSQLAdminFactory.buildSQLAdmin(any(CloudCredential.class), anyString())).thenReturn(sqlAdmin);
when(gcpStackUtil.getProjectId(any(CloudCredential.class))).thenReturn("project-id");
when(sqlAdmin.instances()).thenReturn(sqlAdminInstances);
when(sqlAdminInstances.list(anyString())).thenReturn(sqlAdminInstancesList);
GoogleJsonError googleJsonError = mock(GoogleJsonError.class);
when(googleJsonResponseException.getDetails()).thenReturn(googleJsonError);
when(googleJsonError.getMessage()).thenReturn("error");
when(sqlAdminInstancesList.execute()).thenThrow(googleJsonResponseException);
GcpResourceException gcpResourceException = assertThrows(GcpResourceException.class, () -> underTest.terminate(authenticatedContext, databaseStack, persistenceNotifier));
Assert.assertEquals("error: [ resourceType: GCP_DATABASE, resourceName: server-1 ]", gcpResourceException.getMessage());
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class GcpDatabaseServerTerminateServiceTest method testTerminateWhenDatabaseIsPresentedAndDeleteThrowExceptionShouldDeleteDatabaseFails.
@Test
public void testTerminateWhenDatabaseIsPresentedAndDeleteThrowExceptionShouldDeleteDatabaseFails() throws Exception {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
DatabaseStack databaseStack = mock(DatabaseStack.class);
DatabaseServer databaseServer = mock(DatabaseServer.class);
PersistenceNotifier persistenceNotifier = mock(PersistenceNotifier.class);
SQLAdmin sqlAdmin = mock(SQLAdmin.class);
SQLAdmin.Instances sqlAdminInstances = mock(SQLAdmin.Instances.class);
SQLAdmin.Instances.List sqlAdminInstancesList = mock(SQLAdmin.Instances.List.class);
InstancesListResponse instancesListResponse = mock(InstancesListResponse.class);
when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
when(cloudCredential.getName()).thenReturn("credential");
when(databaseStack.getDatabaseServer()).thenReturn(databaseServer);
when(databaseServer.getServerId()).thenReturn("server-1");
when(gcpSQLAdminFactory.buildSQLAdmin(any(CloudCredential.class), anyString())).thenReturn(sqlAdmin);
when(gcpStackUtil.getProjectId(any(CloudCredential.class))).thenReturn("project-id");
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location(region("region"), availabilityZone("az1")));
when(sqlAdmin.instances()).thenReturn(sqlAdminInstances);
when(sqlAdminInstances.list(anyString())).thenReturn(sqlAdminInstancesList);
when(sqlAdminInstancesList.execute()).thenReturn(instancesListResponse);
DatabaseInstance databaseInstance = new DatabaseInstance();
databaseInstance.setName("server-1");
databaseInstance.setState("RUNNABLE");
Settings settings = new Settings();
settings.setActivationPolicy("ALWAYS");
databaseInstance.setSettings(settings);
when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
SQLAdmin.Instances.Delete delete = mock(SQLAdmin.Instances.Delete.class);
GoogleJsonResponseException googleJsonResponseException = mock(GoogleJsonResponseException.class);
when(sqlAdminInstances.delete(anyString(), anyString())).thenReturn(delete);
when(delete.execute()).thenThrow(googleJsonResponseException);
when(delete.setPrettyPrint(anyBoolean())).thenReturn(delete);
GoogleJsonError googleJsonError = mock(GoogleJsonError.class);
when(googleJsonResponseException.getDetails()).thenReturn(googleJsonError);
when(googleJsonError.getMessage()).thenReturn("error");
GcpResourceException gcpResourceException = assertThrows(GcpResourceException.class, () -> underTest.terminate(authenticatedContext, databaseStack, persistenceNotifier));
Assert.assertEquals("error: [ resourceType: GCP_DATABASE, resourceName: server-1 ]", gcpResourceException.getMessage());
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class GcpDatabaseServerTerminateServiceTest method testTerminateWhenDatabaseIsPresentedShouldDeleteDatabase.
@Test
public void testTerminateWhenDatabaseIsPresentedShouldDeleteDatabase() throws Exception {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
DatabaseStack databaseStack = mock(DatabaseStack.class);
DatabaseServer databaseServer = mock(DatabaseServer.class);
PersistenceNotifier persistenceNotifier = mock(PersistenceNotifier.class);
SQLAdmin sqlAdmin = mock(SQLAdmin.class);
SQLAdmin.Instances sqlAdminInstances = mock(SQLAdmin.Instances.class);
SQLAdmin.Instances.List sqlAdminInstancesList = mock(SQLAdmin.Instances.List.class);
InstancesListResponse instancesListResponse = mock(InstancesListResponse.class);
when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
when(cloudCredential.getName()).thenReturn("credential");
when(databaseStack.getDatabaseServer()).thenReturn(databaseServer);
when(databaseServer.getServerId()).thenReturn("server-1");
when(gcpSQLAdminFactory.buildSQLAdmin(any(CloudCredential.class), anyString())).thenReturn(sqlAdmin);
when(gcpStackUtil.getProjectId(any(CloudCredential.class))).thenReturn("project-id");
when(sqlAdmin.instances()).thenReturn(sqlAdminInstances);
when(sqlAdminInstances.list(anyString())).thenReturn(sqlAdminInstancesList);
when(sqlAdminInstancesList.execute()).thenReturn(instancesListResponse);
DatabaseInstance databaseInstance = new DatabaseInstance();
databaseInstance.setName("server-1");
databaseInstance.setState("RUNNABLE");
Settings settings = new Settings();
settings.setActivationPolicy("ALWAYS");
databaseInstance.setSettings(settings);
when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
SQLAdmin.Instances.Delete delete = mock(SQLAdmin.Instances.Delete.class);
Operation operation = mock(Operation.class);
when(sqlAdminInstances.delete(anyString(), anyString())).thenReturn(delete);
when(delete.execute()).thenReturn(operation);
when(delete.setPrettyPrint(anyBoolean())).thenReturn(delete);
when(operation.getError()).thenReturn(null);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location(region("region"), availabilityZone("az1")));
doNothing().when(databasePollerService).terminateDatabasePoller(any(AuthenticatedContext.class), anyList());
List<CloudResource> terminate = underTest.terminate(authenticatedContext, databaseStack, persistenceNotifier);
Assert.assertEquals(1, terminate.size());
Assert.assertEquals("server-1", terminate.get(0).getName());
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class AwsRdsLaunchServiceTest method createDatabaseStack.
private DatabaseStack createDatabaseStack(boolean useSslEnforcement, boolean sslCertificateIdentifierDefined) {
Subnet subnet = new Subnet(SUBNET_CIDR);
Network network = new Network(subnet, List.of(NETWORK_CIDR), OutboundInternetTraffic.ENABLED);
network.putParameter("subnetId", SUBNET_ID);
network.putParameter("vpcCidr", NETWORK_CIDR);
Security security = new Security(Collections.emptyList(), List.of(SECURITY_GROUP_ID));
DatabaseServer databaseServer = DatabaseServer.builder().useSslEnforcement(useSslEnforcement).params(sslCertificateIdentifierDefined ? Map.of(DatabaseServer.SSL_CERTIFICATE_IDENTIFIER, SSL_CERTIFICATE_IDENTIFIER) : Map.of()).security(security).build();
return new DatabaseStack(network, databaseServer, Collections.emptyMap(), null);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseServer in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method terminateDatabaseServerWithDeleteProtectionTest.
@Test
void terminateDatabaseServerWithDeleteProtectionTest() throws Exception {
DatabaseServer databaseServer = mock(DatabaseServer.class);
when(dbStack.getDatabaseServer()).thenReturn(databaseServer);
when(databaseServer.getServerId()).thenReturn(DB_INSTANCE_IDENTIFIER);
PersistenceNotifier persistenceNotifier = mock(PersistenceNotifier.class);
DescribeDBInstancesResult describeDBInstancesResult = mock(DescribeDBInstancesResult.class);
when(awsRdsStatusLookupService.getDescribeDBInstancesResultForDeleteProtection(any(), any())).thenReturn(describeDBInstancesResult);
when(awsRdsStatusLookupService.isDeleteProtectionEnabled(describeDBInstancesResult)).thenReturn(true);
underTest.terminateDatabaseServer(authenticatedContext, dbStack, Collections.emptyList(), persistenceNotifier, true);
verify(awsRdsModifyService, times(1)).disableDeleteProtection(any(), any());
verify(awsRdsTerminateService, times(1)).terminate(authenticatedContext, dbStack, true, persistenceNotifier, Collections.emptyList());
}
Aggregations