use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseObtainerService method obtainAttemptResult.
AttemptResult<Object> obtainAttemptResult(Cluster cluster, DatabaseOperation databaseOperation, String databaseCrn, boolean cancellable) throws JsonProcessingException {
Optional<AttemptResult<Object>> result = Optional.ofNullable(clusterPollingCheckerService.checkClusterCancelledState(cluster, cancellable));
if (result.isEmpty()) {
checkArgument(cluster != null, "Cluster must not be null");
try {
LOGGER.info("Polling redbeams for database status: '{}'", cluster.getName());
DatabaseServerV4Response rdsStatus = redbeamsClient.getByCrn(databaseCrn);
LOGGER.info("Response from redbeams: {}", JsonUtil.writeValueAsString(rdsStatus));
result = Optional.of(databaseCriteriaResolver.resolveResultByCriteria(databaseOperation, rdsStatus, cluster));
} catch (CloudbreakServiceException e) {
if (e.getCause() instanceof NotFoundException) {
LOGGER.info("Not found returned for database crn: {}", databaseCrn);
result = Optional.of(AttemptResults.finishWith(null));
} else {
throw e;
}
} catch (NotFoundException e) {
LOGGER.info("Not found returned for database crn: {}", databaseCrn);
result = Optional.of(AttemptResults.finishWith(null));
}
}
return result.get();
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class ExternalDatabaseService method provisionDatabase.
public void provisionDatabase(Cluster cluster, DatabaseAvailabilityType externalDatabase, DetailedEnvironmentResponse environment) {
LOGGER.info("Create external {} database server in environment {} for DataHub {}", externalDatabase.name(), environment.getName(), cluster.getName());
String databaseCrn;
try {
Optional<DatabaseServerV4Response> existingDatabase = findExistingDatabase(cluster, environment.getCrn());
if (existingDatabase.isPresent()) {
String dbCrn = existingDatabase.get().getCrn();
LOGGER.debug("Found existing database with CRN {}", dbCrn);
databaseCrn = dbCrn;
} else {
LOGGER.debug("Requesting new database server creation");
AllocateDatabaseServerV4Request request = getDatabaseRequest(environment, externalDatabase, cluster);
databaseCrn = redbeamsClient.create(request).getResourceCrn();
}
updateClusterWithDatabaseServerCrn(cluster, databaseCrn);
} catch (BadRequestException badRequestException) {
LOGGER.error("Redbeams create request failed, bad request", badRequestException);
throw badRequestException;
}
waitAndGetDatabase(cluster, databaseCrn, DatabaseOperation.CREATION, true);
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class ExternalDatabaseService method terminateDatabase.
public void terminateDatabase(Cluster cluster, DatabaseAvailabilityType externalDatabase, DetailedEnvironmentResponse environment, boolean forced) {
LOGGER.info("Terminate external {} database server in environment {} for DataHub {}", externalDatabase.name(), environment.getName(), cluster.getName());
try {
if (externalDatabaseReferenceExist(cluster.getDatabaseServerCrn())) {
DatabaseServerV4Response response = redbeamsClient.deleteByCrn(cluster.getDatabaseServerCrn(), forced);
waitAndGetDatabase(cluster, response.getCrn(), DatabaseOperation.DELETION, false);
} else {
LOGGER.warn("[INVESTIGATE] The external database type was {} but there was no crn", externalDatabase);
}
} catch (NotFoundException notFoundException) {
LOGGER.info("Database server is deleted on redbeams side {}", cluster.getDatabaseServerCrn());
}
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseService method getDatabaseServer.
public StackDatabaseServerResponse getDatabaseServer(String clusterCrn) {
Stack stack = stackOperations.getStackByCrn(clusterCrn);
if (stack.getCluster() == null) {
throw notFound("Data Hub with crn:", clusterCrn).get();
}
if (stack.getCluster().getDatabaseServerCrn() == null) {
throw notFound("Database for Data Hub with Data Hub crn:", clusterCrn).get();
}
DatabaseServerV4Response databaseServerV4Response = databaseServerV4Endpoint.getByCrn(stack.getCluster().getDatabaseServerCrn());
return databaseServerConverter.convert(databaseServerV4Response);
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class AbstractRdsConfigProvider method createServicePillarConfigMapIfNeeded.
/**
* Creates a map of database information for this provider's database, suitable for inclusion
* in a salt pillar. The map usually contains only one key, that being the return value of
* {@link #getPillarKey()}. The configuration information is ultimately used to create the
* database.
*
* @param stack stack for cluster
* @param cluster cluster to associate database with
* @return salt pillar configuration information for this provider's database
*/
public Map<String, Object> createServicePillarConfigMapIfNeeded(Stack stack, Cluster cluster) {
if (isRdsConfigNeeded(cluster.getBlueprint(), cluster.hasGateway())) {
Set<RDSConfig> rdsConfigs = createPostgresRdsConfigIfNeeded(stack, cluster);
RDSConfig rdsConfig = rdsConfigs.stream().filter(rdsConfig1 -> rdsConfig1.getType().equalsIgnoreCase(getRdsType().name())).findFirst().get();
if (rdsConfig.getStatus() == ResourceStatus.DEFAULT && rdsConfig.getDatabaseEngine() != DatabaseVendor.EMBEDDED) {
Map<String, Object> postgres = new HashMap<>();
if (dbServerConfigurer.isRemoteDatabaseNeeded(cluster)) {
DatabaseServerV4Response dbServerResponse = dbServerConfigurer.getDatabaseServer(cluster.getDatabaseServerCrn());
postgres.put("remote_db_url", dbServerResponse.getHost());
postgres.put("remote_db_port", dbServerResponse.getPort());
postgres.put("remote_admin", secretService.getByResponse(dbServerResponse.getConnectionUserName()));
postgres.put("remote_admin_pw", secretService.getByResponse(dbServerResponse.getConnectionPassword()));
}
String dbName = getDb();
postgres.put("database", dbName);
postgres.put("user", dbUsernameConverterService.toDatabaseUsername(rdsConfig.getConnectionUserName()));
postgres.put("password", rdsConfig.getConnectionPassword());
LOGGER.debug("RDS config added to pillar for name: {} databaseEngine: {}", dbName, rdsConfig.getDatabaseEngine());
return Collections.singletonMap(getPillarKey(), postgres);
}
}
return Collections.emptyMap();
}
Aggregations