use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceDropTokenExceptionShouldReturnGcpResourceException.
@Test
public void testCheckWhenDbInstanceDropTokenExceptionShouldReturnGcpResourceException() throws IOException {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
DatabaseStack databaseStack = mock(DatabaseStack.class);
DatabaseServer databaseServer = mock(DatabaseServer.class);
when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
when(cloudCredential.getName()).thenReturn("credential");
when(databaseStack.getDatabaseServer()).thenReturn(databaseServer);
when(databaseServer.getServerId()).thenReturn("test");
when(gcpSQLAdminFactory.buildSQLAdmin(any(CloudCredential.class), anyString())).thenThrow(new GcpResourceException("error"));
GcpResourceException gcpResourceException = assertThrows(GcpResourceException.class, () -> underTest.check(authenticatedContext, databaseStack));
Assert.assertEquals("error", gcpResourceException.getMessage());
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceIsSuspendedShouldReturnStopped.
@Test
public void testCheckWhenDbInstanceIsSuspendedShouldReturnStopped() throws IOException {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
DatabaseStack databaseStack = mock(DatabaseStack.class);
DatabaseServer databaseServer = mock(DatabaseServer.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("test");
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);
when(instancesListResponse.isEmpty()).thenReturn(false);
DatabaseInstance databaseInstance = new DatabaseInstance();
databaseInstance.setName("test");
databaseInstance.setState("SUSPENDED");
when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
ExternalDatabaseStatus check = underTest.check(authenticatedContext, databaseStack);
Assert.assertEquals(ExternalDatabaseStatus.STOPPED, check);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceIsFailedShouldReturnDeleted.
@Test
public void testCheckWhenDbInstanceIsFailedShouldReturnDeleted() throws IOException {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
DatabaseStack databaseStack = mock(DatabaseStack.class);
DatabaseServer databaseServer = mock(DatabaseServer.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("test");
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);
when(instancesListResponse.isEmpty()).thenReturn(false);
DatabaseInstance databaseInstance = new DatabaseInstance();
databaseInstance.setName("test");
databaseInstance.setState("FAILED");
when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
ExternalDatabaseStatus check = underTest.check(authenticatedContext, databaseStack);
Assert.assertEquals(ExternalDatabaseStatus.DELETED, check);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceIsUnknownStateShouldReturnDeleted.
@Test
public void testCheckWhenDbInstanceIsUnknownStateShouldReturnDeleted() throws IOException {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
DatabaseStack databaseStack = mock(DatabaseStack.class);
DatabaseServer databaseServer = mock(DatabaseServer.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("test");
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);
when(instancesListResponse.isEmpty()).thenReturn(false);
DatabaseInstance databaseInstance = new DatabaseInstance();
databaseInstance.setName("test");
databaseInstance.setState("UNKNOWN_STATE");
when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
ExternalDatabaseStatus check = underTest.check(authenticatedContext, databaseStack);
Assert.assertEquals(ExternalDatabaseStatus.DELETED, check);
}
use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.
the class GcpDatabaseServerLaunchServiceTest method testLaunchWhenDatabaseNOTAlreadyExistAndListThrowExceptionShouldThrowGcpResourceException.
@Test
public void testLaunchWhenDatabaseNOTAlreadyExistAndListThrowExceptionShouldThrowGcpResourceException() throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("engineVersion", "1");
DatabaseServer databaseServer = DatabaseServer.builder().connectionDriver("driver").serverId("driver").connectorJarUrl("driver").engine(DatabaseEngine.POSTGRESQL).location("location").port(99).storageSize(50L).rootUserName("rootUserName").rootPassword("rootPassword").flavor("flavor").useSslEnforcement(true).params(map).build();
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
DatabaseStack databaseStack = mock(DatabaseStack.class);
PersistenceNotifier persistenceNotifier = mock(PersistenceNotifier.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
SQLAdmin sqlAdmin = mock(SQLAdmin.class);
Compute compute = mock(Compute.class);
SQLAdmin.Instances sqlAdminInstances = mock(SQLAdmin.Instances.class);
SQLAdmin.Instances.List sqlAdminInstancesList = mock(SQLAdmin.Instances.List.class);
IpMapping ipMapping = new IpMapping();
ipMapping.setIpAddress("10.0.0.0");
ipMapping.setType("PRIVATE");
GoogleJsonResponseException googleJsonResponseException = mock(GoogleJsonResponseException.class);
GoogleJsonError googleJsonError = mock(GoogleJsonError.class);
when(googleJsonResponseException.getDetails()).thenReturn(googleJsonError);
when(googleJsonError.getMessage()).thenReturn("error");
when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
when(cloudCredential.getName()).thenReturn("credential");
when(databaseStack.getDatabaseServer()).thenReturn(databaseServer);
when(gcpSQLAdminFactory.buildSQLAdmin(any(CloudCredential.class), anyString())).thenReturn(sqlAdmin);
when(gcpComputeFactory.buildCompute(any(CloudCredential.class))).thenReturn(compute);
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()).thenThrow(googleJsonResponseException);
GcpResourceException gcpResourceException = assertThrows(GcpResourceException.class, () -> underTest.launch(authenticatedContext, databaseStack, persistenceNotifier));
Assert.assertEquals("error: [ resourceType: GCP_DATABASE, resourceName: driver ]", gcpResourceException.getMessage());
}
Aggregations