Search in sources :

Example 21 with DBStack

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

the class DatabaseServerConfigService method release.

public DatabaseServerConfig release(String resourceCrn) {
    try {
        return transactionService.required(() -> {
            DatabaseServerConfig resource = getByCrn(resourceCrn);
            if (!resource.getResourceStatus().isReleasable()) {
                throw new ConflictException(String.format("Database server configuration has unreleasable resource " + "status %s: releasable statuses are %s", resource.getResourceStatus(), ResourceStatus.getReleasableValues()));
            }
            Optional<DBStack> dbStack = resource.getDbStack();
            if (dbStack.isPresent()) {
                dbStackService.delete(dbStack.get());
                resource.setDbStack(null);
            } else {
                LOGGER.info("Database stack missing for crn: '{}', continuing anyway", resourceCrn);
            }
            resource.setResourceStatus(ResourceStatus.USER_MANAGED);
            return repository.save(resource);
        });
    } catch (TransactionService.TransactionExecutionException e) {
        throw e.getCause() != null ? e.getCause() : new RedbeamsException("Failed to release management of " + resourceCrn);
    }
}
Also used : TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) ConflictException(com.sequenceiq.redbeams.exception.ConflictException) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) RedbeamsException(com.sequenceiq.redbeams.exception.RedbeamsException)

Example 22 with DBStack

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

the class RedbeamsCreationService method saveDbStackAndRegisterDatabaseServerConfig.

private DBStack saveDbStackAndRegisterDatabaseServerConfig(DBStack dbStack, String clusterCrn) {
    DBStack savedStack = saveDbStack(dbStack);
    registerDatabaseServerConfig(savedStack, clusterCrn);
    return savedStack;
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack)

Example 23 with DBStack

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

the class RedbeamsCreationService method saveDbStackInDatabaseServerConfig.

private DBStack saveDbStackInDatabaseServerConfig(DatabaseServerConfig databaseServerConfig, DBStack dbStack) {
    DBStack savedDbStack = saveDbStack(dbStack);
    databaseServerConfig.setDbStack(savedDbStack);
    databaseServerConfigService.update(databaseServerConfig);
    return savedDbStack;
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack)

Example 24 with DBStack

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

the class RedbeamsCreationService method launchDatabaseServer.

public DBStack launchDatabaseServer(DBStack dbStack, String clusterCrn) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Create called with: {}", dbStack);
    }
    if (dbStackService.findByNameAndEnvironmentCrn(dbStack.getName(), dbStack.getEnvironmentId()).isPresent()) {
        throw new BadRequestException("A stack for this database server already exists in the environment");
    }
    Optional<DatabaseServerConfig> optionalDBServerConfig = databaseServerConfigService.findByEnvironmentCrnAndClusterCrn(dbStack.getEnvironmentId(), clusterCrn);
    DBStack savedDbStack;
    boolean startFlow = false;
    if (optionalDBServerConfig.isEmpty()) {
        LOGGER.debug("DataBaseServerConfig is not available by cluster crn '{}'", clusterCrn);
        savedDbStack = saveDbStackAndRegisterDatabaseServerConfig(dbStack, clusterCrn);
        startFlow = true;
    } else {
        DatabaseServerConfig dbServerConfig = optionalDBServerConfig.get();
        if (dbServerConfig.getDbStack().isEmpty()) {
            LOGGER.debug("DBStack is not available in DatabaseServerConfig '{}'", dbServerConfig.getResourceCrn());
            savedDbStack = saveDbStackInDatabaseServerConfig(dbServerConfig, dbStack);
            startFlow = true;
        } else {
            savedDbStack = dbServerConfig.getDbStack().get();
        }
    }
    if (startFlow) {
        flowManager.notify(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector(), new RedbeamsEvent(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector(), savedDbStack.getId()));
    }
    return savedDbStack;
}
Also used : DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

Example 25 with DBStack

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

the class RedbeamsStartService method startDatabaseServer.

public void startDatabaseServer(String crn) {
    DBStack dbStack = dbStackService.getByCrn(crn);
    MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Start called for: {}", dbStack);
    }
    if (dbStack.getStatus().isStartInProgressOrCompleted()) {
        LOGGER.debug("DatabaseServer with crn {} is already being started", dbStack.getResourceCrn());
        return;
    }
    dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.START_REQUESTED);
    flowManager.notify(RedbeamsStartEvent.REDBEAMS_START_EVENT.selector(), new RedbeamsEvent(RedbeamsStartEvent.REDBEAMS_START_EVENT.selector(), dbStack.getId()));
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

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