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

The following are top voted examples for showing how to use com.thinkaurelius.titan.core.TitanFactory. 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 8 votes vote down vote up
public Graph createGraph() throws InterruptedException {
    Graph newGraph;
    if (this.cassandraEnabled) {
        Builder titanBuilder = TitanFactory.build().set("storage.backend", "cassandra")
                .set("storage.cassandra.keyspace", this.cassandraKeyspace)
                .set("storage.hostname", Arrays.asList(hostname.split(","))).set("storage.port", this.port)
                .set("cache.db-cache", this.cacheEnabled).set("cache.db-cache-clean-wait", this.titanCacheCleanWait)
                .set("cache.db-cache-time", this.titanCacheTime).set("cache.db-cache-size", this.titanCacheSize);
        if (StringUtils.isNotEmpty(this.username)) {
            titanBuilder = titanBuilder.set("storage.username", this.username);
        }
        if (StringUtils.isNotEmpty(this.password)) {
            titanBuilder = titanBuilder.set("storage.password", this.password);
        }
        newGraph = titanBuilder.open();
    } else {
        newGraph = TitanFactory.build().set("storage.backend", "inmemory").open();
    }
    createSchemaElements(newGraph);
    LOGGER.info("Initialized titan db.");
    return newGraph;
}
 
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: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByThreadBoundTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
    assertEquals("ALL",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("LOCAL_QUORUM",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
 
Example 4
Project: titan1withtp3.1   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.newTransaction();
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("THREE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 5
Project: titan1withtp3.1   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testCustomConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
            .customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
            .customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();

    assertEquals("ONE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.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: Driver.java   View source code 6 votes vote down vote up
private void doWork()
    {
        TitanGraph graph = TitanFactory.build().set("storage.backend", "inmemory").open();

        // do "auto" transaction work
        graph.addVertex("type", "human");
        graph.tx().commit();

        // do "named" transaction work
//        TitanTransaction tx = graph.buildTransaction().logIdentifier("david1").start();
//        Vertex v = tx.addVertex("type", "dog");
//        Long id = (Long)v.id();
//        tx.commit();

//        GraphTraversalSource g = graph.traversal();
//        Vertex v1 = g.V(id.longValue()).next();
//        v1.remove();

        graph.close();
    }
 
Example 8
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 9
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 10
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 11
Project: titan1.0.1.kafka   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByThreadBoundTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
    assertEquals("ALL",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("LOCAL_QUORUM",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
 
Example 12
Project: titan1.0.1.kafka   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.newTransaction();
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("THREE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 13
Project: titan1.0.1.kafka   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testCustomConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
            .customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
            .customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();

    assertEquals("ONE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 14
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 15
Project: titan0.5.4-hbase1.1.1-custom   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByThreadBoundTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
    assertEquals("ALL",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("LOCAL_QUORUM",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
}
 
Example 16
Project: titan0.5.4-hbase1.1.1-custom   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testGraphConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.newTransaction();
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("THREE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 17
Project: titan0.5.4-hbase1.1.1-custom   File: CassandraGraphTest.java   View source code 6 votes vote down vote up
@Test
public void testCustomConfigUsedByTx() {
    close();
    WriteConfiguration wc = getConfiguration();
    wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
    wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");

    graph = (StandardTitanGraph) TitanFactory.open(wc);

    StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
            .setCustomOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
            .setCustomOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();

    assertEquals("ONE",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
    assertEquals("TWO",
            tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
                    .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
    tx.rollback();
}
 
Example 18
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 19
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 20
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 21
Project: titan0.5.4-hbase1.1.1-custom   File: TitanIndexRepairMapper.java   View source code 6 votes vote down vote up
@Override
public void setup(
        final Mapper<NullWritable, FaunusVertex, NullWritable, NullWritable>.Context context) throws IOException {
    Configuration hadoopConf = DEFAULT_COMPAT.getContextConfiguration(context);
    ModifiableHadoopConfiguration faunusConf = ModifiableHadoopConfiguration.of(hadoopConf);
    BasicConfiguration titanConf = faunusConf.getOutputConf();
    indexName = faunusConf.get(TitanHadoopConfiguration.INDEX_NAME);
    indexType = faunusConf.get(TitanHadoopConfiguration.INDEX_TYPE);

    try {
        Preconditions.checkNotNull(indexName, "Need to provide at least an index name for re-index job");
        log.info("Read index information: name={} type={}", indexName, indexType);
        graph = (StandardTitanGraph)TitanFactory.open(titanConf);
        SchemaContainer schema = new SchemaContainer(graph);
        FaunusSchemaManager typeManager = FaunusSchemaManager.getTypeManager(titanConf);
        typeManager.setSchemaProvider(schema);
        log.info("Opened graph {}", graph);
        mgmt = (ManagementSystem) graph.getManagementSystem();
        validateIndexStatus();
    } catch (final Exception e) {
        if (null != mgmt && mgmt.isOpen())
            mgmt.rollback();
        DEFAULT_COMPAT.incrementContextCounter(context, Counters.FAILED_TRANSACTIONS, 1L);
        throw new IOException(e.getMessage(), e);
    }
}
 
Example 22
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 23
Project: titan-web-example   File: PopulateDB.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Configuration conf = new PropertiesConfiguration(TitanGraphFactory.PROPS_PATH);

    TitanGraph g = TitanFactory.open(conf);

    // Uncomment the following if your graph is already populated and you want to clear it out first.
    // g.close();
    // TitanCleanup.clear(g);
    // g = TitanFactory.open(conf);

    // Interested in the source?
    // https://github.com/thinkaurelius/titan/blob/titan05/titan-core/src/main/java/com/thinkaurelius/titan/example/GraphOfTheGodsFactory.java
    GraphOfTheGodsFactory.load(g);
    g.close();
    System.out.println("Success.");
}
 
Example 24
Project: extended-objects-titan   File: TitanCassandraStore.java   View source code 6 votes vote down vote up
@Override
   public void init(Map<Class<?>, TypeMetadata> registeredMetadata) {
logger.info("Initializing eXtended Objects for Titan on Cassandra...");
Configuration configuration = new BaseConfiguration();
configuration.setProperty("storage.backend", "cassandra");
configuration.setProperty("storage.hostname", host);
if (port > 0) {
    configuration.setProperty("storage.port", port);
}
if (keyspace != null) {
    configuration.setProperty("storage.cassandra.keyspace", keyspace);
}
titanGraph = TitanFactory.open(configuration);
try {
    checkAndInitializeDiscriminatorProperties(registeredMetadata);
    checkAndInitializePropertyIndizes(registeredMetadata);
} finally {
    titanGraph.commit();
}
   }
 
Example 25
Project: antiquity   File: TitanTxLongVersionedGraphTest.java   View source code 6 votes vote down vote up
@Override
protected ActiveVersionedGraph<?, Long> generateGraph() {
    File f = new File("/tmp/testgraph");
    if (f.exists()) {
        if (f.isDirectory()) {
            try {
                FileUtils.deleteDirectory(f);
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        } else {
            f.delete();
        }

    }

    Configuration c = new BaseConfiguration();
    c.addProperty("storage.directory","/tmp/testgraph");
    TitanGraph g = TitanFactory.open(c);

    return new ActiveVersionedGraph.ActiveVersionedTransactionalGraphBuilder<TitanGraph, Long>(g, new LongGraphIdentifierBehavior())
            .init(true).conf(null).build();
}
 
Example 26
Project: keti   File: GraphSubjectRepositoryTest.java   View source code 5 votes vote down vote up
@BeforeClass
public void setup() throws Exception {
    this.subjectRepository = new GraphSubjectRepository();
    Graph graph = TitanFactory.build().set("storage.backend", "inmemory").open();
    GraphConfig.createSchemaElements(graph);
    this.graphTraversalSource = graph.traversal();
    this.subjectRepository.setGraphTraversal(this.graphTraversalSource);
}
 
Example 27
Project: marauder   File: MarauderTitanSink.java   View source code 5 votes vote down vote up
@Override
	public void configure(Context context) {
		Configuration conf = new BaseConfiguration();
		conf.setProperty("storage.backend","hbase");
		conf.setProperty("storage.hostname",
		context.getString("servers", "192.168.1.20"));
//		conf.setProperty("storage.index.t.backend", "lucene");
//		conf.setProperty("storage.index.t.directory", "/tmp/index");
		conf.setProperty("storage.batch-loading", "true");
		batchSize = context.getInteger("batchSize", 1000);
		g = TitanFactory.open(conf);
		g.makeKey("t").dataType(String.class).indexed(Vertex.class).make();
		g.makeKey("o").dataType(Integer.class).indexed(Vertex.class).make();
		g.makeKey("s").dataType(Long.class).indexed(Vertex.class).make();
		g.makeKey("n").dataType(String.class).indexed(Vertex.class).make();
		g.makeLabel("dil").unidirected().manyToMany().make();
		g.makeLabel("sil").unidirected().manyToMany().make();
		g.makeLabel("dpl").unidirected().manyToMany().make();
		g.makeLabel("spl").unidirected().manyToMany().make();
		g.makeLabel("isl").unidirected().manyToMany().make();
		g.makeLabel("hl").unidirected().manyToMany().make();
		g.makeLabel("evl").unidirected().manyToMany().make();
		g.makeLabel("il").unidirected().manyToMany().make();
		g.makeLabel("tl").unidirected().manyToMany().make();
		g.makeLabel("gil").unidirected().manyToMany().make();
		g.commit();
	}
 
Example 28
Project: titan1withtp3.1   File: AbstractTitanGraphProvider.java   View source code 5 votes vote down vote up
@Override
public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test, String testMethodName, final LoadGraphWith.GraphData loadGraphWith) {
    ModifiableConfiguration conf = getTitanConfiguration(graphName, test, testMethodName);
    conf.set(GraphDatabaseConfiguration.COMPUTER_RESULT_MODE, "persist");
    conf.set(GraphDatabaseConfiguration.AUTO_TYPE, "tp3");
    Map<String, Object> result = new HashMap<>();
    conf.getAll().entrySet().stream().forEach(e -> result.put(ConfigElement.getPath(e.getKey().element, e.getKey().umbrellaElements), e.getValue()));
    result.put(Graph.GRAPH, TitanFactory.class.getName());
    return result;
}
 
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: titan1withtp3.1   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 33
Project: ldbc-snb-impls   File: TitanDbConnectionState.java   View source code 5 votes vote down vote up
public TitanDbConnectionState(Map<String, String> props) {
  BaseConfiguration config = new BaseConfiguration();
  config.setDelimiterParsingDisabled(true);

  /*
   * Extract parameters from properties map.
   */
  String cassandraLocator;
  if (props.containsKey("cassandraLocator")) {
    cassandraLocator = props.get("cassandraLocator");
  } else {
    cassandraLocator = "127.0.0.1";
  }

  String graphName;
  if (props.containsKey("graphName")) {
    graphName = props.get("graphName");
  } else {
    graphName = "default";
  }
  
  config.setProperty("storage.backend", "cassandra");
  config.setProperty("storage.hostname", cassandraLocator);
  config.setProperty("storage.cassandra.keyspace", graphName);

  client = TitanFactory.open(config);
}
 
Example 34
Project: simmo-stream-manager   File: TitanGraphDbStorage.java   View source code 5 votes vote down vote up
@Override
public boolean open() {
	BaseConfiguration conf = new BaseConfiguration();
	conf.setProperty("storage.backend", storageBackend);
	conf.setProperty("storage.tablename", storageTableName);
	titanGraph = TitanFactory.open(conf);
	titanGraph.makeKey(vertexUserId).dataType(String.class).indexed(Vertex.class).make();
	titanGraph.makeLabel(edgeMentions).make();
	titanGraph.makeLabel(edgeReTweets).make();
	titanGraph.commit();
	return true;
}
 
Example 35
Project: titan1.0.1.kafka   File: AbstractTitanGraphProvider.java   View source code 5 votes vote down vote up
@Override
public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test, String testMethodName, final LoadGraphWith.GraphData loadGraphWith) {
    ModifiableConfiguration conf = getTitanConfiguration(graphName, test, testMethodName);
    conf.set(GraphDatabaseConfiguration.COMPUTER_RESULT_MODE, "persist");
    conf.set(GraphDatabaseConfiguration.AUTO_TYPE, "tp3");
    Map<String, Object> result = new HashMap<>();
    conf.getAll().entrySet().stream().forEach(e -> result.put(ConfigElement.getPath(e.getKey().element, e.getKey().umbrellaElements), e.getValue()));
    result.put(Graph.GRAPH, TitanFactory.class.getName());
    return result;
}
 
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: 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 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: titan0.5.4-hbase1.1.1-custom   File: VertexIDAssignerTest.java   View source code 5 votes vote down vote up
private static TitanGraph getInMemoryGraph() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, InMemoryStoreManager.class.getCanonicalName());
    config.set(GraphDatabaseConfiguration.IDS_FLUSH, false);
    config.set(GraphDatabaseConfiguration.IDAUTHORITY_WAIT, new StandardDuration(1L, TimeUnit.MILLISECONDS));
    return TitanFactory.open(config);
}