Search in sources :

Example 6 with JanusGraphManagement

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);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement)

Example 7 with JanusGraphManagement

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();
        }
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement)

Example 8 with JanusGraphManagement

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());
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraph(org.janusgraph.core.JanusGraph) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Example 9 with JanusGraphManagement

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));
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) EdgeLabel(org.janusgraph.core.EdgeLabel) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 10 with JanusGraphManagement

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"));
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Aggregations

JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)27 PropertyKey (org.janusgraph.core.PropertyKey)10 Test (org.junit.Test)10 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)9 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)8 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)7 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)6 JanusGraph (org.janusgraph.core.JanusGraph)5 EdgeLabel (org.janusgraph.core.EdgeLabel)4 ScanMetrics (org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics)4 ResourceBundle (java.util.ResourceBundle)3 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)3 RelationType (org.janusgraph.core.RelationType)3 RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)2 JanusGraphException (org.janusgraph.core.JanusGraphException)2 Geoshape (org.janusgraph.core.attribute.Geoshape)2 SchemaStatus (org.janusgraph.core.schema.SchemaStatus)2