Java Code Examples for com.thinkaurelius.titan.core.TitanGraph

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.TitanGraph. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: keti   File: GraphConfig.java   View source code 6 votes vote down vote up
public static void createUniqueCompositeIndex(final Graph newGraph, final String indexName,
        final String[] propertyKeyNames, final Class<?> propertyKeyType) throws InterruptedException {

    Assert.notEmpty(propertyKeyNames);
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    IndexBuilder indexBuilder = mgmt.buildIndex(indexName, Vertex.class);
    if (!mgmt.containsGraphIndex(indexName)) {
        for (String propertyKeyName : propertyKeyNames) {
            PropertyKey indexPropertyKey = getOrCreatePropertyKey(propertyKeyName, propertyKeyType, mgmt);
            indexBuilder.addKey(indexPropertyKey);
        }
        indexBuilder.unique().buildCompositeIndex();
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
 
Example 2
Project: mizo   File: MizoRDD.java   View source code 6 votes vote down vote up
/**
 * Given a path for Titan config file, connects and gets the internal Titan types,
 * converting them to MizoTitanRelationTypes mapped by type-ids
 * @param titanConfigPath Path to Titan's config path
 * @return Mapping between relation type-ids to InternalRelationType instances
 */
protected static HashMap<Long, MizoTitanRelationType> loadRelationTypes(String titanConfigPath) {
    TitanGraph g = TitanFactory.open(titanConfigPath);
    StandardTitanTx tx = (StandardTitanTx)g.buildTransaction().readOnly().start();

    HashMap<Long, MizoTitanRelationType> relations = Maps.newHashMap();

    tx.query()
            .has(BaseKey.SchemaCategory, Contain.IN, Lists.newArrayList(TitanSchemaCategory.values()))
            .vertices()
            .forEach(v -> {
                if (v instanceof InternalRelationType)
                    relations.put(v.longId(), new MizoTitanRelationType((InternalRelationType)v));
            });

    tx.close();

    try {
        ((StandardTitanGraph)g).getBackend().close();
    } catch (BackendException e) {
        e.printStackTrace();
    }

    return relations;
}
 
Example 3
Project: titan1withtp3.1   File: AbstractTitanGraphProvider.java   View source code 6 votes vote down vote up
@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
    if (null != g) {
        while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
        TitanGraph graph = (TitanGraph) g;
        if (graph.isOpen()) {
            if (g.tx().isOpen()) g.tx().rollback();
            g.close();
        }
    }

    WriteConfiguration config = new CommonsConfiguration(configuration);
    BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
    if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
        TitanGraphBaseTest.clearGraph(config);
    }
}
 
Example 4
Project: titan1withtp3.1   File: AbstractTitanGraphProvider.java   View source code 6 votes vote down vote up
@Override
public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) {
    if (loadGraphWith != null) {
        this.createIndices((TitanGraph) g, loadGraphWith.value());
    } else {
        if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) {
            TitanManagement mgmt = ((TitanGraph) g).openManagement();
            mgmt.makePropertyKey("blah").dataType(Double.class).make();
            mgmt.makePropertyKey("bloop").dataType(Integer.class).make();
            mgmt.makePropertyKey("test").dataType(Object.class).make();
            mgmt.makeEdgeLabel("friend").make();
            mgmt.commit();
        }
    }
    super.loadGraphData(g, loadGraphWith, testClass, testName);
}
 
