Search in sources :

Example 1 with ConfigurationValidationException

use of io.dropwizard.configuration.ConfigurationValidationException in project Singularity by HubSpot.

the class SingularityRunnerConfigurationProvider method get.

@Override
public T get() {
    final Configuration configuration = clazz.getAnnotation(Configuration.class);
    try {
        final File baseFile = new File(configuration.filename());
        final T baseConfig = baseFile.exists() ? objectMapper.readValue(baseFile, clazz) : clazz.newInstance();
        final JsonNode overrideNode = filename.isPresent() ? loadYamlField(filename.get(), configuration.consolidatedField()) : objectMapper.createObjectNode();
        final T config = objectMapper.readerForUpdating(baseConfig).readValue(overrideNode);
        final Set<ConstraintViolation<T>> violations = validator.validate(config);
        if (!violations.isEmpty()) {
            throw new ConfigurationValidationException(filename.or(configuration.filename()), violations);
        }
        return config;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : ConfigurationValidationException(io.dropwizard.configuration.ConfigurationValidationException) BaseRunnerConfiguration(com.hubspot.singularity.runner.base.configuration.BaseRunnerConfiguration) Configuration(com.hubspot.singularity.runner.base.configuration.Configuration) ConstraintViolation(javax.validation.ConstraintViolation) JsonNode(com.fasterxml.jackson.databind.JsonNode) File(java.io.File) ConfigurationValidationException(io.dropwizard.configuration.ConfigurationValidationException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 BaseRunnerConfiguration (com.hubspot.singularity.runner.base.configuration.BaseRunnerConfiguration)1 Configuration (com.hubspot.singularity.runner.base.configuration.Configuration)1 ConfigurationValidationException (io.dropwizard.configuration.ConfigurationValidationException)1 File (java.io.File)1 ConstraintViolation (javax.validation.ConstraintViolation)1