【发布时间】:2014-09-10 04:41:26
【问题描述】:
我正在使用 TitanGraphDB + Cassandra。我按如下方式启动Titan
cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
我有一个 Rexster shell,可以用来与上面的 Titan + Cassandra 通信。
cd rexster-console-2.3.0
bin/rexster-console.sh
我正在尝试使用 Titan Graph DB 对网络拓扑进行建模。我想从我的 python 程序中对 Titan Graph DB 进行编程。我为此使用灯泡包。 我创建了五种类型的顶点
- switch
- port
- device
- flow
- flow_entry
我在逻辑连接的顶点之间创建边。边缘没有标记。
假设我想测试Vertex A和Vertex B之间的连通性
我有一个 groovy 脚本 is_connected.groovy
def isConnected (portA, portB) {
return portA.both().retain([portB]).hasNext()
}
现在从我的 rexster 控制台
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]
正如您在上面看到的,我有两个流类型的顶点v[116] 和v[100]
我有两个类型为 flow_entry v[120] 和 v[104] 的顶点
我想检查v[120] 和v[116] 之间的连通性,例如
rexster[groovy]> ?e is_connected.groovy
==>null
rexster[groovy]> is_connected(g.v(116),g.v(120))
==>true
到目前为止一切顺利。现在我希望能够从我的导入灯泡包的 python 程序中使用这个脚本。
我的目录结构如下。
Projects/ryu
--> ryu/app_simple_switch.py
Projects/ryu_extras
--> rexster-console-2.3.0
--> titan-cassandra-0.3.1
我的脚本 is_connected.groovy 包含 isConnected() 函数/程序保存在Projects/ryu_extras/rexster-console-2.3.0
现在,我在Projects/ryu/ryu/app/simple_switch.py 中的python 程序中尝试执行以下操作。
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)
我收到以下错误。
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
如您所见,错误在 scripts.update() 函数中。我似乎无法弄清楚我做错了什么。任何帮助将不胜感激。
【问题讨论】:
标签: groovy titan bulbs rexster