use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.
the class DBStackStatusSyncService method sync.
public void sync(DBStack dbStack) {
DetailedDBStackStatus detailedDBStackStatus = getDetailedDBStackStatusFromProvider(dbStack);
Status status = detailedDBStackStatus.getStatus();
if (dbStack.getStatus() != status) {
if (status == null) {
LOGGER.warn(":::Auto sync::: Can not update DBStack status because 'ExternalDatabaseStatus.{}' is mapped to 'null'", detailedDBStackStatus);
} else {
LOGGER.debug(":::Auto sync::: Update DB Stack Status from '{}' to '{}'", dbStack.getStatus(), status);
dbStackStatusUpdater.updateStatus(dbStack.getId(), detailedDBStackStatus);
}
}
if (status != null && Status.getUnscheduleAutoSyncStatuses().contains(status)) {
LOGGER.debug(":::Auto sync::: Unschedule DB Stack Status sync as the status is '{}'", status);
dbStackJobService.unschedule(dbStack.getId(), dbStack.getName());
}
}
use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.
the class DBStackStatusSyncService method getDetailedDBStackStatusFromProvider.
private DetailedDBStackStatus getDetailedDBStackStatusFromProvider(DBStack dbStack) {
Optional<ExternalDatabaseStatus> externalDatabaseStatus = getExternalDatabaseStatus(dbStack);
DetailedDBStackStatus detailedDBStackStatus = externalDatabaseStatus.map(this::convert).orElse(DetailedDBStackStatus.UNKNOWN);
LOGGER.debug(":::Auto sync::: ExternalDatabaseStatus.{} got converted to DetailedDBStackStatus.{}", externalDatabaseStatus, detailedDBStackStatus);
return detailedDBStackStatus;
}
use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.
the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceIsRunnableNOTAlwaysShouldReturnStarted.
@Test
public void testCheckWhenDbInstanceIsRunnableNOTAlwaysShouldReturnStarted() 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("NOT_ALWAYS");
databaseInstance.setSettings(settings);
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.ExternalDatabaseStatus in project cloudbreak by hortonworks.
the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceNotAvailableShouldReturnDeleted.
@Test
public void testCheckWhenDbInstanceNotAvailableShouldReturnDeleted() 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(true);
ExternalDatabaseStatus check = underTest.check(authenticatedContext, databaseStack);
Assert.assertEquals(ExternalDatabaseStatus.DELETED, check);
}
use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.
the class AwsRdsStatusLookupServiceTest method shouldReturnDeletedInCaseOfDBInstanceNotFoundException.
@Test
public void shouldReturnDeletedInCaseOfDBInstanceNotFoundException() {
when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenThrow(DBInstanceNotFoundException.class);
ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack);
assertThat(result).isEqualTo(ExternalDatabaseStatus.DELETED);
}
Aggregations