+ private static Map<String, Integer> map;\r
+ private static Logger intLogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");\r
+ public NodeClass() {\r
+ // init on first use\r
+ if (map == null) {\r
+ reload();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Add nodes to the NODES table, when the NODES parameter value is changed. Nodes are only added to the table, they\r
+ * are never deleted. The node name is normalized to contain the domain (if missing).\r
+ *\r
+ * @param nodes a pipe separated list of the current nodes\r
+ */\r
+ public static void setNodes(String[] nodes) {\r
+ if (map == null) {\r
+ reload();\r
+ }\r
+ int nextid = 0;\r
+ for (Integer n : map.values()) {\r
+ if (n >= nextid) {\r
+ nextid = n + 1;\r
+ }\r
+ }\r
+ // take | separated list, add domain if needed.\r
+\r
+ for (String node : nodes) {\r
+ node = normalizeNodename(node);\r
+ if (!map.containsKey(node)) {\r
+ intLogger.info("..adding " + node + " to NODES with index " + nextid);\r
+ map.put(node, nextid);\r
+ PreparedStatement ps = null;\r
+ try {\r
+ DB db = new DB();\r
+ @SuppressWarnings("resource")\r
+ Connection conn = db.getConnection();\r
+ ps = conn.prepareStatement("insert into NODES (NODEID, NAME, ACTIVE) values (?, ?, 1)");\r
+ ps.setInt(1, nextid);\r
+ ps.setString(2, node);\r
+ ps.execute();\r
+ ps.close();\r
+ db.release(conn);\r
+ } catch (SQLException e) {\r
+ intLogger.error("PROV0005 doInsert: " + e.getMessage(),e);\r
+ } finally {\r
+ try {\r
+ if(ps!=null){\r
+ ps.close();\r
+ }\r
+ } catch (SQLException e) {\r
+ intLogger.error("Error in closing PreparedStatement: " + e.getMessage(),e);\r
+ }\r
+ }\r
+ nextid++;\r
+ }\r
+ }\r
+ }\r
+\r
+ public static void reload() {\r
+ Map<String, Integer> m = new HashMap<String, Integer>();\r
+ PreparedStatement ps = null;\r