I'm using TitanGraphDB + Cassandra. I'm starting Titan as follows
cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
I have a Rexster shell that I can use to communicate to Titan + Cassandra above.
cd rexster-console-2.3.0
bin/rexster-console.sh
I'm attempting to model a network topology using Titan Graph DB. I want to program the Titan Graph DB from my python program. I'm using bulbs package for that. I create five types of vertices
- switch
- port
- device
- flow
- flow_entry
I create edges between vertices that are connected logically. The edges are not labelled.
Let us say I want to test the connectivity between Vertex A
and Vertex B
I have a groovy script is_connected.groovy
def isConnected (portA, portB) {
return portA.both().retain([portB]).hasNext()
}
Now from my rexster console
g = rexster.getGraph("graph")
==>titangraph[embeddedcassandra:null]
rexster[groovy]> g.V('type', 'flow')
==>v[116]
==>v[100]
rexster[groovy]> g.V('type', 'flow_entry')
==>v[120]
==>v[104]
As you can see above I have two vertices of type flow v[116]
and v[100]
I have two vertices of type flow_entry
v[120]
and v[104]
I want to check for the connectivity between v[120]
and v[116]
for e.g
rexster[groovy]> ?e is_connected.groovy
==>null
rexster[groovy]> is_connected(g.v(116),g.v(120))
==>true
So far so good.Now I want to be able to use this script from my python program that imports bulbs package.
My directory structure is as follows.
Projects/ryu
--> ryu/app_simple_switch.py
Projects/ryu_extras
--> rexster-console-2.3.0
--> titan-cassandra-0.3.1
My script is_connected.groovy which contains isConnected() function/procedure is kept in Projects/ryu_extras/rexster-console-2.3.0
Now from my python program which is in Projects/ryu/ryu/app/simple_switch.py
I try to do the following.
self.g.scripts.update('Projects/ryu_extras/rexster-console-2.3.0/is_connected.groovy') # add file to scripts index
script = self.g.scripts.get('isConnected') # get a function by its name
params = dict(portA=flow,portB=fe1) # put function params in dict
items = self.g.gremlin.query(script, params)
self.create_outgoing_edge(flow,fe1)
self.create_outgoing_edge(fe1,sw_vertex)
I get the following error.
hub: uncaught exception: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/ryu/lib/hub.py", line 48, in _launch
func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/ryu/base/app_manager.py", line 256, in _event_loop
handler(ev)
File "/home/karthik/Projects/ryu/ryu/app/simple_switch.py", line 322, in _packet_in_handler
self.compute_path(src,dst,datapath)
File "/home/karthik/Projects/ryu/ryu/app/simple_switch.py", line 289, in compute_path
self.g.scripts.update('/home/karthik/Projects/ryu_extras/rexster-console-2.3.0/is_connected.groovy') # add file to scripts index
File "/usr/local/lib/python2.7/dist-packages/bulbs/groovy.py", line 120, in update
methods = self._get_methods(file_path)
File "/usr/local/lib/python2.7/dist-packages/bulbs/groovy.py", line 160, in _get_methods
return Parser(file_path).get_methods()
File "/usr/local/lib/python2.7/dist-packages/bulbs/groovy.py", line 255, in __init__
Scanner(handlers).scan(groovy_file)
File "/usr/local/lib/python2.7/dist-packages/bulbs/groovy.py", line 246, in scan
self.get_item(fin,line)
File "/usr/local/lib/python2.7/dist-packages/bulbs/groovy.py", line 236, in get_item
content = "\n".join(sections).strip()
TypeError: sequence item 2: expected string or Unicode, NoneType found
As you can see the error is in scripts.update() function.I just can't seem to figure out what I am doing wrong.Any help would be appreciated.