dynamodb-janusgraph-storage-backend connect remotely from Java

401 views Asked by At

I have dynamodb-janusgraph-storage-backend deployed on AWS and I am trying to figure out how to connect to the gremlin server from Java. I have sbt dependency of dynamodb-janusgraph-storage-backend in my project but I don't want to use the gremlin server running as part of my java application. I need it to run independently and connect java application to that.

I looked into multiple options like using Cluster (gremlin-java) and withRemote (gremlin-driver) but both have limitations. I would like to use the Java Gremlin API which I can't if I use Cluster. Using the withRemote method, I cannot figure out how to initialize the graph instance.

The examples on gremlin docs shows EmptyGraph.instance() which I cannot use if I want to use JanusGraph API. I need this part to work with Janusgraph:

Cluster cluster = Cluster.open("conf/remote-objects.yaml"); // this has hosts and ports to gremlin server running in AWS
graph = EmptyGraph.instance();
graph.traversal().withRemote(DriverRemoteConnection.using(cluster))

I need the graph object to be JanusGraph type so I can use openManagement() and other methods. Also, using the high-level Graph type, I cannot add new vertexes. I need to be able to do create, get, update from my java code.

1

There are 1 answers

4
Jason Plurad On BEST ANSWER

Currently it is not possible to invoke the JanusGraph Schema APIs via the remote driver. If you don't want to open up a JanusGraph instance from your application, you'd have to build the schema as a String and use Client submit to send it to the Gremlin Server. You can still use the traversal source with remote driver to build and query the graph.

Cluster cluster = Cluster.open("conf/remote-objects.yaml");

// use client to create the schema
Client client = cluster.connect();
String schema = "mgmt=graph.openManagement();";
schema += "mgmt.makeVertexLabel(\"person\").make();";
schema += "mgmt.makeVertexLabel(\"person\");";
schema + "mgmt.makePropertyKey(\"name\").dataType(String.class).make();"
schema += "mgmt.commit(); true";
CompletableFuture<List<Result>> results = client.submit(schema).all();

// use traversals only to interact with the graph
Graph graph = EmptyGraph.instance();
GraphTraversalSource g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster));
Vertex v = g.addV("person").property("name", "pepe").next();
List<Vertex> vlist = g.V().toList();