Search in sources :

Example 1 with DatabaseServerV4Response

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();
}
Also used : AttemptResult(com.dyngr.core.AttemptResult) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) NotFoundException(javax.ws.rs.NotFoundException)

Example 2 with DatabaseServerV4Response

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);
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) BadRequestException(javax.ws.rs.BadRequestException)

Example 3 with DatabaseServerV4Response

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());
    }
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) NotFoundException(javax.ws.rs.NotFoundException)

Example 4 with DatabaseServerV4Response

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);
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 5 with 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();
}
Also used : DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) HashMap(java.util.HashMap) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig)

Aggregations

DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)54 Test (org.junit.jupiter.api.Test)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)16 SslConfigV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response)13 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)9 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)7 Test (org.junit.Test)6 StackDatabaseServerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.StackDatabaseServerResponse)5 AllocateDatabaseServerV4Request (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request)5 DatabaseServerSslConfig (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.database.DatabaseServerSslConfig)4 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)4 DatabaseServerStatusV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerStatusV4Response)4 SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)4 Date (java.util.Date)4 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)3 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)3 NotFoundException (javax.ws.rs.NotFoundException)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3