Search in sources :

Example 21 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();
        }
        String waitingOn = Joiner.on(",").withKeyValueSeparator("=").join(notConverged);
        if (!notConverged.isEmpty()) {
            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 22 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 23 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) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 24 with JanusGraphManagement

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

the class AbstractIndexManagementIT method testRemoveGraphIndex.

@Test
public void testRemoveGraphIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();
    // Load the "Graph of the Gods" sample data
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
    // Disable the "name" composite index
    JanusGraphManagement m = graph.openManagement();
    JanusGraphIndex nameIndex = m.getGraphIndex("name");
    m.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to DISABLED
    assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "name").status(SchemaStatus.DISABLED).call().getSucceeded());
    // Remove index
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    JanusGraphIndex index = m.getGraphIndex("name");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REMOVE_INDEX).get();
    assertEquals(12, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT));
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) Test(org.junit.Test) JanusGraphBaseTest(org.janusgraph.graphdb.JanusGraphBaseTest)

Example 25 with JanusGraphManagement

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

the class AbstractJanusGraphProvider method loadGraphData.

@Override
public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) {
    if (loadGraphWith != null) {
        this.createIndices((JanusGraph) g, loadGraphWith.value());
    } else {
        if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) {
            JanusGraphManagement management = ((JanusGraph) g).openManagement();
            management.makePropertyKey("blah").dataType(Double.class).make();
            management.makePropertyKey("bloop").dataType(Integer.class).make();
            management.makePropertyKey("test").dataType(Object.class).make();
            management.makeEdgeLabel("friend").make();
            management.commit();
        }
    }
    super.loadGraphData(g, loadGraphWith, testClass, testName);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraph(org.janusgraph.core.JanusGraph) TransactionTest(org.apache.tinkerpop.gremlin.structure.TransactionTest)

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