Example 5
Project: titan0.5.4-hbase1.1.1-custom   File: SchemaContainer.java   View source code 6 votes vote down vote up
public SchemaContainer(TitanGraph graph) {
    vertexLabels = Maps.newHashMap();
    relationTypes = Maps.newHashMap();
    TitanManagement mgmt = graph.getManagementSystem();

    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 6
Project: titan1withtp3.1   File: ElasticSearchConfigTest.java   View source code 6 votes vote down vote up
@Test
public void testTitanFactoryBuilder()
{
    String baseDir = Joiner.on(File.separator).join("target", "es", "titanfactory_jvmlocal_ext");
    TitanFactory.Builder builder = TitanFactory.build();
    builder.set("storage.backend", "inmemory");
    builder.set("index." + INDEX_NAME + ".elasticsearch.interface", "NODE");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
    TitanGraph graph = builder.open(); // Must not throw an exception
    assertTrue(graph.isOpen());
    graph.close();
}
 
Example 7
Project: titan1withtp3.1   File: ManagementSystem.java   View source code 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 8
Project: titan0.5.4-hbase1.1.1-custom   File: TitanCassandraInputFormatTest.java   View source code 6 votes vote down vote up
@Test
public void testCanReadListValuedProperty() throws Exception {
    TitanGraph tg = TitanFactory.open(getTitanConfiguration());

    TitanManagement mgmt = tg.getManagementSystem();
    mgmt.makePropertyKey("email").dataType(String.class).cardinality(com.thinkaurelius.titan.core.Cardinality.LIST).make();
    mgmt.commit();
    tg.commit();

    TitanVertex v = tg.addVertex();
    v.addProperty("email", "one");
    v.addProperty("email", "two");
    tg.commit();

    Configuration c = new Configuration();
    c.set("titan.hadoop.input.format", "com.thinkaurelius.titan.hadoop.formats.cassandra.TitanCassandraInputFormat");
    c.set("titan.hadoop.input.conf.storage.backend", "cassandrathrift");
    c.set("titan.hadoop.input.conf.storage.cassandra.keyspace", KEYSPACE_NAME);
    c.set("titan.hadoop.sideeffect.format", "org.apache.hadoop.mapreduce.lib.output.TextOutputFormat");
    c.set("titan.hadoop.output.format", "com.thinkaurelius.titan.hadoop.formats.graphson.GraphSONOutputFormat");
    c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner");

    HadoopGraph hg = new HadoopGraph(c);

    assertEquals(0, new HadoopPipeline(hg).V().map().submit());
}
 
Example 9
Project: titan1withtp3.1   File: SchemaContainer.java   View source code 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 10
Project: titan1withtp3.1   File: TitanCleanup.java   View source code 6 votes vote down vote up
/**
 * Clears out the entire graph. This will delete ALL of the data stored in this graph and the data will NOT be
 * recoverable. This method is intended only for development and testing use.
 *
 * @param graph
 * @throws IllegalArgumentException if the graph has not been shut down
 * @throws com.thinkaurelius.titan.core.TitanException if clearing the storage is unsuccessful
 */
public static final void clear(TitanGraph graph) {
    Preconditions.checkNotNull(graph);
    Preconditions.checkArgument(graph instanceof StandardTitanGraph,"Invalid graph instance detected: %s",graph.getClass());
    StandardTitanGraph g = (StandardTitanGraph)graph;
    Preconditions.checkArgument(!g.isOpen(),"Graph needs to be shut down before it can be cleared.");
    final GraphDatabaseConfiguration config = g.getConfiguration();
    BackendOperation.execute(new Callable<Boolean>(){
        @Override
        public Boolean call() throws Exception {
            config.getBackend().clearStorage();
            return true;
        }
        @Override
        public String toString() { return "ClearBackend"; }
    }, Duration.ofSeconds(20));
}
 
Example 11
Project: titan0.5.4-hbase1.1.1-custom   File: TitanSchemaAwareMapper.java   View source code 6 votes vote down vote up
@Override
protected void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);

    // Catch any exceptions, log a warning, and allow the subclass to continue even if schema loading failed
    try {
        ModifiableHadoopConfiguration faunusConf =
                ModifiableHadoopConfiguration.of(DEFAULT_COMPAT.getContextConfiguration(context));

        if (faunusConf.get(TitanHadoopConfiguration.OUTPUT_TITAN_TYPE_CHECKING)) {
            TitanGraph g = TitanFactory.open(faunusConf.getOutputConf());
            FaunusSchemaManager.getTypeManager(null).setSchemaProvider(new SchemaContainer(g));
            log.info("Loaded schema associated with {}", g);
        } else {
            log.debug("Titan schema checking is disabled");
        }
    } catch (Throwable t) {
        log.warn("Unable to load Titan schema", t);
    }
}
 
