public boolean update(BaseVo baseVo) { Oraspaceconfig vo = (Oraspaceconfig) baseVo; boolean result = false; StringBuffer sql = new StringBuffer(); sql.append("update system_oraspaceconf set ipaddress='"); sql.append(vo.getIpaddress()); sql.append("',spacename='"); sql.append(vo.getSpacename()); sql.append("',linkuse='"); sql.append(vo.getLinkuse()); sql.append("',sms="); sql.append(vo.getSms()); sql.append(",bak='"); sql.append(vo.getBak()); sql.append("',reportflag="); sql.append(vo.getReportflag()); sql.append(",alarmvalue="); sql.append(vo.getAlarmvalue()); sql.append(" where id="); sql.append(vo.getId()); try { conn.executeUpdate(sql.toString()); result = true; } catch (Exception e) { result = false; SysLogger.error("OraspaceconfigDao:update()", e); } finally { conn.close(); } return result; }
/** 对IP_Net_To_Media进行探测 */ private void doIPNetProbe() { if (DiscoverEngine.getInstance().getStopStatus() == 1) return; List ipNetTable = SnmpUtil.getInstance().getIpNetToMediaTable(this.getIpAddress(), this.getCommunity()); if (ipNetTable == null || ipNetTable.size() == 0) // important { setDiscovered(true); return; } ipTotal = ipNetTable.size(); int threadTotal = 0; // 线程总数 SysLogger.info("PER_THREAD_IP===" + PER_THREAD_IP); if (ipTotal % PER_THREAD_IP == 0) // 每个线程对N个ip进行探测 threadTotal = ipTotal / PER_THREAD_IP; else threadTotal = ipTotal / PER_THREAD_IP + 1; IPNetProbeThread probeThread = null; for (int i = 0; i < threadTotal; i++) { if (i == threadTotal - 1) probeThread = new IPNetProbeThread(this, ipNetTable.subList(i * PER_THREAD_IP, ipTotal)); else probeThread = new IPNetProbeThread( this, ipNetTable.subList(i * PER_THREAD_IP, (i + 1) * PER_THREAD_IP)); DiscoverEngine.getInstance().addThread(probeThread); } }
/** 保存文件 */ public int writeModelXml(Hashtable has, Hashtable hat) { int done = 1; try { for (int i = 0; i < has.size(); i++) { String[] str1 = ((String) has.get(i)).split(","); System.out.println(str1.length); // 创建节点 node; String index = str1[2]; String direction = (String) hat.get(i); index = index.replaceAll("index", ""); addNodes(index, "image/up_green.gif", str1[0], str1[1], direction); } Format format = Format.getCompactFormat(); format.setEncoding("GB2312"); format.setIndent(" "); serializer = new XMLOutputter(format); fos = new FileOutputStream(fullPath); fos.write(headBytes.getBytes()); serializer.output(doc, fos); fos.close(); } catch (Exception e) { done = 0; e.printStackTrace(); SysLogger.error("Error in XmlOperator.close()", e); } return done; }
/** 删除一个xml */ public void deleteXml() { try { File delFile = new File(fullPath); delFile.delete(); } catch (Exception e) { SysLogger.error("删除文件操作出错" + fullPath, e); } }
/** 准备更新一个新的xml */ public void init4updateXml() { try { fis = new FileInputStream(fullPath); fis.skip(headBytes.getBytes().length); builder = new SAXBuilder(); doc = builder.build(fis); root = doc.getRootElement(); nodes = root.getChild("nodes"); } catch (Exception e) { e.printStackTrace(); SysLogger.error("Error in XmlOperator.init4updateXml(),file=" + fullPath); } }
/** 按描述找到一个接口 */ public IfEntity getIfEntityByDesc(String desc) { if (desc == null) return null; if (ifEntityList == null || ifEntityList.size() == 0) return null; IfEntity ifEntity = null; for (int i = 0; i < ifEntityList.size(); i++) { IfEntity obj = (IfEntity) ifEntityList.get(i); if (obj.getDescr().equals(desc)) { ifEntity = obj; break; } } if (ifEntity == null) SysLogger.info(ipAddress + "中没有端口描述为" + desc + "的接口"); return ifEntity; }
/** 按端口找到一个接口 */ public IfEntity getIfEntityByPort(String port) { if (port == null) return null; if (ifEntityList == null || ifEntityList.size() == 0) return null; IfEntity ifEntity = null; for (int i = 0; i < ifEntityList.size(); i++) { IfEntity obj = (IfEntity) ifEntityList.get(i); if (obj.getPort().equals(port)) { ifEntity = obj; break; } } if (ifEntity == null) SysLogger.info(ipAddress + "中没有端口为" + port + "的接口"); return ifEntity; }
/** 按接口索引找到接口 */ public IfEntity getIfEntityByIndex(String ifIndex) { if (ifEntityList == null || ifEntityList.size() == 0) return null; IfEntity ifEntity = null; for (int i = 0; i < ifEntityList.size(); i++) { IfEntity obj = (IfEntity) ifEntityList.get(i); if (obj.getIndex().equals(ifIndex)) { ifEntity = obj; break; } } if (ifEntity == null) SysLogger.info(ipAddress + "中没有索引为" + ifIndex + "的接口"); return ifEntity; }
/** 保存文件 */ public void writeXml() { try { Format format = Format.getCompactFormat(); format.setEncoding("GB2312"); format.setIndent(" "); serializer = new XMLOutputter(format); fos = new FileOutputStream(fullPath); fos.write(headBytes.getBytes()); serializer.output(doc, fos); fos.close(); } catch (Exception e) { e.printStackTrace(); SysLogger.error("Error in XmlOperator.close()", e); } }
public void run() { try { HostNodeDao nodeDao = new HostNodeDao(); // 得到被监视的防火墙设备 List nodeList = nodeDao.loadNetwork(8); for (int i = 0; i < nodeList.size(); i++) { HostNode node = (HostNode) nodeList.get(i); } Vector vector = null; int numTasks = nodeList.size(); int numThreads = 200; try { List numList = new ArrayList(); TaskXml taskxml = new TaskXml(); numList = taskxml.ListXml(); for (int i = 0; i < numList.size(); i++) { Task task = new Task(); BeanUtils.copyProperties(task, numList.get(i)); if (task.getTaskname().equals("netthreadnum")) { numThreads = task.getPolltime().intValue(); } } } catch (Exception e) { e.printStackTrace(); } // 生成线程池 ThreadPool threadPool = null; if (nodeList != null && nodeList.size() > 0) { threadPool = new ThreadPool(nodeList.size()); // 运行任务 for (int i = 0; i < nodeList.size(); i++) { threadPool.runTask(createTask((HostNode) nodeList.get(i))); } // 关闭线程池并等待所有任务完成 threadPool.join(); threadPool.close(); } threadPool = null; } catch (Exception e) { e.printStackTrace(); } finally { SysLogger.info("********Firewall Thread Count : " + Thread.activeCount()); } }
public void run() { if (DiscoverEngine.getInstance().getStopStatus() == 1) return; snmp = SnmpUtil.getInstance(); SysLogger.info("开始分析设备" + node.getIpAddress() + "的地址转发表"); Set shieldList = DiscoverResource.getInstance().getShieldSet(); List netshieldList = DiscoverResource.getInstance().getNetshieldList(); List netincludeList = DiscoverResource.getInstance().getNetincludeList(); IfEntity ifEntity = null; IfEntity endifEntity = null; // 生成线程池 ThreadPool threadPool = new ThreadPool(addressList.size()); for (int i = 0; i < addressList.size(); i++) { // ################################### // 若不需要服务器,则不进行交换机的ARP表采集 // if(1==1)continue; // ################################### try { // node.updateCount(2); IpAddress ipAddr = (IpAddress) addressList.get(i); threadPool.runTask(NetMediThread.createTask(ipAddr, node)); // SysLogger.info("在"+node.getIpAddress()+"的地址转发表发现IP "+ipAddr.getIpAddress()+",开始分析"); } catch (Exception ex) { ex.printStackTrace(); } } // end_for // 关闭线程池并等待所有任务完成 threadPool.join(); threadPool.close(); threadPool = null; DiscoverEngine.getInstance().addDiscoverdcount(); snmp = null; setCompleted(true); } // end_run
@Override public void addJob( String jobName, byte type, String pathToJar, String className, String pathToData, String[] peers, int parNumber, int numberOfReducers, HashMap<String, Integer> finishedMappers) throws RemoteException { SysLogger.getInstance().info("Job " + jobName + " started"); Logger logger = null; try { logger = new Logger(0, "..\\log\\WorkerNode.log"); } catch (IncorrectLogFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } DFSClient dfs = DFSClient.getInstance(); try { dfs.init("localhost", 20000, logger); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } String localPathToJar = "..\\tasks\\" + jobName + ".jar"; File jarFile = new File(localPathToJar); if (jarFile.exists()) { jarFile.delete(); } String localPathToData = "..\\tasks\\" + jobName + ".dat"; File dataFile = new File(localPathToData); if (dataFile.exists()) { dataFile.delete(); } try { dfs.downloadFile(pathToJar, localPathToJar); if (type == MapReduce.TYPE_MAPPER) { dfs.downloadFile(pathToData, localPathToData); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { URL url = new URL("file:///" + jarFile.getAbsolutePath()); URLClassLoader classLoader = new URLClassLoader(new URL[] {url}); // todo make this Class c = classLoader.loadClass(className); MapReduce jobObject = (MapReduce) c.newInstance(); Job job = null; if (type == MapReduce.TYPE_MAPPER) { job = new Job( jobName, type, jobObject, dataFile.getAbsolutePath(), peers, parNumber, numberOfReducers, finishedMappers); } else if (type == MapReduce.TYPE_REDUCER) { job = new Job( jobName, type, jobObject, pathToData, peers, parNumber, numberOfReducers, finishedMappers); } jobList.put(jobName, job); job.start(); // start new thread // return control } catch (MalformedURLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
public void addSwitchId(int id) { if (switchIds == null) switchIds = "" + id; else switchIds += "," + id; SysLogger.info(ipAddress + "加入一交换,id=" + id); }
/** 更新所有info项和image项 */ public void updateInfo(boolean isCustom) { I_HostLastCollectData hostlastmanager = new HostLastCollectDataManager(); List list = nodes.getChildren(); for (int i = 0; i < list.size(); i++) { Element eleNode = (Element) list.get(i); int id = Integer.valueOf(eleNode.getChildText("id")).intValue(); int direction = Integer.valueOf(eleNode.getChildText("direction")).intValue(); // Hashtable ipAllData = (Hashtable)ShareData.getSharedata().get(ipaddress); Vector vector = new Vector(); String[] netInterfaceItem = { "index", "ifDescr", "ifSpeed", "ifOperStatus", "OutBandwidthUtilHdx", "InBandwidthUtilHdx" }; try { vector = hostlastmanager.getInterface_share(ipaddress, netInterfaceItem, "index", "", ""); } catch (Exception e) { e.printStackTrace(); } SysLogger.info("######################################"); SysLogger.info("######### " + ipaddress + " ##############"); SysLogger.info("######################################"); if (vector != null && vector.size() > 0) { PortconfigDao dao = new PortconfigDao(); try { for (int m = 0; m < vector.size(); m++) { String[] strs = (String[]) vector.get(m); String ifname = strs[1]; String index = strs[0]; String OutBandwidthUtilHdx = strs[4]; String InBandwidthUtilHdx = strs[5]; String portuse = ""; Portconfig portconfig = null; try { portconfig = dao.getPanelByipandindex(ipaddress, index); } catch (Exception e) { } if (portconfig != null && portconfig.getLinkuse() != null && portconfig.getLinkuse().trim().length() > 0) { portuse = portconfig.getLinkuse(); } if (Integer.parseInt(index) == id) { // 当前端口 if (direction == 1) { // 向上方向的端口 if (strs[3].equalsIgnoreCase("up")) { // 端口启动 SysLogger.info(PanelNodeHelper.getUpUpImage(1)); eleNode.getChild("img").setText(PanelNodeHelper.getUpUpImage(1)); } else { // 端口未启动 SysLogger.info(PanelNodeHelper.getUpDownImage(1)); eleNode.getChild("img").setText(PanelNodeHelper.getUpDownImage(1)); } } else { // 向下方向的端口 if (strs[3].equalsIgnoreCase("up")) { // 端口启动 SysLogger.info(PanelNodeHelper.getDownUpImage(1)); eleNode.getChild("img").setText(PanelNodeHelper.getDownUpImage(1)); } else { // 端口未启动 SysLogger.info(PanelNodeHelper.getDownDownImage(1)); eleNode.getChild("img").setText(PanelNodeHelper.getDownDownImage(1)); } } eleNode.getChild("alias").setText(ifname); eleNode.getChild("ip").setText(ipaddress); StringBuffer msg = new StringBuffer(200); msg.append("<font color='green'>索引:"); msg.append(id); msg.append("</font><br>"); msg.append("描述:"); msg.append(ifname); msg.append("<br>"); msg.append("端口应用:"); msg.append(portuse); msg.append("<br>"); msg.append("入口流速:"); msg.append(InBandwidthUtilHdx); msg.append("<br>"); msg.append("出口流速:"); msg.append(OutBandwidthUtilHdx); msg.append("<br>"); SysLogger.info(msg.toString()); eleNode.getChild("info").setText(msg.toString()); eleNode.getChild("menu").setText(PanelNodeHelper.getMenuItem(index, ipaddress)); } } } catch (Exception e) { } finally { dao.close(); } } // nodes.addContent(i, eleNode); } if (isCustom) { writeXml(); return; } writeXml(); }
/** @author nielin modify at 2010-01-08 */ public int writeXml(int flag) { int done = 0; // 需要做分布式判断 String runmodel = PollingEngine.getCollectwebflag(); try { I_HostLastCollectData hostlastmanager = new HostLastCollectDataManager(); Hashtable ipAllData = (Hashtable) ShareData.getSharedata().get(ipaddress); Vector vector = new Vector(); String[] netInterfaceItem = { "index", "ifDescr", "ifSpeed", "ifAdminStatus", "ifOperStatus", "OutBandwidthUtilHdx", "InBandwidthUtilHdx" }; try { if ("0".equals(runmodel)) { // 采集与访问是集成模式 vector = hostlastmanager.getInterface_share(ipaddress, netInterfaceItem, "index", "", ""); } else { // 采集与访问是分离模式 vector = hostlastmanager.getInterface(ipaddress, netInterfaceItem, "index", "", ""); } } catch (Exception e) { e.printStackTrace(); return done; } try { _fis = new FileInputStream( ResourceCenter.getInstance().getSysPath() + "panel/model/" + oid + "_" + imageType + ".jsp"); } catch (Exception e) { e.printStackTrace(); _fis.close(); return done; } _fis.skip(headBytes.getBytes().length); _builder = new SAXBuilder(); _doc = _builder.build(_fis); _root = _doc.getRootElement(); _nodes = _root.getChild("nodes"); List list = _nodes.getChildren(); PortconfigDao dao = new PortconfigDao(); try { for (int i = 0; i < list.size(); i++) { Element eleNode = (Element) list.get(i); if (eleNode.getChildText("index") == null) break; int index = Integer.valueOf(eleNode.getChildText("index")).intValue(); String x = eleNode.getChildText("x"); String y = eleNode.getChildText("y"); String img = eleNode.getChildText("img"); String direction = eleNode.getChildText("direction"); String ifname = ""; String OutBandwidthUtilHdx = "0"; String InBandwidthUtilHdx = "0"; String portuse = ""; if (vector != null && vector.size() > 0) { for (int m = 0; m < vector.size(); m++) { String[] strs = (String[]) vector.get(m); String _ifname = strs[1]; String _index = strs[0]; String opstatus = strs[4]; OutBandwidthUtilHdx = strs[5]; InBandwidthUtilHdx = strs[6]; Portconfig portconfig = null; try { portconfig = dao.getPanelByipandindex(ipaddress, index + ""); } catch (Exception e) { } if (portconfig != null && portconfig.getLinkuse() != null && portconfig.getLinkuse().trim().length() > 0) { portuse = portconfig.getLinkuse(); } // SysLogger.info(ipaddress+"====ifOperStatus====="+strs[4]); if (Integer.parseInt(_index) == index) { ifname = _ifname; if ("down".equalsIgnoreCase(opstatus)) { // DOWN if ("1".equalsIgnoreCase(direction)) { // 向上的端口 img = "image/up_down_gray.gif"; } else { // 向下的端口 img = "image/down_down_gray.gif"; } } else { // UP if ("1".equalsIgnoreCase(direction)) { // 向上的端口 img = "image/up_up_green.gif"; } else { // 向下的端口 img = "image/down_up_green.gif"; } } break; } } } addNode( index + "", InBandwidthUtilHdx, OutBandwidthUtilHdx, img, ipaddress, ifname, portuse, x, y); } } catch (Exception e) { e.printStackTrace(); } finally { dao.close(); } Format format = Format.getCompactFormat(); format.setEncoding("GB2312"); format.setIndent(" "); serializer = new XMLOutputter(format); // SysLogger.info("path==="+fullPath); fos = new FileOutputStream(fullPath); fos.write(headBytes.getBytes()); serializer.output(doc, fos); fos.close(); done = 1; } catch (Exception e) { done = 0; e.printStackTrace(); SysLogger.error("Error in XmlOperator.close()", e); } return done; }