Search in sources :

Example 11 with ExternalDatabaseStatus

use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus 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);
}
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) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) Test(org.junit.jupiter.api.Test)

Example 12 with ExternalDatabaseStatus

use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.

the class AzureDatabaseResourceServiceTest method shouldReturnDeletedStatusInCaseOfMissingResourceGroup.

@Test
void shouldReturnDeletedStatusInCaseOfMissingResourceGroup() {
    when(client.getResourceGroup(RESOURCE_GROUP_NAME)).thenReturn(null);
    when(azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, databaseStack)).thenReturn(RESOURCE_GROUP_NAME);
    ExternalDatabaseStatus actual = victim.getDatabaseServerStatus(ac, databaseStack);
    assertEquals(ExternalDatabaseStatus.DELETED, actual);
}
Also used : ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) Test(org.junit.jupiter.api.Test)

Example 13 with ExternalDatabaseStatus

use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.

the class AwsRdsStatusLookupServiceTest method shouldLookupStartedExternalDatabaseStatus.

@Test
public void shouldLookupStartedExternalDatabaseStatus() {
    when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult);
    when(describeDBInstancesResult.getDBInstances()).thenReturn(List.of(dbInstance));
    when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_STARTED);
    ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack);
    assertThat(result).isEqualTo(ExternalDatabaseStatus.STARTED);
}
Also used : ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.jupiter.api.Test)

Example 14 with ExternalDatabaseStatus

use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.

the class AwsRdsStatusLookupServiceTest method shouldLookupUpdateInProgressExternalDatabaseStatus.

@Test
public void shouldLookupUpdateInProgressExternalDatabaseStatus() {
    when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult);
    when(describeDBInstancesResult.getDBInstances()).thenReturn(List.of(dbInstance));
    when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_ANY);
    ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack);
    assertThat(result).isEqualTo(ExternalDatabaseStatus.UPDATE_IN_PROGRESS);
}
Also used : ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) DescribeDBInstancesRequest(com.amazonaws.services.rds.model.DescribeDBInstancesRequest) Test(org.junit.jupiter.api.Test)

Example 15 with ExternalDatabaseStatus

use of com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus in project cloudbreak by hortonworks.

the class AwsRdsStatusLookupServiceTest method shouldLookupStoppedExternalDatabaseStatus.

@Test
public void shouldLookupStoppedExternalDatabaseStatus() {
    when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult);
    when(describeDBInstancesResult.getDBInstances()).thenReturn(List.of(dbInstance));
    when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_STOPPED);
    ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack);
    assertThat(result).isEqualTo(ExternalDatabaseStatus.STOPPED);
}
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