Search in sources :

Example 1 with ExternalDatabaseStatus

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());
    }
}
Also used : DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) Status(com.sequenceiq.redbeams.api.model.common.Status) DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus)

Example 2 with ExternalDatabaseStatus

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;
}
Also used : DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)

Example 3 with ExternalDatabaseStatus

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);
}
Also used : InstancesListResponse(com.google.api.services.sqladmin.model.InstancesListResponse) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.cloudbreak.cloud.model.DatabaseServer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) SQLAdmin(com.google.api.services.sqladmin.SQLAdmin) DatabaseInstance(com.google.api.services.sqladmin.model.DatabaseInstance) Settings(com.google.api.services.sqladmin.model.Settings) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) Test(org.junit.jupiter.api.Test)

Example 4 with ExternalDatabaseStatus

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);
}
Also used : InstancesListResponse(com.google.api.services.sqladmin.model.InstancesListResponse) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.cloudbreak.cloud.model.DatabaseServer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) SQLAdmin(com.google.api.services.sqladmin.SQLAdmin) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) Test(org.junit.jupiter.api.Test)

Example 5 with ExternalDatabaseStatus

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);
}
Also used : ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)17 Test (org.junit.jupiter.api.Test)13 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 SQLAdmin (com.google.api.services.sqladmin.SQLAdmin)7 InstancesListResponse (com.google.api.services.sqladmin.model.InstancesListResponse)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 DatabaseServer (com.sequenceiq.cloudbreak.cloud.model.DatabaseServer)7 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)7 DatabaseInstance (com.google.api.services.sqladmin.model.DatabaseInstance)6 DescribeDBInstancesRequest (com.amazonaws.services.rds.model.DescribeDBInstancesRequest)4 Settings (com.google.api.services.sqladmin.model.Settings)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 DetailedDBStackStatus (com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus)2 RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)2 Event (reactor.bus.Event)2 Status (com.sequenceiq.redbeams.api.model.common.Status)1 StartDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerFailed)1 StartDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerRequest)1 StartDatabaseServerSuccess (com.sequenceiq.redbeams.flow.redbeams.start.event.StartDatabaseServerSuccess)1 StopDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.stop.event.StopDatabaseServerFailed)1