migrate to Titan 0.3.0
diff --git a/src/main/java/net/onrc/onos/util/GraphDBConnection.java b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
index ee50cd0..01b22ae 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
@@ -2,10 +2,18 @@
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.esotericsoftware.minlog.Log;
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.TransactionalGraph.Conclusion;
+import com.tinkerpop.blueprints.util.wrappers.event.EventGraph;
+import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalGraph;
+import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalIndexableGraph;
+import com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener;
import com.tinkerpop.frames.FramedGraph;
public class GraphDBConnection {
@@ -13,9 +21,17 @@
COMMIT,
ROLLBACK
}
+ public enum GenerateEvent {
+ TRUE,
+ FALSE
+ }
+ protected static Logger log = LoggerFactory.getLogger(GraphDBConnection.class);
private static GraphDBConnection singleton = new GraphDBConnection( );
private static TitanGraph graph;
+ private static EventTransactionalGraph<TitanGraph> eg;
private static GraphDBUtils utils;
+ private static String configFile;
+
/* A private Constructor prevents any other
* class from instantiating.
@@ -23,9 +39,14 @@
private GraphDBConnection(){ }
/* Static 'instance' method */
- public static GraphDBConnection getInstance(String conf) {
- if (graph == null||graph.isOpen() == Boolean.FALSE) {
- graph = TitanFactory.open(conf);
+ public static GraphDBConnection getInstance(final String conf) {
+ if (GraphDBConnection.configFile == null || GraphDBConnection.configFile.isEmpty()) {
+ GraphDBConnection.configFile = conf;
+ log.debug("GraphDBConnection::Setting Config File {}", GraphDBConnection.configFile);
+ }
+ if (!GraphDBConnection.configFile.isEmpty() &&
+ (graph == null||graph.isOpen() == Boolean.FALSE)) {
+ graph = TitanFactory.open(GraphDBConnection.configFile);
// FIXME: Creation on Indexes should be done only once
Set<String> s = graph.getIndexedKeys(Vertex.class);
if (!s.contains("dpid")) {
@@ -44,8 +65,9 @@
graph.createKeyIndex("flow_entry_id",
Vertex.class);
}
- }
- graph.stopTransaction(Conclusion.SUCCESS);
+ graph.stopTransaction(Conclusion.SUCCESS);
+ eg = new EventTransactionalGraph<TitanGraph>(graph);
+ }
if (utils == null) {
utils = new GraphDBUtils();
}
@@ -66,6 +88,21 @@
}
}
+ protected EventTransactionalGraph<TitanGraph> getEventGraph() {
+
+ if (isValid()) {
+ return eg;
+ } else {
+ return null;
+ }
+ }
+
+ public void addEventListener(final LocalGraphChangedListener listener) {
+ EventTransactionalGraph<TitanGraph> eg = this.getEventGraph();
+ eg.addListener(listener);
+ log.debug("Registered listener {}",listener.getClass());
+ }
+
public Boolean isValid() {
return (graph != null||graph.isOpen());
@@ -78,14 +115,33 @@
public void endTx(Transaction tx) {
switch (tx) {
case COMMIT:
- graph.stopTransaction(Conclusion.SUCCESS);
+ eg.stopTransaction(Conclusion.SUCCESS);
case ROLLBACK:
- graph.stopTransaction(Conclusion.FAILURE);
+ eg.stopTransaction(Conclusion.FAILURE);
}
}
+ public void endTx(Transaction tx, GenerateEvent fire) {
+
+ try {
+ if (fire.equals(GenerateEvent.TRUE)) {
+ switch (tx) {
+ case COMMIT:
+ eg.stopTransaction(Conclusion.SUCCESS);
+ case ROLLBACK:
+ eg.stopTransaction(Conclusion.FAILURE);
+ }
+ } else {
+ endTx(tx);
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
public void close() {
- graph.stopTransaction(Conclusion.SUCCESS);
+ graph.shutdown();
}
}
diff --git a/src/main/java/net/onrc/onos/util/GraphDBUtils.java b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
index c43434f..a3d106c 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBUtils.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBUtils.java
@@ -15,8 +15,9 @@
import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.wrappers.event.EventGraph;
+import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalGraph;
import com.tinkerpop.frames.FramedGraph;
-import com.tinkerpop.frames.FramedVertexIterable;
+import com.tinkerpop.frames.structures.FramedVertexIterable;
import com.tinkerpop.gremlin.java.GremlinPipeline;
public class GraphDBUtils implements IDBUtils {
@@ -45,16 +46,6 @@
}
@Override
- public ISwitchObject searchActiveSwitch(GraphDBConnection conn, String dpid) {
- ISwitchObject sw = searchSwitch(conn, dpid);
- if ((sw != null) &&
- sw.getState().equals(SwitchState.ACTIVE.toString())) {
- return sw;
- }
- return null;
- }
-
- @Override
public IDeviceObject searchDevice(GraphDBConnection conn, String macAddr) {
// TODO Auto-generated method stub
FramedGraph<TitanGraph> fg = conn.getFramedGraph();
@@ -89,9 +80,9 @@
@Override
public void removePort(GraphDBConnection conn, IPortObject port) {
-// FramedGraph<TitanGraph> fg = conn.getFramedGraph();
- EventGraph<TitanGraph> eg = conn.getEventGraph();
- eg.removeVertex(port.asVertex());
+ FramedGraph<TitanGraph> fg = conn.getFramedGraph();
+// EventGraph<TitanGraph> eg = conn.getEventGraph();
+ fg.removeVertex(port.asVertex());
}
@Override
@@ -213,4 +204,10 @@
}
return inactiveSwitches;
}
+
+ @Override
+ public ISwitchObject searchActiveSwitch(GraphDBConnection conn, String dpid) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
diff --git a/src/main/java/net/onrc/onos/util/LocalGraphChangedListener.java b/src/main/java/net/onrc/onos/util/LocalGraphChangedListener.java
new file mode 100644
index 0000000..ac819f9
--- /dev/null
+++ b/src/main/java/net/onrc/onos/util/LocalGraphChangedListener.java
@@ -0,0 +1,7 @@
+package net.onrc.onos.util;
+
+import com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener;
+
+public interface LocalGraphChangedListener extends GraphChangedListener {
+
+}
diff --git a/src/main/java/net/onrc/onos/util/LocalTopologyEventListener.java b/src/main/java/net/onrc/onos/util/LocalTopologyEventListener.java
index 186ba58..61f227d 100644
--- a/src/main/java/net/onrc/onos/util/LocalTopologyEventListener.java
+++ b/src/main/java/net/onrc/onos/util/LocalTopologyEventListener.java
@@ -1,10 +1,6 @@
package net.onrc.onos.util;
-import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry;
-import net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath;
import net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject;
-import net.floodlightcontroller.linkdiscovery.internal.TopoLinkServiceImpl;
-import net.floodlightcontroller.util.FlowPath;
import net.onrc.onos.flow.FlowManagerImpl;
import net.onrc.onos.flow.IFlowManager;
@@ -15,12 +11,15 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.blueprints.util.wrappers.event.listener.GraphChangedListener;
-public class LocalTopologyEventListener implements GraphChangedListener {
+public class LocalTopologyEventListener implements LocalGraphChangedListener {
protected static Logger log = LoggerFactory.getLogger(LocalTopologyEventListener.class);
- protected static GraphDBConnection conn = GraphDBConnection.getInstance("");
+ protected static GraphDBConnection conn;
+
+ public LocalTopologyEventListener(GraphDBConnection conn) {
+ LocalTopologyEventListener.conn = conn;
+ }
@Override
public void edgeAdded(Edge arg0) {
@@ -28,11 +27,6 @@
// Convert this Event into NetMapEvent (LinkAdded, FlowEntryEnabled, HostAttached, PortEnabled)
}
- @Override
- public void edgePropertyChanged(Edge arg0, String arg1, Object arg2) {
- // TODO Auto-generated method stub
- // Generate State change events on edges too
- }
@Override
public void edgePropertyRemoved(Edge arg0, String arg1, Object arg2) {
@@ -71,22 +65,40 @@
}
@Override
- public void vertexPropertyChanged(Vertex arg0, String arg1, Object arg2) {
- // TODO Auto-generated method stub
-
-
- }
-
- @Override
public void vertexPropertyRemoved(Vertex arg0, String arg1, Object arg2) {
// TODO Auto-generated method stub
}
@Override
- public void vertexRemoved(Vertex arg0) {
+ public void vertexRemoved(Vertex vertex) {
// TODO Auto-generated method stub
+ // Generate NetMapEvents
+ String type = (String) vertex.getProperty("type");
+ log.debug("TopologyEvents: Received vertex removed event: {}",vertex.toString());
+ if (type.equals("port")) {
+ // port is removed...lets fire reconcile here directly for now
+
+ IPortObject src_port = conn.getFramedGraph().frame(vertex, IPortObject.class);
+ log.debug("TopologyEvents: Port removed: {}:{}",src_port.getSwitch().getDPID(),src_port.getNumber());
+ IFlowManager manager = new FlowManagerImpl();
+ manager.reconcileFlows(src_port);
+ }
+ }
+
+ @Override
+ public void edgePropertyChanged(Edge arg0, String arg1, Object arg2,
+ Object arg3) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void vertexPropertyChanged(Vertex arg0, String arg1, Object arg2,
+ Object arg3) {
+ // TODO Auto-generated method stub
+
}
}