Search code examples
javajanusgraphcompose-db

Connecting to compose Janusgraph from Java for remote traversal


I am trying to connect to a remote compose-janusgraph server to create a graph and add vertices. Note that I don't have access to the server configurations or ability to change server settings.

I am able to do this over my local gremlin console with

:remote connect tinkerpop.server conf/compose.yaml session
:remote console
graph=ConfiguredGraphFactory.create("mygraph")
graph=ConfiguredGraphFactory.open("mygraph")
g.addV("pat")
g.tx().commit()

I want to do the same with a Java client using GraphTraversalSource. From Java, I am able to use Cluser->Client->submit option to submit groovy strings successfully. But I've been unsuccessful with GraphTraversalSource, getting a variety of errors.

The conf/compose.yaml I use to configure gremlin console is as below and is same one I use in remote-graph gremlin.remote.driver.clusterFile config

hosts: [portal-xxx.composedb.com] 
port: 15290 
username: admin 
password: pass 
connectionPool: { enableSsl: true } 
serializer: { className: 
    org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, 
    config: { serializeResultToString: true } }

remote-graph properties looks like

gremlin.remote.remoteConnectionClass=org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection
# cluster file has the remote server configuration
#gremlin.remote.driver.clusterFile=gremlin-console.yaml
gremlin.remote.driver.clusterFile=/Users/julian.stephen/ibm.github/privacy-secbu/Privacy-DataViz/src/main/resources/gremlin-console.yaml
# source name is the global graph traversal source defined on the server
gremlin.remote.driver.sourceName=mygraph

If I try

Graph graph = EmptyGraph.instance();
GraphTraversalSource g = graph.traversal().withRemote(conf);
g.addV("Java Remote Test");
g.close();

Code runs without exceptions but vertex is not created in the graph. I thought it is because the tx() is not committed. So I tried getting a ConfiguredGraphFactory instead of Empty graph, but all the options below are resulting in exceptions.

JanusGraph graph = ConfiguredGraphFactory.open("mygraph");

instead of EmptyGraph results in an error (same as the one described next). When I create a configuration ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));, and then try to open the graph, I am getting an error like Please add a key named "ConfigurationManagementGraph" to the "graphs" property in your YAML file and restart the server to be able to use the functionality of the ConfigurationManagementGraph class. I don't have access to the server as stated first.

I also tried different variations of using JanusGraphFactory to no avail.

Can someone help?


Solution

  • Turned out that this was a misconfiguration of the channelizer setting in the Janusgraph server which was not creating dynamic traversal bindings for new graphs created with GraphConfiguration Factory. Once that was rectified by the server team and deployment updated, the dynamic traversals were getting bound and code started working.