Java Code Examples for com.thinkaurelius.titan.core.TitanGraph#openManagement()

The following examples show how to use com.thinkaurelius.titan.core.TitanGraph#openManagement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagementSystem.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public Consumer<ScanMetrics> getIndexJobFinisher(final TitanGraph graph, final SchemaAction action) {
    Preconditions.checkArgument((graph != null && action != null) || (graph == null && action == null));
    return metrics -> {
        try {
            if (metrics.get(ScanMetrics.Metric.FAILURE) == 0) {
                if (action != null) {
                    ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
                    try {
                        TitanIndex index = retrieve(mgmt);
                        mgmt.updateIndex(index, action);
                    } finally {
                        mgmt.commit();
                    }
                }
                LOGGER.info("Index update job successful for [{}]", IndexIdentifier.this.toString());
            } else {
                LOGGER.error("Index update job unsuccessful for [{}]. Check logs", IndexIdentifier.this.toString());
            }
        } catch (Throwable e) {
            LOGGER.error("Error encountered when updating index after job finished [" + IndexIdentifier.this.toString() + "]: ", e);
        }
    };
}
 
Example 2
Source File: SchemaContainer.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.openManagement();

    try {
        for (VertexLabel vl : mgmt.getVertexLabels()) {
            VertexLabelDefinition vld = new VertexLabelDefinition(vl);
            vertexLabels.put(vld.getName(),vld);
        }

        for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
            EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
            relationTypes.put(eld.getName(),eld);
        }
        for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
            PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
            relationTypes.put(pkd.getName(), pkd);
        }
    } finally {
        mgmt.rollback();
    }

}
 
Example 3
Source File: IndexUpdateJob.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public void workerIterationStart(TitanGraph graph, Configuration config, ScanMetrics metrics) {
    this.graph = (StandardTitanGraph)graph;
    Preconditions.checkArgument(config.has(GraphDatabaseConfiguration.JOB_START_TIME),"Invalid configuration for this job. Start time is required.");
    this.jobStartTime = Instant.ofEpochMilli(config.get(GraphDatabaseConfiguration.JOB_START_TIME));
    if (indexName == null) {
        Preconditions.checkArgument(config.has(INDEX_NAME), "Need to configure the name of the index to be repaired");
        indexName = config.get(INDEX_NAME);
        indexRelationTypeName = config.get(INDEX_RELATION_TYPE);
        log.info("Read index information: name={} type={}", indexName, indexRelationTypeName);
    }

    try {
        this.mgmt = (ManagementSystem)graph.openManagement();

        if (isGlobalGraphIndex()) {
            index = mgmt.getGraphIndex(indexName);
        } else {
            indexRelationType = mgmt.getRelationType(indexRelationTypeName);
            Preconditions.checkArgument(indexRelationType!=null,"Could not find relation type: %s", indexRelationTypeName);
            index = mgmt.getRelationIndex(indexRelationType,indexName);
        }
        Preconditions.checkArgument(index!=null,"Could not find index: %s [%s]",indexName,indexRelationTypeName);
        log.info("Found index {}", indexName);
        validateIndexStatus();

        StandardTransactionBuilder txb = this.graph.buildTransaction();
        txb.commitTime(jobStartTime);
        writeTx = (StandardTitanTx)txb.start();
    } catch (final Exception e) {
        if (null != mgmt && mgmt.isOpen())
            mgmt.rollback();
        if (writeTx!=null && writeTx.isOpen())
            writeTx.rollback();
        metrics.incrementCustom(FAILED_TX);
        throw new TitanException(e.getMessage(), e);
    }
}
 
Example 4
Source File: GraphOfTheGodsFactory.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static void load(final TitanGraph graph, String mixedIndexName, boolean uniqueNameCompositeIndex) {

        //Create Schema
        TitanManagement mgmt = graph.openManagement();
        final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
        TitanManagement.IndexBuilder nameIndexBuilder = mgmt.buildIndex("name", Vertex.class).addKey(name);
        if (uniqueNameCompositeIndex)
            nameIndexBuilder.unique();
        TitanGraphIndex namei = nameIndexBuilder.buildCompositeIndex();
        mgmt.setConsistency(namei, ConsistencyModifier.LOCK);
        final PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
        if (null != mixedIndexName)
            mgmt.buildIndex("vertices", Vertex.class).addKey(age).buildMixedIndex(mixedIndexName);

        final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
        final PropertyKey reason = mgmt.makePropertyKey("reason").dataType(String.class).make();
        final PropertyKey place = mgmt.makePropertyKey("place").dataType(Geoshape.class).make();
        if (null != mixedIndexName)
            mgmt.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName);

        mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
        mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make();
        EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make();
        mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time);
        mgmt.makeEdgeLabel("lives").signature(reason).make();
        mgmt.makeEdgeLabel("pet").make();
        mgmt.makeEdgeLabel("brother").make();

        mgmt.makeVertexLabel("titan").make();
        mgmt.makeVertexLabel("location").make();
        mgmt.makeVertexLabel("god").make();
        mgmt.makeVertexLabel("demigod").make();
        mgmt.makeVertexLabel("human").make();
        mgmt.makeVertexLabel("monster").make();

        mgmt.commit();

        TitanTransaction tx = graph.newTransaction();
        // vertices

        Vertex saturn = tx.addVertex(T.label, "titan", "name", "saturn", "age", 10000);

        Vertex sky = tx.addVertex(T.label, "location", "name", "sky");

        Vertex sea = tx.addVertex(T.label, "location", "name", "sea");

        Vertex jupiter = tx.addVertex(T.label, "god", "name", "jupiter", "age", 5000);

        Vertex neptune = tx.addVertex(T.label, "god", "name", "neptune", "age", 4500);

        Vertex hercules = tx.addVertex(T.label, "demigod", "name", "hercules", "age", 30);

        Vertex alcmene = tx.addVertex(T.label, "human", "name", "alcmene", "age", 45);

        Vertex pluto = tx.addVertex(T.label, "god", "name", "pluto", "age", 4000);

        Vertex nemean = tx.addVertex(T.label, "monster", "name", "nemean");

        Vertex hydra = tx.addVertex(T.label, "monster", "name", "hydra");

        Vertex cerberus = tx.addVertex(T.label, "monster", "name", "cerberus");

        Vertex tartarus = tx.addVertex(T.label, "location", "name", "tartarus");

        // edges

        jupiter.addEdge("father", saturn);
        jupiter.addEdge("lives", sky, "reason", "loves fresh breezes");
        jupiter.addEdge("brother", neptune);
        jupiter.addEdge("brother", pluto);

        neptune.addEdge("lives", sea).property("reason", "loves waves");
        neptune.addEdge("brother", jupiter);
        neptune.addEdge("brother", pluto);

        hercules.addEdge("father", jupiter);
        hercules.addEdge("mother", alcmene);
        hercules.addEdge("battled", nemean, "time", 1, "place", Geoshape.point(38.1f, 23.7f));
        hercules.addEdge("battled", hydra, "time", 2, "place", Geoshape.point(37.7f, 23.9f));
        hercules.addEdge("battled", cerberus, "time", 12, "place", Geoshape.point(39f, 22f));

        pluto.addEdge("brother", jupiter);
        pluto.addEdge("brother", neptune);
        pluto.addEdge("lives", tartarus, "reason", "no fear of death");
        pluto.addEdge("pet", cerberus);

        cerberus.addEdge("lives", tartarus);

        // commit the transaction to disk
        tx.commit();
    }