Example 12
Project: titan-tp3-java-example   File: JavaExample.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    String dataDir = "./data";
    TitanGraph graph = TitanFactory.open("berkeleyje:" + dataDir);

    // see org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateClassic()
    final Vertex marko = graph.addVertex("name", "marko", "age", 29);
    final Vertex vadas = graph.addVertex("name", "vadas", "age", 27);
    final Vertex lop = graph.addVertex("name", "lop", "lang", "java");
    final Vertex josh = graph.addVertex("name", "josh", "age", 32);
    final Vertex ripple = graph.addVertex("name", "ripple", "lang", "java");
    final Vertex peter = graph.addVertex("name", "peter", "age", 35);
    marko.addEdge("knows", vadas, "weight", 0.5f);
    marko.addEdge("knows", josh, "weight", 1.0f);
    marko.addEdge("created", lop, "weight", 0.4f);
    josh.addEdge("created", ripple, "weight", 1.0f);
    josh.addEdge("created", lop, "weight", 0.4f);
    peter.addEdge("created", lop, "weight", 0.2f);

    GraphTraversalSource g = graph.traversal();
    Vertex fromNode = g.V().has("name", "marko").next();
    Vertex toNode = g.V().has("name", "peter").next();
    ArrayList list = new ArrayList();
    g.V(fromNode).repeat(both().simplePath()).until(is(toNode)).limit(1).path().fill(list);
    LOGGER.info(list.toString());
    System.exit(0);
}
 
Example 13
Project: incubator-atlas   File: Titan1GraphDatabase.java   View source code 6 votes vote down vote up
public static TitanGraph getGraphInstance() {
    if (graphInstance == null) {
        synchronized (Titan1GraphDatabase.class) {
            if (graphInstance == null) {
                Configuration config;
                try {
                    config = getConfiguration();
                } catch (AtlasException e) {
                    throw new RuntimeException(e);
                }

                graphInstance = TitanFactory.open(config);
                atlasGraphInstance = new Titan1Graph();
                validateIndexBackend(config);
            }
        }
    }
    return graphInstance;
}
 
Example 14
Project: titan0.5.4-hbase1.1.1-custom   File: LoaderScriptWrapper.java   View source code 6 votes vote down vote up
public TitanEdge getEdge(FaunusEdge faunusEdge, TitanVertex in, TitanVertex out, TitanGraph graph, Mapper.Context context) {
    Bindings bindings = new SimpleBindings();
    bindings.put("faunusEdge", faunusEdge);
    bindings.put("inVertex", in);
    bindings.put("outVertex", out);
    bindings.put("graph", graph);
    bindings.put("context", context);
    bindings.put("log", LOGGER);
    DEFAULT_COMPAT.incrementContextCounter(context, Counters.EDGE_LOADER_SCRIPT_CALLS, 1L);
    try {
        TitanEdge edge = (TitanEdge)edgeMethod.eval(bindings);
        LOGGER.debug("Compiled edge method returned {}", edge);
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.EDGE_LOADER_SCRIPT_RETURNS, 1L);
        return edge;
    } catch (ScriptException e) {
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.EDGE_LOADER_SCRIPT_EXCEPTIONS, 1L);
        throw new RuntimeException(e);
    }
}
 
Example 15
Project: incubator-atlas   File: Titan0GraphDatabase.java   View source code 6 votes vote down vote up
public static TitanGraph getGraphInstance() {
    if (graphInstance == null) {
        synchronized (Titan0GraphDatabase.class) {
            if (graphInstance == null) {
                Configuration config;
                try {
                    config = getConfiguration();
                } catch (AtlasException e) {
                    throw new RuntimeException(e);
                }

                graphInstance = TitanFactory.open(config);
                atlasGraphInstance = new Titan0Graph();
                validateIndexBackend(config);
            }
        }
    }
    return graphInstance;
}
 
Example 16
Project: titan1.0.1.kafka   File: AbstractTitanGraphProvider.java   View source code 6 votes vote down vote up
@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
    if (null != g) {
        while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
        TitanGraph graph = (TitanGraph) g;
        if (graph.isOpen()) {
            if (g.tx().isOpen()) g.tx().rollback();
            g.close();
        }
    }

    WriteConfiguration config = new CommonsConfiguration(configuration);
    BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
    if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
        TitanGraphBaseTest.clearGraph(config);
    }
}
 
