1
votes

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!

1
It is not clear what you want to do. Your code is Python syntax, but uses methods defined in Groovy (retain, hasNext) and you want to run it in rexster console which understands Groovy, not Python. Note, that bulbs implements a small subset of methods (inV, outV, ...) natively in Python, but even if you use bulbs you have to write the larger scripts in proper Groovy.Tohotom
The above is good advice from @Tohotom, but I still like this question and approach. This is a smaller step on the way to something slightly more complicated. Get this to work, then worry about how to do things with Bulbs.stephen mallette

1 Answers

1
votes

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.