Search in sources :

Example 1 with CommonsConfiguration

use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.

the class MapReduceIndexJobs method getIndexJobConf.

private static ModifiableConfiguration getIndexJobConf(String indexName, String relationType) {
    ModifiableConfiguration mc = new ModifiableConfiguration(GraphDatabaseConfiguration.JOB_NS, new CommonsConfiguration(new BaseConfiguration()), BasicConfiguration.Restriction.NONE);
    mc.set(com.thinkaurelius.titan.graphdb.olap.job.IndexUpdateJob.INDEX_NAME, indexName);
    mc.set(com.thinkaurelius.titan.graphdb.olap.job.IndexUpdateJob.INDEX_RELATION_TYPE, relationType);
    mc.set(GraphDatabaseConfiguration.JOB_START_TIME, System.currentTimeMillis());
    return mc;
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfiguration(com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration) ModifiableConfiguration(com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration)

Example 2 with CommonsConfiguration

use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.

the class ElasticSearchConfigTest method testIndexCreationOptions.

@Test
public void testIndexCreationOptions() throws InterruptedException, BackendException {
    final int shards = 77;
    ElasticsearchRunner esr = new ElasticsearchRunner(".", "indexCreationOptions.yml");
    esr.start();
    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "indexCreationOptions");
    ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);
    ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
    settingsBuilder.put("discovery.zen.ping.multicast.enabled", "false");
    settingsBuilder.put("discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
    settingsBuilder.put("cluster.name", "indexCreationOptions");
    NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
    nodeBuilder.client(true).data(false).local(false);
    Node n = nodeBuilder.build().start();
    GetSettingsResponse response = n.client().admin().indices().getSettings(new GetSettingsRequest().indices("titan")).actionGet();
    assertEquals(String.valueOf(shards), response.getSetting("titan", "index.number_of_shards"));
    idx.close();
    n.stop();
    esr.stop();
}
Also used : Configuration(com.thinkaurelius.titan.diskstorage.configuration.Configuration) CommonsConfiguration(com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration) BasicConfiguration(com.thinkaurelius.titan.diskstorage.configuration.BasicConfiguration) GraphDatabaseConfiguration(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) ModifiableConfiguration(com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) Node(org.elasticsearch.node.Node) CommonsConfiguration(com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration) ModifiableConfiguration(com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration) NodeBuilder(org.elasticsearch.node.NodeBuilder) ImmutableSettings(org.elasticsearch.common.settings.ImmutableSettings) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) ElasticSearchIndex(com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Example 3 with CommonsConfiguration

use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.

the class AbstractTitanGraphProvider method clear.

//    @Override
//    public <ID> ID reconstituteGraphSONIdentifier(final Class<? extends Element> clazz, final Object id) {
//        if (Edge.class.isAssignableFrom(clazz)) {
//            // TitanGraphSONModule toStrings the edgeid - expect a String value for the id
//            if (!(id instanceof String)) throw new RuntimeException("Expected a String value for the RelationIdentifier");
//            return (ID) RelationIdentifier.parse((String) id);
//        } else {
//            return (ID) id;
//        }
//    }
@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
    if (null != g) {
        while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
        TitanGraph graph = (TitanGraph) g;
        if (graph.isOpen()) {
            if (g.tx().isOpen())
                g.tx().rollback();
            g.close();
        }
    }
    WriteConfiguration config = new CommonsConfiguration(configuration);
    BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
    if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
        TitanGraphBaseTest.clearGraph(config);
    }
}
Also used : StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) TitanGraph(com.thinkaurelius.titan.core.TitanGraph) Graph(org.apache.tinkerpop.gremlin.structure.Graph) StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) TitanGraph(com.thinkaurelius.titan.core.TitanGraph) WrappedGraph(org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph) CommonsConfiguration(com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration) WriteConfiguration(com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration) BasicConfiguration(com.thinkaurelius.titan.diskstorage.configuration.BasicConfiguration) WrappedGraph(org.apache.tinkerpop.gremlin.structure.util.wrapped.WrappedGraph)

Example 4 with CommonsConfiguration

use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.

