Example usage for com.amazonaws.services.rds.model DescribeDBEngineVersionsResult getDBEngineVersions

List of usage examples for com.amazonaws.services.rds.model DescribeDBEngineVersionsResult getDBEngineVersions

Introduction

In this page you can find the example usage for com.amazonaws.services.rds.model DescribeDBEngineVersionsResult getDBEngineVersions.

Prototype


public java.util.List<DBEngineVersion> getDBEngineVersions() 

Source Link

Document

A list of DBEngineVersion elements.

Usage

From source file:com.cloudera.director.aws.rds.RDSInstanceTemplateConfigurationValidator.java

License:Apache License

/**
 * @param client              the RDS client
 * @param configuration       the configuration to be validated
 * @param accumulator         the exception condition accumulator
 * @param localizationContext the localization context
 *//*from w w w  .j a v  a 2 s  . c  o m*/
@VisibleForTesting
void checkEngine(AmazonRDSClient client, Configured configuration,
        PluginExceptionConditionAccumulator accumulator, LocalizationContext localizationContext) {

    // The preceeding validator has already been run, so we know this value is present.
    String type = configuration.getConfigurationValue(TYPE, localizationContext);

    DatabaseType databaseType;
    try {
        // TODO add validation at the superclass level prior to reaching this point.
        databaseType = DatabaseType.valueOf(type);
    } catch (IllegalArgumentException e) {
        addError(accumulator, TYPE, localizationContext, null, UNSUPPORTED_TYPE, type);
        return;
    }

    RDSInstanceTemplate.RDSInstanceTemplateConfigurationPropertyToken engineErrorToken = TYPE;
    String engine = configuration.getConfigurationValue(ENGINE, localizationContext);
    try {
        if (engine == null) {
            engine = RDSEngine.getDefaultEngine(databaseType).getEngineName();
        } else {
            engineErrorToken = ENGINE;
            Collection<String> engines = RDSEngine.getSupportedEngineNames(databaseType);
            if (!engines.contains(engine)) {
                addError(accumulator, engineErrorToken, localizationContext, null, RDSEngine.INVALID_ENGINE,
                        engine);
                return;
            }
        }
    } catch (IllegalArgumentException e) {
        addError(accumulator, engineErrorToken, localizationContext, null, e.getMessage());
        return;
    }

    DescribeDBEngineVersionsRequest request = new DescribeDBEngineVersionsRequest().withEngine(engine);

    DescribeDBEngineVersionsResult result;
    try {
        result = client.describeDBEngineVersions(request);
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals(INVALID_PARAMETER_VALUE)) {
            addError(accumulator, engineErrorToken, localizationContext, null, RDSEngine.INVALID_ENGINE,
                    engine);
            return;
        } else {
            throw Throwables.propagate(e);
        }
    }

    String engineVersion = configuration.getConfigurationValue(ENGINE_VERSION, localizationContext);
    if (engineVersion != null) {
        boolean foundVersion = false;
        for (DBEngineVersion dbEngineVersion : result.getDBEngineVersions()) {
            if (engineVersion.equals(dbEngineVersion.getEngineVersion())) {
                foundVersion = true;
                break;
            }
        }
        if (!foundVersion) {
            addError(accumulator, ENGINE_VERSION, localizationContext, null, INVALID_ENGINE_VERSION,
                    engineVersion);
        }
    }
}