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;
}
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();
}
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);
}
}
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());
}
}
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));
}
Aggregations