Search in sources :

Example 1 with ConfigElement

use of org.janusgraph.diskstorage.configuration.ConfigElement in project janusgraph by JanusGraph.

the class ConfigurationPrinter method getSortedChildren.

@SuppressWarnings("unchecked")
private <E> List<E> getSortedChildren(ConfigNamespace n, Function<ConfigElement, Boolean> predicate) {
    final List<ConfigElement> sortedElements = new ArrayList<>();
    for (ConfigElement e : n.getChildren()) {
        if (predicate.apply(e)) {
            sortedElements.add(e);
        }
    }
    sortedElements.sort(Comparator.comparing(ConfigElement::getName));
    return (List<E>) sortedElements;
}
Also used : ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ConfigElement

use of org.janusgraph.diskstorage.configuration.ConfigElement in project janusgraph by JanusGraph.

the class ConfigurationLint method validate.

public static Status validate(String filename) throws IOException {
    try (final FileInputStream fis = new FileInputStream(filename)) {
        new Properties().load(fis);
    }
    final PropertiesConfiguration apc;
    try {
        apc = ConfigurationUtil.loadPropertiesConfig(filename);
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    // new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
    // , BasicConfiguration.Restriction.NONE);
    Iterator<String> iterator = apc.getKeys();
    int totalKeys = 0;
    int keysVerified = 0;
    while (iterator.hasNext()) {
        totalKeys++;
        String key = iterator.next();
        String value = apc.getString(key);
        try {
            ConfigElement.PathIdentifier pid = ConfigElement.parse(GraphDatabaseConfiguration.ROOT_NS, key);
            // ConfigElement shouldn't return null; failure here probably relates to janusgraph-core, not the file
            Preconditions.checkNotNull(pid);
            Preconditions.checkNotNull(pid.element);
            if (!pid.element.isOption()) {
                log.warn("Config key {} is a namespace (only options can be keys)", key);
                continue;
            }
            final ConfigOption<?> opt;
            try {
                opt = (ConfigOption<?>) pid.element;
            } catch (RuntimeException re) {
                // This shouldn't happen given the preceding check, but catch it anyway
                log.warn("Config key {} maps to the element {}, but it could not be cast to an option", key, pid.element, re);
                continue;
            }
            try {
                Object o = new CommonsConfiguration(apc).get(key, opt.getDatatype());
                opt.verify(o);
                keysVerified++;
            } catch (RuntimeException re) {
                log.warn("Config key {} is recognized, but its value {} could not be validated", key, value);
                log.debug("Validation exception on {}={} follows", key, value, re);
            }
        } catch (RuntimeException re) {
            log.warn("Unknown config key {}", key);
        }
    }
    return new Status(totalKeys, totalKeys - keysVerified);
}
Also used : ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) IOException(java.io.IOException) Properties(java.util.Properties) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) FileInputStream(java.io.FileInputStream) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Aggregations

ConfigElement (org.janusgraph.diskstorage.configuration.ConfigElement)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)1