1

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!

liv2hak
  • 14,472
  • 53
  • 157
  • 270
  • 3
    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 Jul 16 '14 at 14:01
  • 1
    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 Jul 17 '14 at 10:40

1 Answers1

1

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.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • My final aim is to be able to use the script from my python code as given http://bulbflow.com/api/bulbs/gremlin/. Will that work now? – liv2hak Jul 17 '14 at 03:30
  • This doesn't work for me.For me it says rexster[groovy]> ?e sum.groovy could not read the file specified – liv2hak Jul 17 '14 at 07:06
  • I have kept sum.groovy in the current working directory."still saying could not read file specified" – liv2hak Jul 17 '14 at 07:15
  • 1
    Your "final aim" was not clear in your question. Your question was about rexster-console so I answered that way. With respect to that question and it still not working for you, I'm not sure what could be wrong except that the file is not where it is expected. You say `sum.groovy` is in the current working directory, but where is that? It should be in the root of the rexster-console distribution...is that where is its? If it's there and that's still a problem, why not try to use an explicit absolute path? – stephen mallette Jul 17 '14 at 10:38