Search in sources :

Example 1 with SubnodeConfiguration

use of org.apache.commons.configuration.SubnodeConfiguration in project ovirt-engine by oVirt.

the class EngineConfigLogic method populateAlternateKeyMap.

private void populateAlternateKeyMap(HierarchicalConfiguration config) {
    List<SubnodeConfiguration> configurationsAt = config.configurationsAt("/*/" + ALTERNATE_KEY);
    alternateKeysMap = new HashMap<>(configurationsAt.size());
    for (SubnodeConfiguration node : configurationsAt) {
        String rootKey = node.getRootNode().getParentNode().getName();
        String[] alternateKeys = config.getStringArray("/" + rootKey + "/" + ALTERNATE_KEY);
        for (String token : alternateKeys) {
            alternateKeysMap.put(token, rootKey);
        }
    }
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration)

Example 2 with SubnodeConfiguration

use of org.apache.commons.configuration.SubnodeConfiguration in project blueprints by tinkerpop.

the class Neo4j2GraphConfiguration method configureGraphInstance.

public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException {
    final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION);
    if (graphFile == null || graphFile.length() == 0) {
        throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION);
    }
    final boolean highAvailabilityMode = context.getProperties().getBoolean(Tokens.REXSTER_GRAPH_HA, false);
    // get the <properties> section of the xml configuration
    final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties();
    SubnodeConfiguration neo4jSpecificConfiguration;
    try {
        neo4jSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES);
    } catch (IllegalArgumentException iae) {
        throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES);
    }
    try {
        // properties to initialize the neo4j instance.
        final HashMap<String, String> neo4jProperties = new HashMap<String, String>();
        // read the properties from the xml file and convert them to properties
        // to be injected into neo4j.
        final Iterator<String> neo4jSpecificConfigurationKeys = neo4jSpecificConfiguration.getKeys();
        while (neo4jSpecificConfigurationKeys.hasNext()) {
            String key = neo4jSpecificConfigurationKeys.next();
            // replace the ".." put in play by apache commons configuration.  that's expected behavior
            // due to parsing key names to xml.
            neo4jProperties.put(key.replace("..", "."), neo4jSpecificConfiguration.getString(key));
        }
        if (highAvailabilityMode) {
            if (!neo4jProperties.containsKey("ha.machine_id")) {
                throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.machine_id] in the <properties> of the configuration");
            }
            if (!neo4jProperties.containsKey("ha.server")) {
                throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.server] <properties> of the configuration");
            }
            if (!neo4jProperties.containsKey("ha.initial_hosts")) {
                throw new GraphConfigurationException("Check graph configuration. Neo4j HA requires [ha.initial_hosts] <properties> of the configuration");
            }
            return new Neo4j2HaGraph(graphFile, neo4jProperties);
        } else {
            return new Neo4j2Graph(graphFile, neo4jProperties);
        }
    } catch (GraphConfigurationException gce) {
        throw gce;
    } catch (Exception ex) {
        throw new GraphConfigurationException(ex);
    }
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration) HashMap(java.util.HashMap) GraphConfigurationException(com.tinkerpop.rexster.config.GraphConfigurationException) Neo4j2HaGraph(com.tinkerpop.blueprints.impls.neo4j2.Neo4j2HaGraph) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) GraphConfigurationException(com.tinkerpop.rexster.config.GraphConfigurationException) Neo4j2Graph(com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph)

Example 3 with SubnodeConfiguration

use of org.apache.commons.configuration.SubnodeConfiguration in project ovirt-engine by oVirt.

the class ConfigKeyFactory method generateByPropertiesKey.

