Search in sources :

Example 11 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration 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 = new PropertiesConfiguration(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.checkState(null != pid);
            Preconditions.checkState(null != 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) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 12 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class RestClientSetupTest method baseConfigTest.

private ElasticSearchClient baseConfigTest(Map<String, String> extraConfigValues) throws Exception {
    final CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".backend", "elasticsearch");
    cc.set("index." + INDEX_NAME + ".elasticsearch.interface", "REST_CLIENT");
    for (Map.Entry<String, String> me : extraConfigValues.entrySet()) {
        cc.set(me.getKey(), me.getValue());
    }
    final ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
    doReturn(restClientBuilderMock).when(restClientSetup).getRestClientBuilder(any());
    doReturn(restElasticSearchClientMock).when(restClientSetup).getElasticSearchClient(any(RestClient.class), anyInt());
    return restClientSetup.connect(config.restrictTo(INDEX_NAME));
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) RestClient(org.elasticsearch.client.RestClient) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 13 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class ElasticSearchIndexTest method getESTestConfig.

public Configuration getESTestConfig() {
    final String index = "es";
    final CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    if (esr.getEsMajorVersion().value > 2) {
        cc.set("index." + index + ".elasticsearch.ingest-pipeline.ingestvertex", "pipeline_1");
    }
    return esr.setElasticsearchConfiguration(new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE), index).set(GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE, 3, index).restrictTo(index);
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration)

Example 14 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class LocalStoreManagerTest method getStoreManager.

public LocalStoreManager getStoreManager(Map<ConfigOption, String> map) throws BackendException {
    final ModifiableConfiguration mc = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(new BaseConfiguration()), NONE);
    map.forEach(mc::set);
    return new LocalStoreManagerSampleImplementation(mc);
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration)

Example 15 with CommonsConfiguration

use of org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationInstanceIdTest method graphShouldNotOpenWithSameInstanceId.

@Test
public void graphShouldNotOpenWithSameInstanceId() {
    final Map<String, Object> map = new HashMap<String, Object>();
    map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory");
    map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), "not-unique");
    final MapConfiguration config = new MapConfiguration(map);
    final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    assertEquals(graph1.openManagement().getOpenInstances().size(), 1);
    assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique");
    thrown.expect(JanusGraphException.class);
    final String err = "A JanusGraph graph with the same instance id [not-unique] is already open. Might required forced shutdown.";
    thrown.expectMessage(equalTo(err));
    final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config)));
    graph1.close();
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Aggregations

CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)20 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)10 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)9 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)9 Test (org.junit.Test)9 MapConfiguration (org.apache.commons.configuration.MapConfiguration)8 HashMap (java.util.HashMap)7 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)6 ImmutableMap (com.google.common.collect.ImmutableMap)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)2 ManagementSystem (org.janusgraph.graphdb.database.management.ManagementSystem)2 ConfigurationManagementGraph (org.janusgraph.graphdb.management.ConfigurationManagementGraph)2 JanusGraphManager (org.janusgraph.graphdb.management.JanusGraphManager)2 FileInputStream (java.io.FileInputStream)1 Duration (java.time.Duration)1