0

I have set up a Janusgraph Cluster with Cassandra + ES. The cluster has been set up to support ConfiguredGraphFactory. Also, I am connecting the gremlin cluster remotely. I have set up a client and am able to create a graph using :

client.submit(String.format("ConfiguredGraphFactory.create(\"%s\")", graphName));

However, I am not able to get the traversalSource of the graph created using the gremlin driver. Do I have to create raw gremlin queries and traverse the graph using client.submit or is there a way to get it through the gremlin driver using Emptygraph.Instance().

AKG
  • 598
  • 6
  • 18

1 Answers1

3

To get the remote traversal reference, you need to pass in a variable name that is bound to your graph traversal. This binding is usually done as part of the "globals" in your startup script when you start the remote server (the start up script is configured to run as part of the gremlin-server.yaml).

There is currently no inherent way to dynamically bind a variable to a graph or traversal reference, but I plan on fixing this at some point.

A short term fix is to bind your graph and traversal references to a method that will be variably defined, and then create some mechanism to change the variable dynamically.

To further explain a potential solution:

  1. Update your server's startup script to bind g to something variable:

    globals << [g : DynamicBindingTool.getBoundGraphTraversal()]
    
  2. Create DynamicBindingTool, which has to do two things:

    A. Provide a way to setBoundGraph() which may look something like:

    setBoundGraph(graphName) {
        this.boundGraph = ConfiguredGraphFactory.open(graphName);
    }
    

    B. Provide a way to getBoundGraphTraversal() which may look something like:

    getBoundGraphTraversal() {
        this.boundGraph.traversal();
    }
    

You can include these sorts of functions in your start-up script or perhaps even create a separate jar that you attach to your Gremlin Server.

Finally, I would like to note that the proposed example solution does not take into account a multi-node JanusGraph cluster, i.e. your notion of the current bound graph would not be shared across the JG nodes. To make this a multi-node solution, you can update the functions to define the bound graph on an external database or even piggybacked on a JanusGraph graph.

For example, something like this would be a multi-node safe implementation:

setBoundGraph(graphName) {
    def managementGraph = ConfiguredGraphFactory.open("managementGraph");
    managementGraph.traversal().V().has("boundGraph", true).remove();
    def v = managementGraph.addVertex();
    v.property("boundGraph", true);
    v.property("graph.graphname", graphName);
}

and:

getBoundGraphTraversal() {
    def managementGraph = ConfiguredGraphFactory.open("managementGraph");
    def graphName = managementGraph.traversal().V().has("boundGraph", true).values("graph.graphname");
    return ConfiguredGraphFactory.open(graphName).traversal();
}

EDIT:

Unfortunately, the above "short-term trick" will not work as the global bindings are evaluated once and stored in a Map for the duration of the sever life cycle. Please see here for more information and updates on fixes: https://issues.apache.org/jira/browse/TINKERPOP-1839.

David
  • 486
  • 2
  • 9
  • Hi David - Thanks for your quick reply. However, I didn't quite understand your note well. I am not sure what you mean by "notion of the current bound graph would not be shared across the JG nodes". 1. Does that mean that If I am writing to the same graph from different nodes I might run into issues? 2. Also, for binding the graph to a janusgraph do I modify the method to create a graph using Janusgraphfactory by using the template/graph information stored in ConfiguredGraphFactory. – AKG Nov 17 '17 at 17:01
  • > 1. Does that mean that If I am writing to the same graph from different nodes I might run into issues? No; it means, if your solution went the route above in the provided example and `getBoundGraphTraversal()` returned a traversal object saved on the current JVM and _not_ a traversal object saved and accessed by all JG nodes in your cluster, then this function can return a different bound graph on each Gremlin Server. Updating the answer above with something that might be multi-node safe. – David Nov 17 '17 at 17:15
  • My edit above should have also answered your number (2). – David Nov 17 '17 at 17:36
  • Here is how my groovy script looks now : http://gist.github.com/aaur0/c7f50f02b43a40809eac617c96dd74e9 Gremlin server is throwing error : " Could not initialize gremlin-groovy ScriptEngine with scripts/empty-sample.groovy as script could not be evaluated - javax.script.ScriptException: java.lang.IllegalStateException: Please create configuration for this graph using the ConfigurationManagementGraph#createConfiguration API." Any idea what's going on here? It seems I will have to initialize a graph but I am not sure how. – AKG Nov 17 '17 at 20:46
  • You are trying to open a graph using the ConfiguredGraphFactory for which no graph configuration has been created. If you are using a TemplateConfiguration, then you must call `ConfiguredGraphFactory.create(..)` the first time you access the graph and `open()` every time there after http://docs.janusgraph.org/latest/configuredgraphfactory.html. – David Nov 17 '17 at 23:29
  • Yes. I figured that out and added code creating configuration. But, I am still getting the same error message. One interesting thing to note here is the error message says to use "ConfigurationManagementGraph#createConfiguration" to create the template instead of ConfiguredGraphFactory.createTemplateConfiguration. Updated gist : https://gist.github.com/aaur0/c7f50f02b43a40809eac617c96dd74e9 – AKG Nov 18 '17 at 00:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159268/discussion-between-anand-gupta-and-david). – AKG Nov 18 '17 at 00:18
  • I have lost access to the chat room. I am not sure if you posted anything new in there. Also, I didn't see any activity on the Tinkerpop board ticket lately. Any suggestion how to take this ahead? – AKG Dec 05 '17 at 22:57
  • Conversation has been moved to this [JG-users thread](https://groups.google.com/forum/#!topic/janusgraph-users/-E7VfEG-cd0) – David Dec 06 '17 at 15:03