refactor LinkStorageImpl class to use GraphDBOperation class.
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
index c8ca86f..be15ca0 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImpl.java
@@ -9,7 +9,7 @@
import net.floodlightcontroller.linkdiscovery.LinkInfo;
import net.floodlightcontroller.routing.Link;
import net.onrc.onos.util.GraphDBConnection;
-import net.onrc.onos.util.GraphDBConnection.Transaction;
+import net.onrc.onos.util.GraphDBOperation;
import org.openflow.util.HexString;
import org.slf4j.Logger;
@@ -26,7 +26,7 @@
public class LinkStorageImpl implements ILinkStorage {
protected static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class);
- protected String conf;
+ protected GraphDBOperation dbop;
@Override
public void update(Link link, DM_OPERATION op) {
@@ -55,7 +55,6 @@
}
public void updateLink(Link lt, LinkInfo linkinfo, DM_OPERATION op) {
- GraphDBConnection conn = GraphDBConnection.getInstance(this.conf);
IPortObject vportSrc = null, vportDst = null;
log.trace("updateLink(): op {} {} {}", new Object[]{op, lt, linkinfo});
@@ -64,12 +63,12 @@
// get source port vertex
String dpid = HexString.toHexString(lt.getSrc());
short port = lt.getSrcPort();
- vportSrc = conn.utils().searchPort(conn, dpid, port);
+ vportSrc = dbop.searchPort(dpid, port);
// get dest port vertex
dpid = HexString.toHexString(lt.getDst());
port = lt.getDstPort();
- vportDst = conn.utils().searchPort(conn, dpid, port);
+ vportDst = dbop.searchPort(dpid, port);
if (vportSrc != null && vportDst != null) {
@@ -90,12 +89,12 @@
} else {
vportSrc.setLinkPort(vportDst);
- conn.endTx(Transaction.COMMIT);
+ dbop.commit();
log.debug("updateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
}
} else {
log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
- conn.endTx(Transaction.ROLLBACK);
+ dbop.rollback();
}
} catch (TitanException e) {
/*
@@ -117,7 +116,6 @@
@Override
public void deleteLink(Link lt) {
- GraphDBConnection conn = GraphDBConnection.getInstance(this.conf);
IPortObject vportSrc = null, vportDst = null;
int count = 0;
@@ -127,12 +125,12 @@
// get source port vertex
String dpid = HexString.toHexString(lt.getSrc());
short port = lt.getSrcPort();
- vportSrc = conn.utils().searchPort(conn, dpid, port);
+ vportSrc = dbop.searchPort(dpid, port);
// get dst port vertex
dpid = HexString.toHexString(lt.getDst());
port = lt.getDstPort();
- vportDst = conn.utils().searchPort(conn, dpid, port);
+ vportDst = dbop.searchPort(dpid, port);
// FIXME: This needs to remove all edges
if (vportSrc != null && vportDst != null) {
@@ -146,13 +144,13 @@
}
}*/
vportSrc.removeLink(vportDst);
- conn.endTx(Transaction.COMMIT);
+ dbop.commit();
log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{
lt, vportSrc, vportDst});
} else {
log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
- conn.endTx(Transaction.ROLLBACK);
+ dbop.rollback();
}
} catch (TitanException e) {
@@ -160,7 +158,7 @@
* retry till we succeed?
*/
log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()});
- conn.endTx(Transaction.ROLLBACK);
+ dbop.rollback();
e.printStackTrace();
}
}
@@ -168,12 +166,11 @@
// TODO: Fix me
@Override
public List<Link> getLinks(Long dpid, short port) {
- GraphDBConnection conn = GraphDBConnection.getInstance(this.conf);
IPortObject vportSrc, vportDst;
List<Link> links = null;
Link lt;
- vportSrc = conn.utils().searchPort(conn, HexString.toHexString(dpid), port);
+ vportSrc = dbop.searchPort(HexString.toHexString(dpid), port);
if (vportSrc != null) {
for (Edge e : vportSrc.asVertex().getEdges(Direction.OUT)) {
@@ -188,9 +185,7 @@
@Override
public void init(String conf) {
//TODO extract the DB location from properties
-
- this.conf = conf;
-
+ this.dbop = new GraphDBOperation(GraphDBConnection.getInstance(conf));
}
@Override
@@ -206,10 +201,7 @@
}
public List<Link> getActiveLinks() {
-
- GraphDBConnection conn = GraphDBConnection.getInstance(this.conf);
-
- Iterable<ISwitchObject> switches = conn.utils().getActiveSwitches(conn);
+ Iterable<ISwitchObject> switches = dbop.getActiveSwitches();
List<Link> links = new ArrayList<Link>();
for (ISwitchObject sw : switches) {