use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class JanusGraphBaseTest 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);
JanusGraphManagement janusGraphManagement = null;
ModifiableConfiguration modifiableConfiguration = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.LOCAL);
for (Map.Entry<TestConfigOption, Object> option : options.entrySet()) {
if (option.getKey().option.isLocal()) {
modifiableConfiguration.set(option.getKey().option, option.getValue(), option.getKey().umbrella);
} else {
if (janusGraphManagement == null)
janusGraphManagement = graph.openManagement();
janusGraphManagement.set(ConfigElement.getPath(option.getKey().option, option.getKey().umbrella), option.getValue());
}
}
if (janusGraphManagement != null)
janusGraphManagement.commit();
modifiableConfiguration.close();
}
if (null != graph && null != graph.tx() && graph.tx().isOpen())
graph.tx().commit();
if (null != graph && graph.isOpen())
graph.close();
Preconditions.checkNotNull(config);
open(config);
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class SerializerGraphConfiguration method testOnlyRegisteredSerialization.
@Test
public void testOnlyRegisteredSerialization() {
JanusGraphManagement management = graph.openManagement();
PropertyKey time = management.makePropertyKey("time").dataType(Integer.class).make();
management.makePropertyKey("any").cardinality(Cardinality.LIST).dataType(Object.class).make();
management.buildIndex("byTime", Vertex.class).addKey(time).buildCompositeIndex();
management.makeEdgeLabel("knows").make();
management.makeVertexLabel("person").make();
management.commit();
JanusGraphTransaction tx = graph.newTransaction();
JanusGraphVertex v = tx.addVertex("person");
v.property("time", 5);
v.property("any", 5.0);
v.property("any", new TClass1(5, 1.5f));
v.property("any", TEnum.THREE);
tx.commit();
tx = graph.newTransaction();
v = tx.query().has("time", 5).vertices().iterator().next();
assertEquals(5, (int) v.value("time"));
assertEquals(3, Iterators.size(v.properties("any")));
tx.rollback();
// Verify that non-registered objects aren't allowed
for (Object o : new Object[] { new TClass2("abc", 5) }) {
tx = graph.newTransaction();
v = tx.addVertex("person");
try {
// Should not be allowed
v.property("any", o);
tx.commit();
fail();
} catch (IllegalArgumentException ignored) {
} finally {
if (tx.isOpen())
tx.rollback();
}
}
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
the class JanusGraphAppTest method createSchema.
@Test
public void createSchema() throws ConfigurationException {
final JanusGraphApp app = new JanusGraphApp(CONF_FILE);
final GraphTraversalSource g = app.openGraph();
app.createSchema();
final JanusGraph janusGraph = (JanusGraph) g.getGraph();
final JanusGraphManagement management = janusGraph.openManagement();
final List<String> vertexLabels = StreamSupport.stream(management.getVertexLabels().spliterator(), false).map(Namifiable::name).collect(Collectors.toList());
final List<String> expectedVertexLabels = Stream.of("titan", "location", "god", "demigod", "human", "monster").collect(Collectors.toList());
assertTrue(vertexLabels.containsAll(expectedVertexLabels));
final List<String> edgeLabels = StreamSupport.stream(management.getRelationTypes(EdgeLabel.class).spliterator(), false).map(Namifiable::name).collect(Collectors.toList());
final List<String> expectedEdgeLabels = Stream.of("father", "mother", "brother", "pet", "lives", "battled").collect(Collectors.toList());
assertTrue(edgeLabels.containsAll(expectedEdgeLabels));
final EdgeLabel father = management.getEdgeLabel("father");
assertTrue(father.isDirected());
assertFalse(father.isUnidirected());
assertEquals(Multiplicity.MANY2ONE, father.multiplicity());
final List<String> propertyKeys = StreamSupport.stream(management.getRelationTypes(PropertyKey.class).spliterator(), false).map(Namifiable::name).collect(Collectors.toList());
final List<String> expectedPropertyKeys = Stream.of("name", "age", "time", "place", "reason").collect(Collectors.toList());
assertTrue(propertyKeys.containsAll(expectedPropertyKeys));
final PropertyKey place = management.getPropertyKey("place");
assertEquals(Cardinality.SINGLE, place.cardinality());
assertEquals(Geoshape.class, place.dataType());
final JanusGraphIndex nameIndex = management.getGraphIndex("nameIndex");
assertTrue(nameIndex.isCompositeIndex());
assertTrue(nameIndex.getIndexedElement().equals(JanusGraphVertex.class));
final PropertyKey[] nameIndexKeys = nameIndex.getFieldKeys();
assertEquals(1, nameIndexKeys.length);
assertEquals("name", nameIndexKeys[0].name());
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
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
JanusGraphManagement 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));
}
use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.
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
JanusGraphManagement 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();
JanusGraphIndex 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<JanusGraphVertex> hits = graph.query().has("age", 4500).vertices();
assertNotNull(hits);
assertEquals(1, Iterables.size(hits));
JanusGraphVertex v = Iterables.getOnlyElement(hits);
assertNotNull(v);
assertEquals("neptune", v.value("name"));
}
Aggregations