Search in sources :

Example 26 with DBStack

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

the class RedbeamsStopService method stopDatabaseServer.

public void stopDatabaseServer(String crn) {
    DBStack dbStack = dbStackService.getByCrn(crn);
    MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Stop called for: {}", dbStack);
    }
    if (dbStack.getStatus().isStopInProgressOrCompleted()) {
        LOGGER.debug("DatabaseServer with crn {} is already being stopped", dbStack.getResourceCrn());
        return;
    }
    dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.STOP_REQUESTED);
    flowManager.notify(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), new RedbeamsEvent(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), dbStack.getId()));
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

Example 27 with DBStack

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

the class DatabaseServerConfigTest method testUnsetRelationsToEntitiesToBeDeleted.

@Test
public void testUnsetRelationsToEntitiesToBeDeleted() {
    config.setDbStack(new DBStack());
    Set<DatabaseConfig> databases = new HashSet<>();
    databases.add(new DatabaseConfig());
    config.setDatabases(databases);
    config.unsetRelationsToEntitiesToBeDeleted();
    assertFalse(config.getDbStack().isPresent());
    assertTrue(config.getDatabases().isEmpty());
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with DBStack

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

the class AbstractRedbeamsProvisionActionTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    dbStack = new DBStack();
    dbStack.setId(101L);
    dbStack.setResourceCrn(CrnTestUtil.getDatabaseServerCrnBuilder().setAccountId("acc").setResource("resource").build().toString());
    dbStack.setName("mystack");
    dbStack.setRegion("us-east-1");
    dbStack.setAvailabilityZone("us-east-1b");
    dbStack.setCloudPlatform("AWS");
    dbStack.setPlatformVariant("GovCloud");
    dbStack.setEnvironmentId(ENVIRONMENT_CRN);
    dbStack.setOwnerCrn(Crn.safeFromString("crn:cdp:iam:us-west-1:cloudera:user:bob@cloudera.com"));
    credential = new Credential("userId", null, "userCrn", "account");
    cloudCredential = new CloudCredential("userId", "userName", "account");
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.redbeams.dto.Credential) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with DBStack

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

the class AllocateDatabaseServerV4RequestToDBStackConverter method convert.

public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) {
    Crn ownerCrn = Crn.safeFromString(ownerCrnString);
    CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString);
    DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn());
    DBStack dbStack = new DBStack();
    dbStack.setOwnerCrn(ownerCrn);
    dbStack.setUserName(user.getEmail());
    CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform());
    dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName()));
    dbStack.setEnvironmentId(source.getEnvironmentCrn());
    setRegion(dbStack, environment);
    if (source.getDatabaseServer() != null) {
        dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, ownerCrn, environment.getSecurityAccess()));
    }
    Map<String, Object> asMap = providerParameterCalculator.get(source).asMap();
    if (asMap != null) {
        Map<String, String> parameter = new HashMap<>();
        asMap.forEach((key, value) -> parameter.put(key, value.toString()));
        dbStack.setParameters(parameter);
    }
    dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack));
    Instant now = clock.getCurrentInstant();
    dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli()));
    dbStack.setResourceCrn(crnService.createCrn(dbStack).toString());
    dbStack.setTags(getTags(dbStack, source, environment));
    dbStack.setSslConfig(getSslConfig(source, dbStack));
    return dbStack;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) HashMap(java.util.HashMap) Instant(java.time.Instant) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 30 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<UpdateDatabaseServerRegistrationRequest> handlerEvent) {
    Event<UpdateDatabaseServerRegistrationRequest> event = handlerEvent.getEvent();
    LOGGER.debug("Received event: {}", event);
    UpdateDatabaseServerRegistrationRequest request = event.getData();
    DBStack dbStack = dbStackService.getById(request.getResourceId());
    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