Java Code Examples for com.thinkaurelius.titan.core.TitanFactory#open()

The following examples show how to use com.thinkaurelius.titan.core.TitanFactory#open() . 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: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 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 2
Source File: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 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 3
Source File: CassandraGraphTest.java    From titan1withtp3.1 with Apache License 2.0 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 4
Source File: MizoRDD.java    From mizo with Apache License 2.0 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 5
Source File: TitanTxLongVersionedGraphTest.java    From antiquity with GNU General Public License v3.0 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 6
Source File: PopulateDB.java    From titan-web-example with Apache License 2.0 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 7
Source File: Titan0GraphDatabase.java    From incubator-atlas with Apache License 2.0 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 8
Source File: Titan1GraphDatabase.java    From incubator-atlas with Apache License 2.0 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 9
Source File: ThriftGraphSpeedTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
protected StandardTitanGraph getGraph() throws BackendException {


    if (null == graph) {
        GraphDatabaseConfiguration graphconfig = new GraphDatabaseConfiguration(conf);
        graphconfig.getBackend().clearStorage();
        log.debug("Cleared backend storage");
        graph = (StandardTitanGraph)TitanFactory.open(conf);
        initializeGraph(graph);
    }
    return graph;
}
 
Example 10
Source File: VertexIDAssignerTest.java    From titan1withtp3.1 with Apache License 2.0 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 11
Source File: TitanGraphFactory.java    From titan-web-example with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    try {
        logger.info("Titan Properties Path: {}", PROPS_PATH);
        Configuration conf = new PropertiesConfiguration(PROPS_PATH);
        g = TitanFactory.open(conf);
        logger.info("Titan graph loaded successfully.");
    } catch (ConfigurationException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 12
Source File: HadoopVertexScanMapper.java    From titan1withtp3.1 with Apache License 2.0 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 13
Source File: TitanGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 4 votes vote down vote up
private static final TitanGraph buildTitanGraph(GraphDatabaseType type, File dbPath, BenchmarkConfiguration bench,
    boolean batchLoading)
{
    final Configuration conf = generateBaseTitanConfiguration(type, dbPath, batchLoading, bench);
    final Configuration storage = conf.subset(GraphDatabaseConfiguration.STORAGE_NS.getName());

    if (GraphDatabaseType.TITAN_CASSANDRA == type)
    {
        storage.addProperty("hostname", "localhost");
        storage.addProperty("transactions", Boolean.toString(batchLoading));
    }
    else if (GraphDatabaseType.TITAN_CASSANDRA_EMBEDDED == type)
    {
        // TODO(amcp) - this line seems broken:
        // throws: Unknown configuration element in namespace
        // [root.storage]: cassandra-config-dir
        storage.addProperty("cassandra-config-dir", "configuration/cassandra.yaml");
        storage.addProperty("transactions", Boolean.toString(batchLoading));
    }
    else if (GraphDatabaseType.TITAN_DYNAMODB == type)
    {
        final Configuration dynamodb = storage.subset("dynamodb");
        final Configuration client = dynamodb.subset(Constants.DYNAMODB_CLIENT_NAMESPACE.getName());
        final Configuration credentials = client.subset(Constants.DYNAMODB_CLIENT_CREDENTIALS_NAMESPACE.getName());
        storage.addProperty("transactions", Boolean.toString(batchLoading));
        if (bench.getDynamodbDataModel() == null)
        {
            throw new IllegalArgumentException("data model must be set for dynamodb benchmarking");
        }
        if (GraphDatabaseType.TITAN_DYNAMODB == type && bench.getDynamodbEndpoint() != null
            && !bench.getDynamodbEndpoint().isEmpty())
        {
            client.addProperty(Constants.DYNAMODB_CLIENT_ENDPOINT.getName(), bench.getDynamodbEndpoint());
            client.addProperty(Constants.DYNAMODB_CLIENT_MAX_CONN.getName(), bench.getDynamodbWorkerThreads());
        } else {
            throw new IllegalArgumentException("require endpoint");
        }

        if (bench.getDynamodbCredentialsFqClassName() != null
            && !bench.getDynamodbCredentialsFqClassName().isEmpty())
        {
            credentials.addProperty(Constants.DYNAMODB_CREDENTIALS_CLASS_NAME.getName(), bench.getDynamodbCredentialsFqClassName());
        }

        if (bench.getDynamodbCredentialsCtorArguments() != null)
        {
            credentials.addProperty(Constants.DYNAMODB_CREDENTIALS_CONSTRUCTOR_ARGS.getName(),
                bench.getDynamodbCredentialsCtorArguments());
        }

        dynamodb.addProperty(Constants.DYNAMODB_FORCE_CONSISTENT_READ.getName(), bench.dynamodbConsistentRead());
        Configuration executor = client.subset(Constants.DYNAMODB_CLIENT_EXECUTOR_NAMESPACE.getName());
        executor.addProperty(Constants.DYNAMODB_CLIENT_EXECUTOR_CORE_POOL_SIZE.getName(), bench.getDynamodbWorkerThreads());
        executor.addProperty(Constants.DYNAMODB_CLIENT_EXECUTOR_MAX_POOL_SIZE.getName(), bench.getDynamodbWorkerThreads());
        executor.addProperty(Constants.DYNAMODB_CLIENT_EXECUTOR_KEEP_ALIVE.getName(), TimeUnit.MINUTES.toMillis(1));
        executor.addProperty(Constants.DYNAMODB_CLIENT_EXECUTOR_QUEUE_MAX_LENGTH.getName(), bench.getTitanBufferSize());

        final long writeTps = bench.getDynamodbTps();
        final long readTps = Math.max(1, bench.dynamodbConsistentRead() ? writeTps : writeTps / 2);

        final Configuration stores = dynamodb.subset(Constants.DYNAMODB_STORES_NAMESPACE.getName());
        for (String storeName : Constants.REQUIRED_BACKEND_STORES)
        {
            final Configuration store = stores.subset(storeName);
            store.addProperty(Constants.STORES_DATA_MODEL.getName(), bench.getDynamodbDataModel().name());
            store.addProperty(Constants.STORES_CAPACITY_READ.getName(), readTps);
            store.addProperty(Constants.STORES_CAPACITY_WRITE.getName(), writeTps);
            store.addProperty(Constants.STORES_READ_RATE_LIMIT.getName(), readTps);
            store.addProperty(Constants.STORES_WRITE_RATE_LIMIT.getName(), writeTps);
        }
    }
    return TitanFactory.open(conf);
}
 
Example 14
Source File: VertexJobConverter.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public void initializeGraph(Configuration config) {
    if (!provided) {
        this.graph = (StandardTitanGraph) TitanFactory.open((BasicConfiguration) config);
    }
}
 
Example 15
Source File: TitanHadoopSetupImpl.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public TitanHadoopSetupImpl(final Configuration config) {
    scanConf = ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, config);
    BasicConfiguration bc = scanConf.getTitanGraphConf();
    graph = (StandardTitanGraph) TitanFactory.open(bc);
    tx = (StandardTitanTx)graph.buildTransaction().readOnly().vertexCacheSize(200).start();
}
 
