use of com.google.api.services.sqladmin.model.InstancesListResponse 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.google.api.services.sqladmin.model.InstancesListResponse 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.google.api.services.sqladmin.model.InstancesListResponse in project cloudbreak by hortonworks.
the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceIsRunnableAlwaysShouldReturnStarted.
@Test
public void testCheckWhenDbInstanceIsRunnableAlwaysShouldReturnStarted() 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("RUNNABLE");
Settings settings = new Settings();
settings.setActivationPolicy("ALWAYS");
databaseInstance.setSettings(settings);
when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
ExternalDatabaseStatus check = underTest.check(authenticatedContext, databaseStack);
Assert.assertEquals(ExternalDatabaseStatus.STARTED, check);
}
use of com.google.api.services.sqladmin.model.InstancesListResponse in project cloudbreak by hortonworks.
the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceIsTESTShouldReturnDeleted.
@Test
public void testCheckWhenDbInstanceIsTESTShouldReturnDeleted() 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("TEST");
when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
ExternalDatabaseStatus check = underTest.check(authenticatedContext, databaseStack);
Assert.assertEquals(ExternalDatabaseStatus.UPDATE_IN_PROGRESS, check);
}
use of com.google.api.services.sqladmin.model.InstancesListResponse 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);
}
Aggregations