Search in sources :

Example 61 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class GraphIndexStatusWatcher method call.

@Override
public GraphIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(graphIndexName, "Index name must not be null");
    Preconditions.checkNotNull(statuses, "Target statuses must not be null");
    Preconditions.checkArgument(statuses.size() > 0, "Target statuses must include at least one status");
    Map<String, SchemaStatus> notConverged = new HashMap<>();
    Map<String, SchemaStatus> converged = new HashMap<>();
    JanusGraphIndex idx;
    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        JanusGraphManagement management = null;
        try {
            management = g.openManagement();
            idx = management.getGraphIndex(graphIndexName);
            for (PropertyKey pk : idx.getFieldKeys()) {
                SchemaStatus s = idx.getIndexStatus(pk);
                LOGGER.debug("Key {} has status {}", pk, s);
                if (!statuses.contains(s))
                    notConverged.put(pk.toString(), s);
                else
                    converged.put(pk.toString(), s);
            }
        } finally {
            if (null != management)
                // Let an exception here propagate up the stack
                management.rollback();
        }
        if (!notConverged.isEmpty()) {
            String waitingOn = StringUtils.join(notConverged, "=", ",");
            LOGGER.info("Some key(s) on index {} do not currently have status(es) {}: {}", graphIndexName, statuses, waitingOn);
        } else {
            LOGGER.info("All {} key(s) on index {} have status(es) {}", converged.size(), graphIndexName, statuses);
            return new GraphIndexStatusReport(true, graphIndexName, statuses, notConverged, converged, t.elapsed());
        }
        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);
        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} to converge on status(es) {}", timeout, graphIndexName, statuses);
            return new GraphIndexStatusReport(false, graphIndexName, statuses, notConverged, converged, t.elapsed());
        }
        notConverged.clear();
        converged.clear();
        Thread.sleep(poll.toMillis());
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Timer(org.janusgraph.diskstorage.util.time.Timer) HashMap(java.util.HashMap) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) PropertyKey(org.janusgraph.core.PropertyKey)

Example 62 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class RelationIndexStatusWatcher method call.

/**
 * Poll a relation index until it has a certain {@link SchemaStatus},
 * or until a configurable timeout is exceeded.
 *
 * @return a report with information about schema state, execution duration, and the index
 */
