Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tinkerpop3 connect to remote TitanDB server

I am trying to obtain Graph object using Tinkerpop3 in Java as client from already running TitanDB server (I do not want to create server).

In other words, I am trying to implement such function:

public Graph obtainGraph(String serverIp, String graphName);

I was trying to do it like here: AWS Lambda + Tinkerpop/Gremlin + TitanDB on EC2 + AWS DynamoDB in cloud

but as I understand, TitanFactory.open() starts server, and I do not want to do this - I just want to connect to existing server.

Documentation as well as most materials in Internet use in-memory graphs for examples, and I cannot find one, that shows how to:

  • create new graph and save it on remote server

  • retrieve existing graph from remote server

  • update such remote Graph, so after adding/removing edges committing changes

  • delete whole graph

I do not want to do above stuff through Gremlin language (Strings), but through Java API (TinkerpopBlueprins). This guy is getting close to what I need: Add vertices to TitanDB Graph in Java however, his method already takes Graph as argument.

I have seen in many places in Internet, that GraphFactory.open() gets path to properties file, however I haven't seen example of content of such file, especially with TitanDB relevant data, so I would prefer to use Configuration object.

Graph graph = GraphFactory.open(new BaseConfiguration())

says, that there is no gremlin.graph property.

Configuration configuration = new BaseConfiguration();
configuration.setProperty("gremlin.graph", "titan");

Graph graph = GraphFactory.open(configuration);

says GraphFactory could not find [titan] - Ensure that the jar is in the classpath

Is there any statically typed builder with enums and constants, instead of Map<String, Object>, that will tell me, what properties I have to provide and what is their type? Is there any open source project, that uses Tinkerpop3 to connect as client to remote TitanDB server, that I could use as example?

I would like to see fully working example, instead of in-memory with external configuration.

like image 635
spam Avatar asked Aug 03 '16 15:08

spam


1 Answers

Here is an example of a Titan driver program that connects to a running Titan Server. https://github.com/pluradj/titan-tp3-driver-example As you have noted, this will pass Gremlin as a string to the remote Titan Server.

If you don't want to do this because you want to use the Java API directly, you should use TitanFactory.open() to make a direct connection to your graph. TitanFactory.open() creates a TitanGraph instance that you can execute your graph API calls against. It does not start a Titan Server. Under the covers, it creates client connections to the backend storage and index.

You can refer to this example for a Titan Java program without Titan Server https://github.com/pluradj/titan-tp3-java-example

You can configure this using a properties file (here is an example configuration using Cassandra and Elasticsearch) or by constructing a Configuration object through code (basically setting the same key-value pairs that are in the properties file).

  • If the graph does not exist before your initial connection, Titan will create the graph keyspace in Cassandra and index in Elasticsearch.

  • Make note of the storage.hostname and index.search.hostname as these are your Cassandra and Elasticsearch clusters respectively. These are essentially your "graph server". You don't need a separate Titan Server running.

  • Titan does not have any APIs to delete the graph from the backend storage. To delete the whole graph, you would need to connect to Cassandra through a Java client driver, and execute the API to drop the keyspace. Similarly, you would need to connect to Elasticsearch through its Indices API, and delete the index.

like image 99
Jason Plurad Avatar answered Oct 18 '22 07:10

Jason Plurad