从使用灯泡的python程序调用gremlin脚本 [英] Calling a gremlin script from python program that uses Bulbs

查看:595
本文介绍了从使用灯泡的python程序调用gremlin脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是TitanGraphDB + Cassandra.I am starting Titan如下

  cd titan-cassandra-0.3.1 
bin / titan.sh config / titan-server-rexster.xml config / titan-server-cassandra.properties


$ b b

我有一个Rexster外壳,我可以用来与上面的Titan + Cassandra通信。

  cd rexster-console- 2.3.0 
bin / rexster-console.sh

拓扑使用Titan图DB。我想编程的Titan图DB从我的python程序。我使用灯泡包。
我创建了三种类型的顶点

   -  switch 
- port
- device

我在物理连接的端口之间创建标签边。我使用的标签是链接。<让我们说我有两个端口顶点 portA portB



我想检查 portA 是否连接到 portB 从我的 python程序使用灯泡包。



作为第一步。我写一个脚本文件 is_connected.sh

  def is_connected(portA,portB) :
return portA.both(link)。retain([portB])。hasNext()


$ b b

如果我尝试从我的rexster-console执行上面的脚本,我得到以下结果。

  sudo ./start_rexter.sh 
(l_(l
(_______(0-
((-Y-)< woof>
l l ----- ll
ll ,, ll ,,
打开会话[127.0.0.1:8184]
?h帮助

rexster [groovy]> ?e
指定文件为executerexster [groovy]> is_connected.sh
==>处理语言[groovy]的脚本时出错。会话中所有图形的所有事务都以失败结束:java.util.concurrent.ExecutionException:javax.script.ScriptException:javax.script.ScriptException:groovy.lang.MissingPropertyException:没有这样的属性:is_connected for class:Script2

这是我第一次尝试写一个存储过程(又名gremlin脚本)。我不知道如果这是正确的方法来接近它。我的最终目标是能够从我的python程序,使用灯泡调用这个脚本。如果有人可以指向正确的方向,这将是巨大的!

解决方案

?e 命令要求您指定要在同一行执行的文件。我创建了 sum.groovy

  def sum(x,y) {x + y} 

然后从控制台:

  rexster [groovy]> ?e sum.groovy 
==> null
rexster [groovy]> sum(1,2)
==> 3

$ c>?e 没有文件不做正确的换行。我会尽力解决这个问题。


I am using TitanGraphDB + Cassandra.I am 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 am attempting to model a network topology using Titan Graph DB.I want to program the Titan Graph DB from my python program.I am using bulbs package for that. I create three types of vertices

 - switch
 - port 
 - device

I create labelled edges between ports that are connected physically.The label that I use is "link".

Let us say I have two port vertices portA and portB.

I want to check if portA is connected to portB from my python program using bulbs package.

As a first step.I write a script (saved in a file is_connected.sh)

def is_connected(portA, portB):
    return portA.both("link").retain([portB]).hasNext()

If I try to execute the above script from my rexster-console as follows,I get the following result.

sudo ./start_rexter.sh 
        (l_(l
(_______( 0 0
(        (-Y-) <woof>
l l-----l l
l l,,   l l,,
opening session [127.0.0.1:8184]
?h for help

rexster[groovy]> ?e
specify the file to executerexster[groovy]> is_connected.sh
==>An error occurred while processing the script for language [groovy]. All transactions across all graphs in the session have been concluded with failure: java.util.concurrent.ExecutionException: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: is_connected for class: Script2

This is my very first attempt at writing a stored procedure (a.k.a gremlin script).I don't know if this is the right way to approach it.Also my final aim would be to be able to call this script from my python program that uses bulbs.If someone could point me in the right direction that would be great!

解决方案

The ?e command requires that you specify the file to execute in the same line. I created sum.groovy:

def sum(x,y) { x+y }

then from the console:

rexster[groovy]> ?e sum.groovy
==>null
rexster[groovy]> sum(1,2)
==>3

Strange that specifying ?e without the file doesn't do a proper line feed. I'll try to go fix that.

这篇关于从使用灯泡的python程序调用gremlin脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