@Override
public RelationIndexStatusReport call() throws InterruptedException {
    Preconditions.checkNotNull(g, "Graph instance must not be null");
    Preconditions.checkNotNull(relationIndexName, "Index name must not be null");
    Preconditions.checkNotNull(statuses, "Target statuses must not be null");
    Preconditions.checkArgument(statuses.size() > 0, "Target statuses must include at least one status");
    RelationTypeIndex idx;
    Timer t = new Timer(TimestampProviders.MILLI).start();
    boolean timedOut;
    while (true) {
        final SchemaStatus actualStatus;
        JanusGraphManagement management = null;
        try {
            management = g.openManagement();
            idx = management.getRelationIndex(management.getRelationType(relationTypeName), relationIndexName);
            actualStatus = idx.getIndexStatus();
            LOGGER.info("Index {} (relation type {}) has status {}", relationIndexName, relationTypeName, actualStatus);
            if (statuses.contains(actualStatus)) {
                return new RelationIndexStatusReport(true, relationIndexName, relationTypeName, actualStatus, statuses, t.elapsed());
            }
        } finally {
            if (null != management)
                // Let an exception here propagate up the stack
                management.rollback();
        }
        timedOut = null != timeout && 0 < t.elapsed().compareTo(timeout);
        if (timedOut) {
            LOGGER.info("Timed out ({}) while waiting for index {} (relation type {}) to reach status(es) {}", timeout, relationIndexName, relationTypeName, statuses);
            return new RelationIndexStatusReport(false, relationIndexName, relationTypeName, actualStatus, statuses, t.elapsed());
        }
        Thread.sleep(poll.toMillis());
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Timer(org.janusgraph.diskstorage.util.time.Timer) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) SchemaStatus(org.janusgraph.core.schema.SchemaStatus)

Example 63 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class JanusGraphApp method createSchema.

@Override
public void createSchema() {
    final JanusGraphManagement management = getJanusGraph().openManagement();
    try {
        // naive check if the schema was previously created
        if (management.getRelationTypes(RelationType.class).iterator().hasNext()) {
            management.rollback();
            return;
        }
        LOGGER.info("creating schema");
        createProperties(management);
        createVertexLabels(management);
        createEdgeLabels(management);
        createCompositeIndexes(management);
        createMixedIndexes(management);
        management.commit();
    } catch (Exception e) {
        management.rollback();
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) IOException(java.io.IOException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Example 64 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class QueryTest method testFuzzyMatchWithoutIndex.

@Test
public void testFuzzyMatchWithoutIndex() {
    JanusGraphManagement mgmt = graph.openManagement();
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.commit();
    tx.addVertex().property("name", "some value");
    tx.commit();
    // Exact match
    assertEquals(1, graph.traversal().V().has("name", Text.textFuzzy("some value")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textContainsFuzzy("value")).count().next());
    // One character different
    assertEquals(1, graph.traversal().V().has("name", Text.textFuzzy("some values")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textContainsFuzzy("values")).count().next());
    // Two characters different
    assertEquals(1, graph.traversal().V().has("name", Text.textFuzzy("some val")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textContainsFuzzy("values!")).count().next());
    // Three characters different
    assertEquals(0, graph.traversal().V().has("name", Text.textFuzzy("some Val")).count().next());
    assertEquals(0, graph.traversal().V().has("name", Text.textContainsFuzzy("valuable")).count().next());
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.jupiter.api.Test)

Example 65 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project janusgraph by JanusGraph.

the class QueryTest method testTextNegatedWithoutIndex.

@Test
public void testTextNegatedWithoutIndex() {
    JanusGraphManagement mgmt = graph.openManagement();
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    mgmt.commit();
    tx.addVertex().property("name", "some value");
    tx.addVertex().property("name", "other value");
    tx.commit();
    // Text.textNotFuzzy
    assertEquals(1, graph.traversal().V().has("name", Text.textNotFuzzy("other values")).count().next());
    assertEquals(2, graph.traversal().V().has("name", Text.textNotFuzzy("final values")).count().next());
    // Text.textNotRegex
    assertEquals(0, graph.traversal().V().has("name", Text.textNotRegex(".*value")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textNotRegex("other.*")).count().next());
    assertEquals(2, graph.traversal().V().has("name", Text.textNotRegex("final.*")).count().next());
    // Text.textNotPrefix
    assertEquals(1, graph.traversal().V().has("name", Text.textNotPrefix("other")).count().next());
    assertEquals(2, graph.traversal().V().has("name", Text.textNotPrefix("final")).count().next());
    // Text.textNotContains
    assertEquals(0, graph.traversal().V().has("name", Text.textNotContains("value")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textNotContains("other")).count().next());
    assertEquals(2, graph.traversal().V().has("name", Text.textNotContains("final")).count().next());
    // Text.textNotContainsFuzzy
    assertEquals(0, graph.traversal().V().has("name", Text.textNotContainsFuzzy("values")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textNotContainsFuzzy("others")).count().next());
    assertEquals(2, graph.traversal().V().has("name", Text.textNotContainsFuzzy("final")).count().next());
    // Text.textNotContainsRegex
    assertEquals(0, graph.traversal().V().has("name", Text.textNotContainsRegex("val.*")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textNotContainsRegex("oth.*")).count().next());
    assertEquals(2, graph.traversal().V().has("name", Text.textNotContainsRegex("fin.*")).count().next());
    // Text.textNotContainsPrefix
    assertEquals(0, graph.traversal().V().has("name", Text.textNotContainsPrefix("val")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textNotContainsPrefix("oth")).count().next());
    assertEquals(2, graph.traversal().V().has("name", Text.textNotContainsPrefix("final")).count().next());
    // Text.textNotContainsPhrase
    assertEquals(0, graph.traversal().V().has("name", Text.textNotContainsPhrase("value")).count().next());
    assertEquals(1, graph.traversal().V().has("name", Text.textNotContainsPhrase("other value")).count().next());
    assertEquals(2, graph.traversal().V().has("name", Text.textNotContainsPhrase("final value")).count().next());
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.jupiter.api.Test)

Aggregations

JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)92 PropertyKey (org.janusgraph.core.PropertyKey)44 Test (org.junit.jupiter.api.Test)26 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)24 JanusGraph (org.janusgraph.core.JanusGraph)23 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)20 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)17 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)12 HashMap (java.util.HashMap)9 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)8 Test (org.junit.Test)8 JanusGraphDBEngine (org.onap.aai.serialization.engines.JanusGraphDBEngine)8 TransactionalGraphEngine (org.onap.aai.serialization.engines.TransactionalGraphEngine)8 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)7 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)6 EdgeLabel (org.janusgraph.core.EdgeLabel)6 Map (java.util.Map)5 JanusGraphException (org.janusgraph.core.JanusGraphException)5