use of com.thinkaurelius.titan.core.schema.TitanManagement in project incubator-atlas by apache.
the class Titan1Graph method getIndexKeys.
private Set<String> getIndexKeys(Class<? extends Element> titanElementClass) {
TitanManagement mgmt = getGraph().openManagement();
Iterable<TitanGraphIndex> indices = mgmt.getGraphIndexes(titanElementClass);
Set<String> result = new HashSet<String>();
for (TitanGraphIndex index : indices) {
result.add(index.name());
}
mgmt.commit();
return result;
}
use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.
the class TitanGraphBaseTest method clopen.
public void clopen(Object... settings) {
config = getConfiguration();
if (mgmt != null && mgmt.isOpen())
mgmt.rollback();
if (null != tx && tx.isOpen())
tx.commit();
if (settings != null && settings.length > 0) {
Map<TestConfigOption, Object> options = validateConfigOptions(settings);
TitanManagement gconf = null;
ModifiableConfiguration lconf = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.LOCAL);
for (Map.Entry<TestConfigOption, Object> option : options.entrySet()) {
if (option.getKey().option.isLocal()) {
lconf.set(option.getKey().option, option.getValue(), option.getKey().umbrella);
} else {
if (gconf == null)
gconf = graph.openManagement();
gconf.set(ConfigElement.getPath(option.getKey().option, option.getKey().umbrella), option.getValue());
}
}
if (gconf != null)
gconf.commit();
lconf.close();
}
if (null != graph && graph.isOpen())
graph.close();
Preconditions.checkNotNull(config);
open(config);
}
use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.
the class ManagementTest method testReservedNamesRejectedForPropertyKeys.
@Test
public void testReservedNamesRejectedForPropertyKeys() {
for (String s : ILLEGAL_USER_DEFINED_NAMES) {
TitanManagement tm = graph.openManagement();
try {
tm.makePropertyKey(s);
Assert.fail("Property key \"" + s + "\" must be rejected");
} catch (IllegalArgumentException e) {
log.debug("Caught expected exception", e);
} finally {
tm.commit();
}
}
}
use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.
the class AbstractIndexManagementIT method testRepairGraphIndex.
@Test
public void testRepairGraphIndex() throws InterruptedException, BackendException, ExecutionException {
tx.commit();
mgmt.commit();
// Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
// Create and enable a graph index on age
TitanManagement m = graph.openManagement();
PropertyKey age = m.getPropertyKey("age");
m.buildIndex("verticesByAge", Vertex.class).addKey(age).buildCompositeIndex();
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to REGISTERED
assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge").status(SchemaStatus.REGISTERED).call().getSucceeded());
m = graph.openManagement();
TitanGraphIndex index = m.getGraphIndex("verticesByAge");
m.updateIndex(index, SchemaAction.ENABLE_INDEX);
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to ENABLED
assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "verticesByAge").status(SchemaStatus.ENABLED).call().getSucceeded());
// Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
assertFalse(graph.query().has("age", 10000).vertices().iterator().hasNext());
// Repair
MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
m = graph.openManagement();
index = m.getGraphIndex("verticesByAge");
ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
assertEquals(6, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
// Test the index
Iterable<TitanVertex> hits = graph.query().has("age", 4500).vertices();
assertNotNull(hits);
assertEquals(1, Iterables.size(hits));
TitanVertex v = Iterables.getOnlyElement(hits);
assertNotNull(v);
assertEquals("neptune", v.value("name"));
}
use of com.thinkaurelius.titan.core.schema.TitanManagement in project titan by thinkaurelius.
the class AbstractIndexManagementIT method testRepairRelationIndex.
@Test
public void testRepairRelationIndex() throws InterruptedException, BackendException, ExecutionException {
tx.commit();
mgmt.commit();
// Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
// Create and enable a relation index on lives edges by reason
TitanManagement m = graph.openManagement();
PropertyKey reason = m.getPropertyKey("reason");
EdgeLabel lives = m.getEdgeLabel("lives");
m.buildEdgeIndex(lives, "livesByReason", Direction.BOTH, Order.decr, reason);
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to REGISTERED
assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives").status(SchemaStatus.REGISTERED).call().getSucceeded());
m = graph.openManagement();
RelationTypeIndex index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
m.updateIndex(index, SchemaAction.ENABLE_INDEX);
m.commit();
graph.tx().commit();
// Block until the SchemaStatus transitions to ENABLED
assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives").status(SchemaStatus.ENABLED).call().getSucceeded());
// Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
//assertFalse(graph.query().has("reason", "no fear of death").edges().iterator().hasNext());
// Repair
MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
m = graph.openManagement();
index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
assertEquals(8, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
}
Aggregations