- private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");\r
- private final int subid;\r
- private final int nodeid;\r
-\r
- /**\r
- * Get a set of all Egress Routes in the DB. The set is sorted according to the natural sorting order\r
- * of the routes (based on the subscription ID in each route).\r
- * @return the sorted set\r
- */\r
- public static SortedSet<EgressRoute> getAllEgressRoutes() {\r
- SortedSet<EgressRoute> set = new TreeSet<EgressRoute>();\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- Statement stmt = conn.createStatement();\r
- ResultSet rs = stmt.executeQuery("select SUBID, NODEID from EGRESS_ROUTES");\r
- while (rs.next()) {\r
- int subid = rs.getInt("SUBID");\r
- int nodeid = rs.getInt("NODEID");\r
- set.add(new EgressRoute(subid, nodeid));\r
- }\r
- rs.close();\r
- stmt.close();\r
- db.release(conn);\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- return set;\r
- }\r
- /**\r
- * Get a single Egress Route for the subscription <i>sub</i>.\r
- * @param sub the subscription to lookup\r
- * @return an EgressRoute, or null if there is no route for this subscription\r
- */\r
- public static EgressRoute getEgressRoute(int sub) {\r
- EgressRoute v = null;\r
- PreparedStatement ps = null;\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- String sql = "select NODEID from EGRESS_ROUTES where SUBID = ?";\r
- ps = conn.prepareStatement(sql);\r
- ps.setInt(1, sub);\r
- ResultSet rs = ps.executeQuery();\r
- if (rs.next()) {\r
- int node = rs.getInt("NODEID");\r
- v = new EgressRoute(sub, node);\r
- }\r
- rs.close();\r
- ps.close();\r
- db.release(conn);\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- } finally {\r
- try {\r
- ps.close();\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return v;\r
- }\r
-\r
- public EgressRoute(int subid, int nodeid) throws IllegalArgumentException {\r
- this.subid = subid;\r
- this.nodeid = nodeid;\r
-// Note: unlike for Feeds, it subscriptions can be removed from the tables, so it is\r
-// possible that an orphan ERT entry can exist if a sub is removed.\r
-// if (Subscription.getSubscriptionById(subid) == null)\r
-// throw new IllegalArgumentException("No such subscription: "+subid);\r
- }\r
-\r
- public EgressRoute(int subid, String node) throws IllegalArgumentException {\r
- this(subid, lookupNodeName(node));\r
- }\r
-\r
- @Override\r
- public boolean doDelete(Connection c) {\r
- boolean rv = true;\r
- PreparedStatement ps = null;\r
- try {\r
- String sql = "delete from EGRESS_ROUTES where SUBID = ?";\r
- ps = c.prepareStatement(sql);\r
- ps.setInt(1, subid);\r
- ps.execute();\r
- } catch (SQLException e) {\r
- rv = false;\r
- intlogger.warn("PROV0007 doDelete: "+e.getMessage());\r
- e.printStackTrace();\r
- } finally {\r
- try {\r
- ps.close();\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return rv;\r
- }\r
-\r
- @Override\r
- public boolean doInsert(Connection c) {\r
- boolean rv = false;\r
- PreparedStatement ps = null;\r
- try {\r
- // Create the NETWORK_ROUTES row\r
- String sql = "insert into EGRESS_ROUTES (SUBID, NODEID) values (?, ?)";\r
- ps = c.prepareStatement(sql);\r
- ps.setInt(1, this.subid);\r
- ps.setInt(2, this.nodeid);\r
- ps.execute();\r
- ps.close();\r
- rv = true;\r
- } catch (SQLException e) {\r
- intlogger.warn("PROV0005 doInsert: "+e.getMessage());\r
- e.printStackTrace();\r
- } finally {\r
- try {\r
- ps.close();\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return rv;\r
- }\r
-\r
- @Override\r
- public boolean doUpdate(Connection c) {\r
- boolean rv = true;\r
- PreparedStatement ps = null;\r
- try {\r
- String sql = "update EGRESS_ROUTES set NODEID = ? where SUBID = ?";\r
- ps = c.prepareStatement(sql);\r
- ps.setInt(1, nodeid);\r
- ps.setInt(2, subid);\r
- ps.executeUpdate();\r
- } catch (SQLException e) {\r
- rv = false;\r
- intlogger.warn("PROV0006 doUpdate: "+e.getMessage());\r
- e.printStackTrace();\r
- } finally {\r
- try {\r
- ps.close();\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return rv;\r
- }\r
-\r
- @Override\r
- public JSONObject asJSONObject() {\r
- JSONObject jo = new JSONObject();\r
- jo.put(""+subid, lookupNodeID(nodeid));\r
- return jo;\r
- }\r
-\r
- @Override\r
- public String getKey() {\r
- return ""+subid;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (!(obj instanceof EgressRoute))\r
- return false;\r
- EgressRoute on = (EgressRoute)obj;\r
- return (subid == on.subid) && (nodeid == on.nodeid);\r
- }\r
-\r
- @Override\r
- public int compareTo(EgressRoute o) {\r
- return this.subid - o.subid;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return String.format("EGRESS: sub=%d, node=%d", subid, nodeid);\r
- }\r
+\r
+ private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
+ private final int subid;\r
+ private final int nodeid;\r
+\r
+ /**\r
+ * EgressRoute constructor.\r
+ * @param subid subscription id\r
+ * @param nodeid node id\r
+ */\r
+ public EgressRoute(int subid, int nodeid) {\r
+ this.subid = subid;\r
+ this.nodeid = nodeid;\r
+ }\r
+\r
+ public EgressRoute(int subid, String node) {\r
+ this(subid, lookupNodeName(node));\r
+ }\r
+\r
+ /**\r
+ * Get a set of all Egress Routes in the DB. The set is sorted according to the natural sorting order of the routes\r
+ * (based on the subscription ID in each route).\r
+ *\r
+ * @return the sorted set\r
+ */\r
+ public static SortedSet<EgressRoute> getAllEgressRoutes() {\r
+ SortedSet<EgressRoute> set = new TreeSet<>();\r
+ DB db = new DB();\r
+ String sql = "select SUBID, NODEID from EGRESS_ROUTES";\r
+ try (Connection conn = db.getConnection()) {\r
+ try (Statement stmt = conn.createStatement()) {\r
+ try (ResultSet rs = stmt.executeQuery(sql)) {\r
+ addEgressRouteToSet(set, rs);\r
+ }\r
+ } finally {\r
+ db.release(conn);\r
+ }\r
+ } catch (SQLException e) {\r
+ intlogger.error("PROV0008 EgressRoute.getAllEgressRoutes: " + e.getMessage(), e);\r
+ }\r
+ return set;\r
+ }\r
+\r
+ private static void addEgressRouteToSet(SortedSet<EgressRoute> set, ResultSet rs) throws SQLException {\r
+ while (rs.next()) {\r
+ int subid = rs.getInt("SUBID");\r
+ int nodeid = rs.getInt("NODEID");\r
+ set.add(new EgressRoute(subid, nodeid));\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Get a single Egress Route for the subscription <i>sub</i>.\r
+ *\r
+ * @param sub the subscription to lookup\r
+ * @return an EgressRoute, or null if there is no route for this subscription\r
+ */\r
+ public static EgressRoute getEgressRoute(int sub) {\r
+ EgressRoute er = null;\r
+ DB db = new DB();\r
+ String sql = "select NODEID from EGRESS_ROUTES where SUBID = ?";\r
+ try (Connection conn = db.getConnection();\r
+ PreparedStatement ps = conn.prepareStatement(sql)) {\r
+ ps.setInt(1, sub);\r
+ try (ResultSet rs = ps.executeQuery()) {\r
+ if (rs.next()) {\r
+ int node = rs.getInt("NODEID");\r
+ er = new EgressRoute(sub, node);\r
+ }\r
+ } finally {\r
+ db.release(conn);\r
+ }\r
+ } catch (SQLException e) {\r
+ intlogger.error("PROV0009 EgressRoute.getEgressRoute: " + e.getMessage(), e);\r
+ }\r
+ return er;\r
+ }\r
+\r
+ @Override\r
+ public boolean doDelete(Connection conn) {\r
+ boolean rv = true;\r
+ String sql = "delete from EGRESS_ROUTES where SUBID = ?";\r
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {\r
+ ps.setInt(1, subid);\r
+ ps.execute();\r
+ } catch (SQLException e) {\r
+ rv = false;\r
+ intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);\r
+ }\r
+ return rv;\r
+ }\r
+\r
+ @Override\r
+ public boolean doInsert(Connection conn) {\r
+ boolean rv = false;\r
+ String sql = "insert into EGRESS_ROUTES (SUBID, NODEID) values (?, ?)";\r
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {\r
+ // Create the NETWORK_ROUTES row\r
+ ps.setInt(1, this.subid);\r
+ ps.setInt(2, this.nodeid);\r
+ ps.execute();\r
+ rv = true;\r
+ } catch (SQLException e) {\r
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);\r
+ }\r
+ return rv;\r
+ }\r
+\r
+ @Override\r
+ public boolean doUpdate(Connection conn) {\r
+ boolean rv = true;\r
+ String sql = "update EGRESS_ROUTES set NODEID = ? where SUBID = ?";\r
+ try (PreparedStatement ps = conn.prepareStatement(sql)) {\r
+ ps.setInt(1, nodeid);\r
+ ps.setInt(2, subid);\r
+ ps.executeUpdate();\r
+ } catch (SQLException e) {\r
+ rv = false;\r
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
+ }\r
+ return rv;\r
+ }\r
+\r
+ @Override\r
+ public JSONObject asJSONObject() {\r
+ JSONObject jo = new JSONObject();\r
+ jo.put("" + subid, lookupNodeID(nodeid));\r
+ return jo;\r
+ }\r
+\r
+ @Override\r
+ public String getKey() {\r
+ return "" + subid;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (!(obj instanceof EgressRoute)) {\r
+ return false;\r
+ }\r
+ EgressRoute on = (EgressRoute) obj;\r
+ return (subid == on.subid) && (nodeid == on.nodeid);\r
+ }\r
+\r
+ @Override\r
+ public int compareTo(EgressRoute er) {\r
+ return this.subid - er.subid;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return String.format("EGRESS: sub=%d, node=%d", subid, nodeid);\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ return Objects.hash(subid, nodeid);\r
+ }\r