Search in sources :

Example 81 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class RedbeamsTerminationServiceTest method setup.

@BeforeEach
void setup() {
    dbStack = new DBStack();
    dbStack.setId(1L);
    DBStackStatus dbStackStatus = new DBStackStatus();
    dbStack.setDBStackStatus(dbStackStatus);
    dbStack.getDbStackStatus().setStatus(Status.AVAILABLE);
    dbStack2 = new DBStack();
    dbStack2.setId(2L);
    dbStackStatus = new DBStackStatus();
    dbStack2.setDBStackStatus(dbStackStatus);
    dbStack2.getDbStackStatus().setStatus(Status.AVAILABLE);
    server = new DatabaseServerConfig();
    server.setId(1L);
    server.setResourceCrn(SERVER_CRN);
    server.setResourceStatus(ResourceStatus.SERVICE_MANAGED);
    server2 = new DatabaseServerConfig();
    server2.setId(2L);
    server2.setResourceCrn(SERVER_2_CRN);
    server2.setResourceStatus(ResourceStatus.SERVICE_MANAGED);
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus) DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 82 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class DeregisterDatabaseServerHandlerTest method testDeleteDatabaseServerConfigIfExists.

@Test
public void testDeleteDatabaseServerConfigIfExists() {
    mockDeregisterEvent();
    DBStack dbStack = new DBStack();
    dbStack.setResourceCrn(RESOURCE_CRN);
    when(dbStackService.getById(RESOURCE_ID)).thenReturn(dbStack);
    DatabaseServerConfig databaseServerConfig = new DatabaseServerConfig();
    when(databaseServerConfigService.getByCrn(any(Crn.class))).thenReturn(Optional.of(databaseServerConfig));
    underTest.accept(event);
    verify(databaseServerConfigService).delete(databaseServerConfig);
    verify(eventBus).notify(any(Object.class), any(Event.class));
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) Event(reactor.bus.Event) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Test(org.junit.jupiter.api.Test)

Example 83 with DBStack

use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.

the class UpdateDatabaseServerRegistrationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent handlerEvent) {
    Event<UpdateDatabaseServerRegistrationRequest> event = handlerEvent.getEvent();
    LOGGER.debug("Received event: {}", event);
    UpdateDatabaseServerRegistrationRequest request = event.getData();
    DBStack dbStack = request.getDBStack();
    List<CloudResource> dbResources = request.getDbResources();
    Selectable response;
    try {
        DatabaseServerConfig dbServerConfig = databaseServerConfigService.getByCrn(Crn.safeFromString(dbStack.getResourceCrn())).orElseThrow(() -> new IllegalStateException("Cannot find database server " + dbStack.getResourceCrn()));
        CloudResource dbHostname = cloudResourceHelper.getResourceTypeFromList(ResourceType.RDS_HOSTNAME, dbResources).orElseThrow(() -> new IllegalStateException("DB hostname not found for allocated database."));
        CloudResource dbPort = cloudResourceHelper.getResourceTypeFromList(ResourceType.RDS_PORT, dbResources).orElseThrow(() -> new IllegalStateException("DB port not found for allocated database."));
        CloudPlatform cloudPlatform = CloudPlatform.valueOf(dbStack.getCloudPlatform());
        String dbHostnameString = dbHostname.getName();
        dbServerConfig.setHost(dbHostnameString);
        dbServerConfig.setPort(Integer.parseInt(dbPort.getName()));
        String updatedUserName = userGeneratorService.updateUserName(dbServerConfig.getConnectionUserName(), Optional.of(cloudPlatform), dbHostnameString);
        dbServerConfig.setConnectionUserName(updatedUserName);
        databaseServerConfigService.update(dbServerConfig);
        CloudContext cloudContext = request.getCloudContext();
        databaseServerSslCertificateSyncService.syncSslCertificateIfNeeded(cloudContext, request.getCloudCredential(), dbStack, request.getDatabaseStack());
        response = new UpdateDatabaseServerRegistrationSuccess(request.getResourceId());
        LOGGER.debug("Database server registration update successfully finished for {}", cloudContext);
    } catch (Exception e) {
        response = new UpdateDatabaseServerRegistrationFailed(request.getResourceId(), e);
        LOGGER.warn("Error updating the database server registration:", e);
    }
    return response;
}
Also used : UpdateDatabaseServerRegistrationRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationRequest) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) UpdateDatabaseServerRegistrationFailed(com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationFailed) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) UpdateDatabaseServerRegistrationSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.register.UpdateDatabaseServerRegistrationSuccess) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)83 Test (org.junit.jupiter.api.Test)28 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 Test (org.junit.Test)13 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)7 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)7 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)7 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)6 Credential (com.sequenceiq.redbeams.dto.Credential)6 RedbeamsFailureEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsFailureEvent)6 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)5 CloudDatabaseServerSslCertificate (com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate)5 RedbeamsEvent (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Location (com.sequenceiq.cloudbreak.cloud.model.Location)4