public ConfigKey generateByPropertiesKey(String key) {
    SubnodeConfiguration configurationAt = null;
    try {
        if (Character.isLetter(key.charAt(0))) {
            configurationAt = keysConfig.configurationAt(key);
        }
    } catch (IllegalArgumentException e) {
    // Can't find a key. maybe its an alternate key.
    }
    if (configurationAt == null || configurationAt.isEmpty()) {
        key = alternateKeysMap.get(key);
        configurationAt = keysConfig.configurationAt(key);
    }
    String type = configurationAt.getString("type");
    if (StringUtils.isBlank(type)) {
        type = "String";
    }
    String[] validValues = configurationAt.getStringArray("validValues");
    // Description containing the list delimiter *will* be broken into an array, so rejoin it using that delimiter.
    // We pad the separator because the strings in the array are trimmed automatically.
    String description = StringUtils.join(configurationAt.getStringArray("description"), configurationAt.getListDelimiter() + " ");
    String alternateKey = keysConfig.getString("/" + key + "/" + "alternateKey");
    // If the isReloadable attribute isn't specified - assume it is false
    boolean reloadable = configurationAt.getBoolean("isReloadable", false);
    ConfigKey configKey = new ConfigKey(type, description, alternateKey, key, "", validValues, "", getHelperByType(type), reloadable, isDeprecated(key));
    configKey.setParser(parser);
    return configKey;
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration)

Example 4 with SubnodeConfiguration

use of org.apache.commons.configuration.SubnodeConfiguration in project OA4MP by ncsa.

the class ServiceConfigTest method testConfig.

@Test
public void testConfig() throws Exception {
    XMLConfiguration c = getConfiguration();
    Iterator iterator = c.getKeys();
    say("echoing configuration to console:");
    ConfigurationNode root = c.getRootNode();
    say("name of root = " + root.getName());
    say("child count = " + root.getChildren().size());
    while (iterator.hasNext()) {
        String key = iterator.next().toString();
        say("(k, v)=(" + key + ", " + c.getString(key) + ")");
    }
    SubnodeConfiguration mailC = c.configurationAt("service.mail");
    say("mail configured? " + mailC.getString("[@enabled]"));
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode) Iterator(java.util.Iterator) ConfigTest(edu.uiuc.ncsa.security.core.configuration.ConfigTest) Test(org.junit.Test)

Example 5 with SubnodeConfiguration

use of org.apache.commons.configuration.SubnodeConfiguration in project orientdb by orientechnologies.

the class OrientGraphConfiguration method configureGraphInstance.

public Graph configureGraphInstance(final GraphConfigurationContext context) throws GraphConfigurationException {
    final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION);
    if (graphFile == null || graphFile.length() == 0) {
        throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION);
    }
    // get the <properties> section of the xml configuration
    final HierarchicalConfiguration graphSectionConfig = (HierarchicalConfiguration) context.getProperties();
    SubnodeConfiguration orientDbSpecificConfiguration;
    try {
        orientDbSpecificConfiguration = graphSectionConfig.configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES);
    } catch (IllegalArgumentException iae) {
        throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES, iae);
    }
    try {
        final String username = orientDbSpecificConfiguration.getString("username", "");
        final String password = orientDbSpecificConfiguration.getString("password", "");
        // implementation of shutdown will call the orientdb close method.
        return OrientGraphFactory.getTxGraphImplFactory().getGraph(graphFile, username, password);
    } catch (Exception ex) {
        throw new GraphConfigurationException(ex);
    }
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration) GraphConfigurationException(com.tinkerpop.rexster.config.GraphConfigurationException) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) GraphConfigurationException(com.tinkerpop.rexster.config.GraphConfigurationException)

Aggregations

SubnodeConfiguration (org.apache.commons.configuration.SubnodeConfiguration)5 GraphConfigurationException (com.tinkerpop.rexster.config.GraphConfigurationException)2 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)2 Neo4j2Graph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2Graph)1 Neo4j2HaGraph (com.tinkerpop.blueprints.impls.neo4j2.Neo4j2HaGraph)1 ConfigTest (edu.uiuc.ncsa.security.core.configuration.ConfigTest)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)1 ConfigurationNode (org.apache.commons.configuration.tree.ConfigurationNode)1 Test (org.junit.Test)1