📄 availabilitydata.java
字号:
Filter filter = new Filter(); initialiseConnection(); // Prepare the statement to get service entries for each IP PreparedStatement servicesGetStmt = m_availConn.prepareStatement(AvailabilityConstants.DB_GET_SVC_ENTRIES); // Prepared statement to get node info for an ip PreparedStatement ipInfoGetStmt = m_availConn.prepareStatement(AvailabilityConstants.DB_GET_INFO_FOR_IP); // Prepared statement to get outages entries PreparedStatement outagesGetStmt = m_availConn.prepareStatement(AvailabilityConstants.DB_GET_OUTAGE_ENTRIES); // get the rule for this category, get the list of nodes that satisfy // this rule m_catComment = cat.getComment(); String filterRule = m_commonRule; if (log.isDebugEnabled()) log.debug("Category: " + filterRule); String ip = null; ResultSet ipRS = null; try { List nodeIPs = filter.getIPList(filterRule); if (log.isDebugEnabled()) log.debug("Number of IPs satisfying rule: " + nodeIPs.size()); // For each of these IP addresses, get the details from the // ifServices and services tables Iterator ipIter = nodeIPs.iterator(); while (ipIter.hasNext()) { ip = (String) ipIter.next(); // get node info for this ip ipInfoGetStmt.setString(1, ip); ipRS = ipInfoGetStmt.executeQuery(); while (ipRS.next()) { int nodeid = ipRS.getInt(1); String nodeName = ipRS.getString(2); // if(log.isDebugEnabled()) // log.debug("IP->node info lookup result: " + nodeid); // // get the services for this IP address // ResultSet svcRS = null; servicesGetStmt.setLong(1, nodeid); servicesGetStmt.setString(2, ip); servicesGetStmt.setString(3, ip); servicesGetStmt.setLong(4, nodeid); svcRS = servicesGetStmt.executeQuery(); // create node objects for this nodeID/IP/service while (svcRS.next()) { // read data from the resultset int svcid = svcRS.getInt(1); String svcname = svcRS.getString(2); // If the list is empty, we assume all services are // monitored. If it has any, we use it as a filter if (monitoredServices.isEmpty() || monitoredServices.contains(svcname)) { // if(log.isDebugEnabled()) // log.debug("services result: " + nodeid + "\t" + // ip + "\t" + svcname); OutageSvcTimesList outageSvcTimesList = new OutageSvcTimesList(); getOutagesNodeIpSvc(nodeid, nodeName, ip, svcid, svcname, outageSvcTimesList, outagesGetStmt); /* * IfService ifservice = new IfService(nodeid, ip, * svcid, nodeName, svcname); Map svcOutages = * (Map)m_services.get(svcname); if(svcOutages == * null) svcOutages = new HashMap(); * svcOutages.put(ifservice, outageSvcTimesList); * m_services.put(svcname, svcOutages); */ } } // finally close the result set try { if (svcRS != null) svcRS.close(); } catch (Exception e) { if (log.isEnabledFor(Priority.FATAL)) log.fatal("Exception while closing the services result set", e); throw e; } } } } catch (SQLException e) { if (log.isEnabledFor(Priority.FATAL)) log.fatal("Unable to get node list for category \'" + cat.getLabel(), e); throw e; } catch (FilterParseException e) { // if we get here, the error was most likely in // getting the nodelist from the filters if (log.isEnabledFor(Priority.FATAL)) log.fatal("Unable to get node list for category \'" + cat.getLabel(), e); // throw exception throw e; } catch (Exception e) { if (log.isEnabledFor(Priority.FATAL)) log.fatal("Unable to get node list for category \'" + cat.getLabel(), e); // throw exception throw new Exception("Unable to get node list for category \'" + cat.getLabel() + "\':\n\t" + e); } finally { try { if (ipRS != null) ipRS.close(); if (servicesGetStmt != null) servicesGetStmt.close(); if (ipInfoGetStmt != null) ipInfoGetStmt.close(); if (outagesGetStmt != null) outagesGetStmt.close(); if (m_availConn != null) closeConnection(); } catch (Exception e) { if (log.isEnabledFor(Priority.FATAL)) log.fatal("Exception while closing the ip get node info result set - ip: " + ip, e); throw e; } } } /** * Get all outages for this nodeid/ipaddr/service combination and add it to * m_nodes. */ private void getOutagesNodeIpSvc(int nodeid, String nodeName, String ipaddr, int serviceid, String serviceName, OutageSvcTimesList outageSvcTimesList, PreparedStatement outagesGetStmt) throws SQLException { org.apache.log4j.Category log = ThreadCategory.getInstance(AvailabilityData.class); // Get outages for this node/ip/svc pair try { // if (log.isDebugEnabled()) // log.debug("Node " + nodeid + " ipaddr " + ipaddr + " serviceid " // + serviceid); outagesGetStmt.setInt(1, nodeid); outagesGetStmt.setString(2, ipaddr); outagesGetStmt.setInt(3, serviceid); ResultSet rs = outagesGetStmt.executeQuery(); if (m_nodes != null && m_nodes.size() > 0) { ListIterator lstIter = m_nodes.listIterator(); boolean foundFlag = false; Node oldNode = null; while (lstIter.hasNext()) { oldNode = (Node) lstIter.next(); if (oldNode != null && oldNode.getNodeID() == nodeid) { foundFlag = true; break; } } if (!foundFlag) { Node newNode = new Node(nodeName, nodeid); newNode.addInterface(ipaddr, serviceName); m_nodes.add(newNode); } else { oldNode.addInterface(ipaddr, serviceName); } } else { Node newNode = new Node(nodeName, nodeid); newNode.addInterface(ipaddr, serviceName); m_nodes.add(newNode); }// rs.beforeFirst(); while (rs.next()) { Timestamp lost = rs.getTimestamp(1); Timestamp regained = rs.getTimestamp(2); long losttime = lost.getTime(); long regainedtime = 0; if (regained != null) regainedtime = regained.getTime(); if (regainedtime > 0) { if (regainedtime <= m_12MonthsBack || losttime >= m_endTime) continue; } else { if (losttime >= m_endTime) continue; } Outage outage = new Outage(losttime, regainedtime); outageSvcTimesList.add(outage); addNode(nodeName, nodeid, ipaddr, serviceName, losttime, regainedtime); } if (rs != null) rs.close(); } catch (SQLException e) { if (log.isEnabledFor(Priority.FATAL)) log.fatal("Error has occured while getting the outages ", e); throw e; } } /** * This method adds a unique tuple to the list of nodes m_nodes. */ public void addNode(String nodeName, int nodeid, String ipaddr, String serviceid, long losttime, long regainedtime) { org.apache.log4j.Category log = ThreadCategory.getInstance(AvailabilityData.class); if (m_nodes == null) m_nodes = new ArrayList(); else { if (m_nodes.size() <= 0) { Node newNode = new Node(nodeName, nodeid); // if(log.isDebugEnabled()) // log.debug("Created the new node."); if (losttime > 0) { if (regainedtime > 0) newNode.addInterface(ipaddr, serviceid, losttime, regainedtime); else newNode.addInterface(ipaddr, serviceid, losttime); } else { newNode.addInterface(ipaddr, serviceid); } m_nodes.add(newNode); return; } else // look for the node with the nodeName { Node newNode = null; boolean foundFlag = false; ListIterator lstIter = m_nodes.listIterator(); while (lstIter.hasNext()) { newNode = (Node) lstIter.next(); if (newNode.getNodeID() == nodeid) { foundFlag = true; break; } } if (!foundFlag) { newNode = new Node(nodeName, nodeid); if (losttime > 0) { if (regainedtime > 0) newNode.addInterface(ipaddr, serviceid, losttime, regainedtime); else newNode.addInterface(ipaddr, serviceid, losttime); } else { newNode.addInterface(ipaddr, serviceid); } m_nodes.add(newNode); return; } else { if (losttime > 0) { if (regainedtime > 0) newNode.addInterface(ipaddr, serviceid, losttime, regainedtime); else newNode.addInterface(ipaddr, serviceid, losttime); } else { newNode.addInterface(ipaddr, serviceid); } return; } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -