How to work with the same graph in Gremlin console as Gremlin-Python

1,084 views
Skip to first unread message

Olav Laudy

unread,
Dec 21, 2017, 3:14:34 PM12/21/17
to Gremlin-users
Hi,


I'd like to create a situation where I'm working both in Python as well as in Gremlin on the same graph. That is: if I add a vertex in Python and I query the graph in the console, it shows the added vertex. 

The reason I want this is
a) I better understand the concept of a TinkerGraph for the lack of clear Python tutorials. 
b) I can connect Gephi to the console and not to Python


I'm working with Gremlin 3.3.1 (both server and gremlin-python).

I verified Python is working by adding some nodes and edges and listing them back.

I created my own graph source name (CL, see for details below):

-created a  .properties file specifying the graph/vertexIdManager/graphLocation/graphFormat
-mapped the .properties file in the server yaml graph section.
-added a traversal source in the .groovy file
-in the console remote-graph.properties set the gremlin.remote.driver.sourceName


In Python this works:
    graph = Graph()
    CL = graph.traversal().withRemote(DriverRemoteConnection('ws://10.0.10.52:8182/gremlin','CL')) 


In the console this works:
graph = TinkerGraph.open()
g = graph.traversal()


YET, when I add a vertex in Python and I connect the console, it still shows me an empty graph.

What am I missing?


On a side note: how do I use the .close() statement in Python to write the graph to the disk?

Thanks!




Details for my own source:

server:

groovy:
    globals << [g : graph.traversal(), CL : CLgraph.traversal() ]

server yaml:
    graphs: {
      graph: gremlin-graph.properties,
      CLgraph: CL-graph.properties}

CL-graph.properties:
    gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
    gremlin.tinkergraph.vertexIdManager=LONG
    gremlin.tinkergraph.graphLocation=/graph_file/CL-graph.gson
    gremlin.tinkergraph.graphFormat=graphson


console:

remote-graph.properties:
    gremlin.remote.driver.sourceName=CLgraph

HadoopMarc

unread,
Dec 22, 2017, 4:14:02 PM12/22/17
to Gremlin-users
Hi Olav,

I do not know whether TinkerGraph allows at all what you try to do. TinkerGraph is not a transactional database, so close() is indeed the only way to persist a TinkerGraph. But it is of course weird to close a graph on a graph serving instance ...

Unless someone comes up with a way to do this with TinkerGraph, you better look at the JanusGraph implementation of TinkerPop, e.g. with the BerkeleyDb backend. Then you can call g.tx.commit() to make changes from one console visible in the other.

Hope this helps,

Marc

Op donderdag 21 december 2017 21:14:34 UTC+1 schreef Olav Laudy:

Robert Dale

unread,
Dec 22, 2017, 4:40:18 PM12/22/17
to gremli...@googlegroups.com
You just need to connect your console to the same remote Gremlin Server as python.  See also http://tinkerpop.apache.org/docs/3.2.7/reference/#connecting-via-console


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/f7864f82-661b-4931-9629-1a4bc4144f5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Robert Dale

Olav Laudy

unread,
Dec 27, 2017, 5:15:44 PM12/27/17
to Gremlin-users
Hi,


I appreciate your response, but this is not the solution.


I issue: :remote connect tinkerpop.server conf/remote.yaml

It correctly connects to the server. 

Then I specify:
CLgraph = TinkerGraph.open()

and it comes back with ==>tinkergraph[vertices:0 edges:0] which is not correct, as my Python graph as filled


Any other ideas?

Robert Dale

unread,
Dec 27, 2017, 5:35:40 PM12/27/17
to gremli...@googlegroups.com
You are creating and referencing a new graph.  Stop doing that.  Just reference the bound graph variables in your server.


Robert Dale

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/38ba92aa-4097-449e-80a6-df0c2b4b1d99%40googlegroups.com.

Olav Laudy

unread,
Dec 27, 2017, 5:43:11 PM12/27/17
to Gremlin-users
Apologies for being such a noob..., but how?

I open the console and then connect to the server with :remote connect tinkerpop.server conf/remote.yaml

I walked through all the files in the conf dir (of the client/console) to ensure I'm referencing the right graph.

After I issue the remote connect, I get an error if I try to query (e.g. g.V() or in my case CL.V() or CL.V().next()



Olav

Robert Dale

Robert Dale

unread,
Dec 28, 2017, 11:44:30 AM12/28/17
to gremli...@googlegroups.com
I don't know where things on your end are not aligned. I was able to successfully connect using the configuration provided. I imagine that the issue is not in the server config since you are connecting to it via python. Configuration and steps provided below.

diff -ruw apache-tinkerpop-gremlin-server-3.2.7/conf/gremlin-server.yaml apache-tinkerpop-gremlin-server-3.2.7-test/conf/gremlin-server.yaml
--- apache-tinkerpop-gremlin-server-3.2.7/conf/gremlin-server.yaml 2017-12-15 07:37:22.000000000 -0500
+++ apache-tinkerpop-gremlin-server-3.2.7-test/conf/gremlin-server.yaml 2017-12-28 11:12:01.546613096 -0500
@@ -20,7 +20,8 @@
 scriptEvaluationTimeout: 30000
 channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer
 graphs: {
-  graph: conf/tinkergraph-empty.properties}
+  graph: conf/tinkergraph-empty.properties,
+  CLgraph: conf/clgraph.properties}
 plugins:
   - tinkerpop.tinkergraph
 scriptEngines: {
diff -ruw apache-tinkerpop-gremlin-server-3.2.7/scripts/empty-sample.groovy apache-tinkerpop-gremlin-server-3.2.7-test/scripts/empty-sample.groovy
--- apache-tinkerpop-gremlin-server-3.2.7/scripts/empty-sample.groovy 2017-02-13 10:24:42.000000000 -0500
+++ apache-tinkerpop-gremlin-server-3.2.7-test/scripts/empty-sample.groovy 2017-12-28 11:20:27.380347558 -0500
@@ -37,4 +37,4 @@
 ] as LifeCycleHook]
 
 // define the default TraversalSource to bind queries to - this one will be named "g".
-globals << [g : graph.traversal()]
+globals << [g : graph.traversal(), CL : CLgraph.traversal()]

I'm using a packaged graphson file.

conf/clgraph.properties:
gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
gremlin.tinkergraph.vertexIdManager=LONG
gremlin.tinkergraph.graphLocation=data/tinkerpop-classic.json
gremlin.tinkergraph.graphFormat=graphson

Assuming you are using the default remote.yaml, no configuration necessary in gremlin-console since you're connecting via remote string and not actually using remote-graph.properties.

conf/remote.yaml:
hosts: [localhost]
port: 8182
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}


I start the server and can see both graphs and traversals are bound. Again, you shouldn't have problem here since you can see them via python.

[...]
[INFO] DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
[INFO] DefaultGraphManager - Graph [CLgraph] was successfully configured via [conf/clgraph.properties].
[...]
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [CL] with graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]


I start gremlin console and can see the CLgraph and CL traversal.

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :> CL.V()
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]
gremlin> :> CLgraph.traversal().V()
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]

Hope you find your problem.



Robert Dale

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/bb6b0531-d17a-406d-825c-c14374d7bb94%40googlegroups.com.

Olav Laudy

unread,
Dec 28, 2017, 11:50:06 AM12/28/17
to Gremlin-users
I got it!


The trick was to ensure I call the graph with >: in front as : only connects locally.




Thanks a lot!
Reply all
Reply to author
Forward
0 new messages