Example 17
Project: titan1.0.1.kafka   File: AbstractTitanGraphProvider.java   View source code 6 votes vote down vote up
@Override
public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) {
    if (loadGraphWith != null) {
        this.createIndices((TitanGraph) g, loadGraphWith.value());
    } else {
        if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) {
            TitanManagement mgmt = ((TitanGraph) g).openManagement();
            mgmt.makePropertyKey("blah").dataType(Double.class).make();
            mgmt.makePropertyKey("bloop").dataType(Integer.class).make();
            mgmt.makePropertyKey("test").dataType(Object.class).make();
            mgmt.makeEdgeLabel("friend").make();
            mgmt.commit();
        }
    }
    super.loadGraphData(g, loadGraphWith, testClass, testName);
}
 
Example 18
Project: titan1.0.1.kafka   File: ElasticSearchConfigTest.java   View source code 6 votes vote down vote up
@Test
public void testTitanFactoryBuilder()
{
    String baseDir = Joiner.on(File.separator).join("target", "es", "titanfactory_jvmlocal_ext");
    TitanFactory.Builder builder = TitanFactory.build();
    builder.set("storage.backend", "inmemory");
    builder.set("index." + INDEX_NAME + ".elasticsearch.interface", "NODE");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
    builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
    TitanGraph graph = builder.open(); // Must not throw an exception
    assertTrue(graph.isOpen());
    graph.close();
}
 
Example 19
Project: molgraph   File: UniprotTest01.java   View source code 6 votes vote down vote up
@Test
  public void readUniprot() throws Exception
  {
    TitanGraph g = Titans.openHBaseGraph();
//    TransactionBuilder tx = g.buildTransaction();
//    tx.enableBatchLoading();
//    TitanTransaction t = tx.start();
    g.shutdown(); TitanCleanup.clear(g);
//    Graphs.clear(g);

    g = Titans.openHBaseGraph();
    UniprotHandler uniprot = new UniprotHandler(g, "Homo sapiens");
    uniprot.parseDocument("/home/wyu/Projects/molgraph/data/up1k.xml");
//    uniprot.parseDocument("/media/data/import/bio4j/uniprot_sprot.xml");
    g.shutdown();
  }
 
Example 20
Project: titan0.5.4-hbase1.1.1-custom   File: LoaderScriptWrapper.java   View source code 6 votes vote down vote up
public TitanVertex getVertex(FaunusVertex faunusVertex, TitanGraph graph, Mapper.Context context) {
    Bindings bindings = new SimpleBindings();
    bindings.put("faunusVertex", faunusVertex);
    bindings.put("graph", graph);
    bindings.put("context", context);
    bindings.put("log", LOGGER);
    DEFAULT_COMPAT.incrementContextCounter(context, Counters.VERTEX_LOADER_SCRIPT_CALLS, 1L);
    try {
        TitanVertex tv = (TitanVertex)vertexMethod.eval(bindings);
        LOGGER.debug("Compiled vertex loader script returned {}", tv);
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.VERTEX_LOADER_SCRIPT_RETURNS, 1L);
        return tv;
    } catch (ScriptException e) {
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.VERTEX_LOADER_SCRIPT_EXCEPTIONS, 1L);
        throw new RuntimeException(e);
    }
}
 
Example 21
Project: titan0.5.4-hbase1.1.1-custom   File: LoaderScriptWrapper.java   View source code 6 votes vote down vote up
public void getVProp(TitanProperty titanProperty, TitanVertex vertex, TitanGraph graph, Mapper.Context context) {
    Bindings bindings = new SimpleBindings();
    bindings.put("titanProperty", titanProperty);
    bindings.put("vertex", vertex);
    bindings.put("graph", graph);
    bindings.put("context", context);
    bindings.put("log", LOGGER);
    DEFAULT_COMPAT.incrementContextCounter(context, Counters.VERTEX_PROP_LOADER_SCRIPT_CALLS, 1L);
    try {
        vpropMethod.eval(bindings);
        LOGGER.debug("Compiled property loader method invoked");
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.VERTEX_PROP_LOADER_SCRIPT_RETURNS, 1L);
    } catch (ScriptException e) {
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.VERTEX_PROP_LOADER_SCRIPT_EXCEPTIONS, 1L);
        throw new RuntimeException(e);
    }
}
 
