groovycassandragremlintitanbulbs

Bulbs: How to check if two vertices are connected by an edge in Titan


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 write a function as below

def is_connected(portA, portB):
     ...
     ... 
     ...

How do I find if two vertices are "connected by a labelled edge"?

I have two graph vertices

src_sw_other_ports
<Vertex: http://localhost:8182/graphs/graph/vertices/48>

dst_sw_other_ports
<Vertex: http://localhost:8182/graphs/graph/vertices/72>

I have tried

link_exists = src_sw_other_ports.out.retain([dst_sw_other_ports]).hasNext()

It is giving me the following error.

  File "/home/karthik/Projects/ryu/ryu/app/simple_switch.py", line 238, in compute_path
    link_exists = src_sw_other_ports.out.retain([dst_sw_other_ports]).hasNext()
  File "/usr/local/lib/python2.7/dist-packages/bulbs/element.py", line 209, in __getattr__
    raise AttributeError(name)
AttributeError: out

Solution

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

    See http://gremlindocs.com/#recipes/finding-edges-between-vertices

    NB: I used your function definition in the code above; however, your function definition uses Python syntax, not Groovy, so the above example will only work if you are calling the Gremlin code from Jython.

    The Gremlin-Groovy definition would be:

    def isConnected (portA, portB) {
         return portA.both("link").retain([portB]).hasNext()
    }