Example 16
Source File: InMemoryConfigurationTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public void initialize(ConfigOption option, Object value) {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(option,value);
    graph = (StandardTitanGraph) TitanFactory.open(config);
}
 
Example 17
Source File: TitanFactoryShorthandTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testTitanFactoryShorthand() {
    TitanGraph g = TitanFactory.open("inmemory");
    g.close();
}
 
Example 18
Source File: VertexListTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Test
public void testLists() {

    int num = 13;

    TitanGraph g = TitanFactory.open("inmemory");
    StandardTitanTx tx = (StandardTitanTx) g.newTransaction();
    VertexLongList vll = new VertexLongList(tx);
    VertexArrayList val = new VertexArrayList(tx);
    for (int i=0; i<num; i++) {
        TitanVertex v = tx.addVertex();
        vll.add(v);
        val.add(v);
    }

    assertEquals(num, Iterables.size(vll));
    assertEquals(num, Iterables.size(val));

    vll.sort();
    val.sort();
    assertTrue(vll.isSorted());
    assertTrue(val.isSorted());

    for (Iterable<TitanVertex> iterable : new Iterable[]{val,vll}) {
        Iterator<TitanVertex> iter = iterable.iterator();
        TitanVertex previous = null;
        for (int i = 0; i < num; i++) {
            TitanVertex next = iter.next();
            if (previous!=null) assertTrue(previous.longId()<next.longId());
            previous = next;
        }
        try {
            iter.next();
            fail();
        } catch (NoSuchElementException ex) {

        }
    }


    tx.commit();
    g.close();

}
 
Example 19
Source File: StorageSetup.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public static TitanGraph getInMemoryGraph() {
    return TitanFactory.open(getInMemoryConfiguration());
}
 
Example 20
Source File: GraphOfTheGodsFactory.java    From titan1withtp3.1 with Apache License 2.0 3 votes vote down vote up
/**
 * Calls {@link TitanFactory#open(String)}, passing the Titan configuration file path
 * which must be the sole element in the {@code args} array, then calls
 * {@link #load(com.thinkaurelius.titan.core.TitanGraph)} on the opened graph,
 * then calls {@link com.thinkaurelius.titan.core.TitanGraph#close()}
 * and returns.
 * <p/>
 * This method may call {@link System#exit(int)} if it encounters an error, such as
 * failure to parse its arguments.  Only use this method when executing main from
 * a command line.  Use one of the other methods on this class ({@link #create(String)}
 * or {@link #load(com.thinkaurelius.titan.core.TitanGraph)}) when calling from
 * an enclosing application.
 *
 * @param args a singleton array containing a path to a Titan config properties file
 */
public static void main(String args[]) {
    if (null == args || 1 != args.length) {
        System.err.println("Usage: GraphOfTheGodsFactory <titan-config-file>");
        System.exit(1);
    }

    TitanGraph g = TitanFactory.open(args[0]);
    load(g);
    g.close();
}