Example 22
Project: titan1.0.1.kafka   File: TitanCleanup.java   View source code 6 votes vote down vote up
/**
 * Clears out the entire graph. This will delete ALL of the data stored in this graph and the data will NOT be
 * recoverable. This method is intended only for development and testing use.
 *
 * @param graph
 * @throws IllegalArgumentException if the graph has not been shut down
 * @throws com.thinkaurelius.titan.core.TitanException if clearing the storage is unsuccessful
 */
public static final void clear(TitanGraph graph) {
    Preconditions.checkNotNull(graph);
    Preconditions.checkArgument(graph instanceof StandardTitanGraph,"Invalid graph instance detected: %s",graph.getClass());
    StandardTitanGraph g = (StandardTitanGraph)graph;
    Preconditions.checkArgument(!g.isOpen(),"Graph needs to be shut down before it can be cleared.");
    final GraphDatabaseConfiguration config = g.getConfiguration();
    BackendOperation.execute(new Callable<Boolean>(){
        @Override
        public Boolean call() throws Exception {
            config.getBackend().clearStorage();
            return true;
        }
        @Override
        public String toString() { return "ClearBackend"; }
    }, Duration.ofSeconds(20));
}
 
Example 23
Project: titan0.5.4-hbase1.1.1-custom   File: TestBed.java   View source code 6 votes vote down vote up
private static void codeSnippets() throws Exception {
    TitanGraph g = TitanFactory.open("/tmp/titan");
    g.createKeyIndex("name", Vertex.class);
    Vertex juno = g.addVertex(null);
    juno.setProperty("name", "juno");
    juno = g.getVertices("name", "juno").iterator().next();

    TransactionalGraph tx = g.newTransaction();
    Thread[] threads = new Thread[10];
    for (int i = 0; i < threads.length; i++) {
        //threads[i]=new Thread(new DoSomething(tx));
        threads[i].start();
    }
    for (int i = 0; i < threads.length; i++) threads[i].join();
    tx.commit();
}
 
Example 24
Project: titan0.5.4-hbase1.1.1-custom   File: GraphGenerator.java   View source code 6 votes vote down vote up
public static void main(String args[]) throws IOException {
    if (4 != args.length) {
        System.err.println("Usage: GraphGenerator titanproperties vertexcount edgecount outfile");
        System.exit(1);
    }
    int i = 0;
    String c = args[i++];
    int v = Integer.valueOf(args[i++]);
    int e = Integer.valueOf(args[i++]);
    String o = args[i++];
    Schema s = new Schema.Builder(v, e).build();
    TitanGraph graph = TitanFactory.open(c);
    new GraphGenerator(s).generateTypesAndData(graph);
    OutputStream out = new GZIPOutputStream(new FileOutputStream(o));
    GraphGenerator.writeData(graph, out);
    out.close();
    graph.shutdown();
    System.exit(0);
}
 