the class CommonConfigTest method testDateParsing.

@Test
public void testDateParsing() {
    BaseConfiguration base = new BaseConfiguration();
    CommonsConfiguration config = new CommonsConfiguration(base);
    for (ChronoUnit unit : Arrays.asList(ChronoUnit.NANOS, ChronoUnit.MICROS, ChronoUnit.MILLIS, ChronoUnit.SECONDS, ChronoUnit.MINUTES, ChronoUnit.HOURS, ChronoUnit.DAYS)) {
        base.setProperty("test", "100 " + unit.toString());
        Duration d = config.get("test", Duration.class);
        assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(unit)), d.toNanos());
    }
    Map<ChronoUnit, String> mapping = ImmutableMap.of(ChronoUnit.MICROS, "us", ChronoUnit.DAYS, "d");
    for (Map.Entry<ChronoUnit, String> entry : mapping.entrySet()) {
        base.setProperty("test", "100 " + entry.getValue());
        Duration d = config.get("test", Duration.class);
        assertEquals(TimeUnit.NANOSECONDS.convert(100, Temporals.timeUnit(entry.getKey())), d.toNanos());
    }
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfiguration(com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration) Duration(java.time.Duration) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ChronoUnit(java.time.temporal.ChronoUnit) Test(org.junit.Test)

Example 5 with CommonsConfiguration

use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.

the class ConfigurationTest method testConfigHierarchy.

