Search in sources :

Example 1 with Configuration

use of com.hubspot.singularity.runner.base.configuration.Configuration in project Singularity by HubSpot.

the class SingularityRunnerBaseLogging method printProperties.

public void printProperties() {
    for (BaseRunnerConfiguration configuration : configurations) {
        try {
            final Configuration annotation = configuration.getClass().getAnnotation(Configuration.class);
            final String filename = consolidatedConfigFilename.or(annotation == null ? "(unknown)" : annotation.filename());
            LOG.trace(String.format("Loaded %s from %s:%n%s", configuration.getClass().getSimpleName(), filename, yamlMapper.writeValueAsString(configuration)));
        } catch (Exception e) {
            LOG.warn(String.format("Exception while attempting to print %s!", configuration.getClass().getName()), e);
        }
    }
}
Also used : BaseRunnerConfiguration(com.hubspot.singularity.runner.base.configuration.BaseRunnerConfiguration) BaseRunnerConfiguration(com.hubspot.singularity.runner.base.configuration.BaseRunnerConfiguration) SingularityRunnerBaseConfiguration(com.hubspot.singularity.runner.base.configuration.SingularityRunnerBaseConfiguration) Configuration(com.hubspot.singularity.runner.base.configuration.Configuration)

Example 2 with Configuration

use of com.hubspot.singularity.runner.base.configuration.Configuration 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

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