Example 25
Project: keti   File: GraphConfig.java   View source code 5 votes vote down vote up
public static void createIndex(final Graph newGraph, final String indexName, final String indexKey)
        throws InterruptedException {
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    if (!mgmt.containsGraphIndex(indexName)) {
        PropertyKey indexPropertyKey = mgmt.makePropertyKey(indexKey).dataType(String.class).make();
        mgmt.buildIndex(indexName, Vertex.class).addKey(indexPropertyKey).buildCompositeIndex();
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
 
Example 26
Project: keti   File: GraphConfig.java   View source code 5 votes vote down vote up
public static void createUniqueIndexForLabel(final Graph newGraph, final String indexName, final String indexKey,
        final String label) throws InterruptedException {
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    if (!mgmt.containsGraphIndex(indexName)) {
        PropertyKey indexPropertyKey = mgmt.makePropertyKey(indexKey).dataType(Integer.class).make();
        VertexLabel versionLabel = mgmt.makeVertexLabel(label).make();
        // Create a unique composite index for the property key that indexes only vertices with a given label
        mgmt.buildIndex(indexName, Vertex.class).addKey(indexPropertyKey).indexOnly(versionLabel).unique()
                .buildCompositeIndex();
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitGraphIndexStatus((TitanGraph) newGraph, indexName).status(SchemaStatus.ENABLED).call();
}
 
Example 27
Project: keti   File: GraphConfig.java   View source code 5 votes vote down vote up
public static void createEdgeIndex(final Graph newGraph, final String indexName, final String label,
        final String indexKey) throws InterruptedException {
    newGraph.tx().rollback(); // Never create new indexes while a transaction is active
    TitanManagement mgmt = ((TitanGraph) newGraph).openManagement();
    EdgeLabel edgeLabel = mgmt.getOrCreateEdgeLabel(label);
    if (!mgmt.containsRelationIndex(edgeLabel, indexName)) {
        PropertyKey indexPropertyKey = getOrCreatePropertyKey(indexKey, String.class, mgmt);
        mgmt.buildEdgeIndex(edgeLabel, indexName, Direction.OUT, indexPropertyKey);
    }
    mgmt.commit();
    // Wait for the index to become available
    ManagementSystem.awaitRelationIndexStatus((TitanGraph) newGraph, indexName, label).status(SchemaStatus.ENABLED)
            .call();
}
 
Example 28
Project: titan1withtp3.1   File: TitanIndexTest.java   View source code 5 votes vote down vote up
public static void assertGraphOfTheGods(TitanGraph gotg) {
    assertCount(12, gotg.query().vertices());
    assertCount(3, gotg.query().has(LABEL_NAME, "god").vertices());
    TitanVertex h = getOnlyVertex(gotg.query().has("name", "hercules"));
    assertEquals(30, h.<Integer>value("age").intValue());
    assertEquals("demigod", h.label());
    assertCount(5, h.query().direction(Direction.BOTH).edges());
    gotg.tx().commit();
}
 
Example 29
Project: titan1withtp3.1   File: VertexIDAssignerTest.java   View source code 5 votes vote down vote up
private static TitanGraph getInMemoryGraph() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, InMemoryStoreManager.class.getCanonicalName());
    config.set(GraphDatabaseConfiguration.IDS_FLUSH, false);
    config.set(GraphDatabaseConfiguration.IDAUTHORITY_WAIT, Duration.ofMillis(1L));
    return TitanFactory.open(config);
}
 
Example 30
Project: titan1withtp3.1   File: TinkerpopFeaturesTest.java   View source code 5 votes vote down vote up
public TitanGraph open(boolean useVertexIdSetting)
{
    TitanFactory.Builder builder = TitanFactory.build();
    builder.set("storage.backend", "inmemory");
    builder.set("graph.set-vertex-id", useVertexIdSetting);
    return builder.open();
}
 
Example 31
Project: titan1withtp3.1   File: HadoopVertexScanMapper.java   View source code 5 votes vote down vote up
@Override
protected void setup(Context context) throws IOException, InterruptedException {
    /* Don't call super implementation super.setup(context); */
    org.apache.hadoop.conf.Configuration hadoopConf = DEFAULT_COMPAT.getContextConfiguration(context);
    ModifiableHadoopConfiguration scanConf = ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, hadoopConf);
    VertexScanJob vertexScan = getVertexScanJob(scanConf);
    ModifiableConfiguration graphConf = getTitanConfiguration(context);
    TitanGraph graph = TitanFactory.open(graphConf);
    job = VertexJobConverter.convert(graph, vertexScan);
    metrics = new HadoopContextScanMetrics(context);
    finishSetup(scanConf, graphConf);
}
 
Example 32
Project: peapod   File: TitanSuite.java   View source code 5 votes vote down vote up
@BeforeClass
public static void setGraphProvider() throws IOException {
    GraphTest.graphProvider = new GraphProvider() {
        public Graph getGraph() throws IOException {
            TitanGraph graph = TitanFactory.build().set("storage.backend", "inmemory").open();
            TitanManagement management = graph.openManagement();
            management.makePropertyKey("location").dataType(String.class).cardinality(Cardinality.LIST).make();
            management.makePropertyKey("firstName").dataType(String.class).cardinality(Cardinality.LIST).make();
            management.commit();
            return graph;
        }
    };

}
 