@Test
public void testConfigHierarchy() {
    ConfigNamespace root = new ConfigNamespace(null, "config", "root");
    ConfigNamespace indexes = new ConfigNamespace(root, "indexes", "Index definitions", true);
    ConfigNamespace storage = new ConfigNamespace(root, "storage", "Storage definitions");
    ConfigNamespace special = new ConfigNamespace(storage, "special", "Special storage definitions");
    ConfigOption<String[]> hostnames = new ConfigOption<String[]>(storage, "hostname", "Storage backend hostname", ConfigOption.Type.LOCAL, String[].class);
    ConfigOption<Boolean> partition = new ConfigOption<Boolean>(storage, "partition", "whether to enable partition", ConfigOption.Type.MASKABLE, false);
    ConfigOption<Long> locktime = new ConfigOption<Long>(storage, "locktime", "how long to lock", ConfigOption.Type.FIXED, 500l);
    ConfigOption<Byte> bits = new ConfigOption<Byte>(storage, "bits", "number of unique bits", ConfigOption.Type.GLOBAL_OFFLINE, (byte) 8);
    ConfigOption<Short> retry = new ConfigOption<Short>(special, "retry", "retry wait time", ConfigOption.Type.GLOBAL, (short) 200);
    ConfigOption<Double> bar = new ConfigOption<Double>(special, "bar", "bar", ConfigOption.Type.GLOBAL, 1.5d);
    ConfigOption<Integer> bim = new ConfigOption<Integer>(special, "bim", "bim", ConfigOption.Type.MASKABLE, Integer.class);
    ConfigOption<String> indexback = new ConfigOption<String>(indexes, "name", "index name", ConfigOption.Type.MASKABLE, String.class);
    ConfigOption<Integer> ping = new ConfigOption<Integer>(indexes, "ping", "ping time", ConfigOption.Type.LOCAL, 100);
    ConfigOption<Boolean> presort = new ConfigOption<Boolean>(indexes, "presort", "presort result set", ConfigOption.Type.LOCAL, false);
    //Local configuration
    ModifiableConfiguration config = new ModifiableConfiguration(root, new CommonsConfiguration(new BaseConfiguration()), BasicConfiguration.Restriction.LOCAL);
    UserModifiableConfiguration userconfig = new UserModifiableConfiguration(config);
    assertFalse(config.get(partition));
    assertEquals("false", userconfig.get("storage.partition"));
    userconfig.set("storage.partition", true);
    assertEquals("true", userconfig.get("storage.partition"));
    userconfig.set("storage.hostname", new String[] { "localhost", "some.where.org" });
    assertEquals("[localhost,some.where.org]", userconfig.get("storage.hostname"));
    userconfig.set("storage.hostname", "localhost");
    assertEquals("[localhost]", userconfig.get("storage.hostname"));
    assertEquals("null", userconfig.get("storage.special.bim"));
    assertEquals("", userconfig.get("indexes"));
    userconfig.set("indexes.search.name", "foo");
    assertEquals("+ search", userconfig.get("indexes").trim());
    assertEquals("foo", userconfig.get("indexes.search.name"));
    assertEquals("100", userconfig.get("indexes.search.ping"));
    userconfig.set("indexes.search.ping", 400l);
    assertEquals("400", userconfig.get("indexes.search.ping"));
    assertFalse(config.isFrozen());
    try {
        userconfig.set("storage.locktime", 500);
        fail();
    } catch (IllegalArgumentException e) {
    }
    try {
        config.set(retry, (short) 100);
        fail();
    } catch (IllegalArgumentException e) {
    }
    //        System.out.println(userconfig.get("storage"));
    userconfig.close();
    ReadConfiguration localConfig = userconfig.getConfiguration();
    config = new ModifiableConfiguration(root, new CommonsConfiguration(new BaseConfiguration()), BasicConfiguration.Restriction.GLOBAL);
    userconfig = new UserModifiableConfiguration(config);
    userconfig.set("storage.locktime", 1111);
    userconfig.set("storage.bits", 5);
    userconfig.set("storage.special.retry", 222);
    assertEquals("5", userconfig.get("storage.bits"));
    assertEquals("222", userconfig.get("storage.special.retry"));
    config.freezeConfiguration();
    userconfig.set("storage.special.retry", 333);
    assertEquals("333", userconfig.get("storage.special.retry"));
    try {
        userconfig.set("storage.bits", 6);
    } catch (IllegalArgumentException e) {
    }
    userconfig.set("storage.bits", 6);
    try {
        userconfig.set("storage.locktime", 1221);
    } catch (IllegalArgumentException e) {
    }
    try {
        userconfig.set("storage.locktime", 1221);
    } catch (IllegalArgumentException e) {
    }
    userconfig.set("indexes.find.name", "lulu");
    userconfig.close();
    ReadConfiguration globalConfig = userconfig.getConfiguration();
    MixedConfiguration mixed = new MixedConfiguration(root, globalConfig, localConfig);
    assertEquals(ImmutableSet.of("search", "find"), mixed.getContainedNamespaces(indexes));
    Configuration search = mixed.restrictTo("search");
    assertEquals("foo", search.get(indexback));
    assertEquals(400, search.get(ping).intValue());
    assertEquals(100, mixed.get(ping, "find").intValue());
    assertEquals(false, mixed.get(presort, "find").booleanValue());
    assertEquals(400, mixed.get(ping, "search").intValue());
    assertEquals(false, mixed.get(presort, "search").booleanValue());
    assertFalse(mixed.has(bim));
    assertTrue(mixed.has(bits));
    assertEquals(5, mixed.getSubset(storage).size());
    assertEquals(1.5d, mixed.get(bar).doubleValue(), 0.0);
    assertEquals("localhost", mixed.get(hostnames)[0]);
    assertEquals(1111, mixed.get(locktime).longValue());
    mixed.close();
//System.out.println(ConfigElement.toString(root));
}
Also used : GraphDatabaseConfiguration(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration) CommonsConfiguration(com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CommonsConfiguration(com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Test(org.junit.Test)

Aggregations

CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)11 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)8 Test (org.junit.Test)6 BasicConfiguration (com.thinkaurelius.titan.diskstorage.configuration.BasicConfiguration)5 ModifiableConfiguration (com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration)5 GraphDatabaseConfiguration (com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration)5 Configuration (com.thinkaurelius.titan.diskstorage.configuration.Configuration)4 ElasticSearchIndex (com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex)4 File (java.io.File)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)1 ConfigElement (com.thinkaurelius.titan.diskstorage.configuration.ConfigElement)1 WriteConfiguration (com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration)1 StandardTitanGraph (com.thinkaurelius.titan.graphdb.database.StandardTitanGraph)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 ChronoUnit (java.time.temporal.ChronoUnit)1