Search in sources :

Example 1 with DatabaseVendor

use of com.sequenceiq.cloudbreak.api.model.DatabaseVendor in project cloudbreak by hortonworks.

the class RDSConfigRequestToRDSConfigConverter method convert.

@Override
public RDSConfig convert(RDSConfigRequest source) {
    RDSConfig rdsConfig = new RDSConfig();
    if (Strings.isNullOrEmpty(source.getName())) {
        rdsConfig.setName(missingResourceNameGenerator.generateName(APIResourceType.RDS_CONFIG));
    } else {
        rdsConfig.setName(source.getName());
    }
    rdsConfig.setConnectionURL(source.getConnectionURL());
    Optional<DatabaseVendor> databaseVendor = DatabaseVendor.getVendorByJdbcUrl(source.getConnectionURL());
    if (databaseVendor.isPresent()) {
        rdsConfig.setDatabaseEngine(databaseVendor.get().name());
        rdsConfig.setConnectionDriver(databaseVendor.get().connectionDriver());
    } else {
        throw new BadRequestException("Not a valid DatabaseVendor which was provided in the jdbc url.");
    }
    rdsConfig.setConnectionUserName(source.getConnectionUserName());
    rdsConfig.setConnectionPassword(source.getConnectionPassword());
    rdsConfig.setCreationDate(new Date().getTime());
    rdsConfig.setStatus(ResourceStatus.USER_MANAGED);
    rdsConfig.setType(source.getType());
    return rdsConfig;
}
Also used : DatabaseVendor(com.sequenceiq.cloudbreak.api.model.DatabaseVendor) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Date(java.util.Date)

Aggregations

DatabaseVendor (com.sequenceiq.cloudbreak.api.model.DatabaseVendor)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)1 Date (java.util.Date)1