Example 33
Project: titan0.5.4-hbase1.1.1-custom   File: BerkeleyElasticsearchTest.java   View source code 5 votes vote down vote up
/**
 * Test {@link com.thinkaurelius.titan.example.GraphOfTheGodsFactory#create(String)}.
 */
@Test
public void testGraphOfTheGodsFactoryCreate() {
    String bdbtmp = Joiner.on(File.separator).join("target", "gotgfactory");
    TitanGraph gotg = GraphOfTheGodsFactory.create(bdbtmp);
    TitanIndexTest.assertGraphOfTheGods(gotg);
    gotg.shutdown();
}
 
Example 34
Project: molgraph   File: UniprotTest01.java   View source code 5 votes vote down vote up
@Test
public void readVertices() throws Exception
{
  TitanGraph g = Titans.openHBaseGraph();

  Map<String, PropertyNode> tag_node = Graphs.getVertices(
      g.buildTransaction().start(), "gene");

  g.shutdown();

}
 
Example 35
Project: titan1.0.1.kafka   File: TitanIndexTest.java   View source code 5 votes vote down vote up
public static void assertGraphOfTheGods(TitanGraph gotg) {
    assertCount(12, gotg.query().vertices());
    assertCount(3, gotg.query().has(LABEL_NAME, "god").vertices());
    TitanVertex h = getOnlyVertex(gotg.query().has("name", "hercules"));
    assertEquals(30, h.<Integer>value("age").intValue());
    assertEquals("demigod", h.label());
    assertCount(5, h.query().direction(Direction.BOTH).edges());
    gotg.tx().commit();
}
 
Example 36
Project: titan1.0.1.kafka   File: VertexIDAssignerTest.java   View source code 5 votes vote down vote up
private static TitanGraph getInMemoryGraph() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, InMemoryStoreManager.class.getCanonicalName());
    config.set(GraphDatabaseConfiguration.IDS_FLUSH, false);
    config.set(GraphDatabaseConfiguration.IDAUTHORITY_WAIT, Duration.ofMillis(1L));
    return TitanFactory.open(config);
}
 
Example 37
Project: titan1.0.1.kafka   File: TinkerpopFeaturesTest.java   View source code 5 votes vote down vote up
public TitanGraph open(boolean useVertexIdSetting)
{
    TitanFactory.Builder builder = TitanFactory.build();
    builder.set("storage.backend", "inmemory");
    builder.set("graph.set-vertex-id", useVertexIdSetting);
    return builder.open();
}
 
Example 38
Project: titan1.0.1.kafka   File: BerkeleyElasticsearchTest.java   View source code 5 votes vote down vote up
/**
 * Test {@link com.thinkaurelius.titan.example.GraphOfTheGodsFactory#create(String)}.
 */
@Test
public void testGraphOfTheGodsFactoryCreate() {
    File bdbtmp = new File("target/gotgfactory");
    IOUtils.deleteDirectory(bdbtmp, true);

    TitanGraph gotg = GraphOfTheGodsFactory.create(bdbtmp.getPath());
    TitanIndexTest.assertGraphOfTheGods(gotg);
    gotg.close();
}
 
Example 39
Project: titan1.0.1.kafka   File: GraphOfTheGodsFactory.java   View source code 5 votes vote down vote up
public static TitanGraph create(final String directory) {
    TitanFactory.Builder config = TitanFactory.build();
    config.set("storage.backend", "berkeleyje");
    config.set("storage.directory", directory);
    config.set("index." + INDEX_NAME + ".backend", "elasticsearch");
    config.set("index." + INDEX_NAME + ".directory", directory + File.separator + "es");
    config.set("index." + INDEX_NAME + ".elasticsearch.local-mode", true);
    config.set("index." + INDEX_NAME + ".elasticsearch.client-only", false);

    TitanGraph graph = config.open();
    GraphOfTheGodsFactory.load(graph);
    return graph;
}
 
Example 40
Project: titan1.0.1.kafka   File: IndexUpdateJob.java   View source code 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);
    }
}