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);
}
}
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;
}
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;
}
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;
}
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()));
}
Aggregations