Tinkerpop3 connect to remote TitanDB server
Asked Answered
R

1

7

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.

Room answered 3/8, 2016 at 15:0 Comment(1)
C
7

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.

Charo answered 3/8, 2016 at 15:20 Comment(7)
It uses plain Gremlin - "g.V().hasLabel('software').has('name',n).in('created').values('name')". I would like to communicate with server without queries as strings, something closer to JPA.Room
Yep, it helps a little, as I am finally sure, that TitanFactory.open() does not start server (documentation is unclear, at least for me). However, I do not know what should write as value for storage.backend - simple "titan" and "titandb" does not work.Room
What backend are you trying to use? Possible values with Titan 1.0 out-of-the-box are: cassandra or cassandrathrift, hbase, berkeleyje. If you want to use DynamoDB, it looks like it is com.amazon.titan.diskstorage.dynamodb.DynamoDBStoreManager. I'd suggest you review the Titan storage backend documentation. Lots of this is covered there. s3.thinkaurelius.com/docs/titan/1.0.0/storage-backends.htmlCharo
Well yes, finally backend will be DynamoDB, however why would client have to know it? Shouldn't client just know, that he connects to TitanDB? Anyway, adding it as DynamoDB gives me same warnings and execution hold as im my edit in my question #38592553 so basically reduced merged two problems into one :)Room
@JasonPlurad What are the advantages of using Titan server? Isn't it always more convenient to just use the Java API assuming that I want to access the graph from Java?Margaretmargareta
Benefits: see the 5 bullets here tinkerpop.apache.org/docs/current/reference/#gremlin-server -- but yes, using the Java API to connect directly to a TitanGraph is suitable for many tasks without running a server.Charo
Can we run ServiceTest on remote gremlin server? I pointed host: 192.168.1.65 in gremlin-server.yaml and driver-settings.yaml, but statements after this.server = new GremlinServer(Settings.read(stream)); doesn't execute. INFO org.apache.zookeeper.ClientCnxn - Session establishment complete on server 192.168.1.65/192.168.1.65:2181, sessionid = 0x15cafd4cee75c81, negotiated timeout = 90000. I am running titan with hbase as storage backend.Solo

© 2022 - 2024 — McMap. All rights reserved.