⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 availabilitydata.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2006 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// 2006 May 30: Added a way to choose the date to run the availability reports.//// Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// For more information contact://      OpenNMS Licensing       <license@opennms.org>//      http://www.opennms.org///      http://www.opennms.com///// Tab Size = 8//package org.opennms.report.availability;import java.io.IOException;import java.lang.reflect.UndeclaredThrowableException;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Timestamp;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Enumeration;import java.util.GregorianCalendar;import java.util.Iterator;import java.util.List;import java.util.ListIterator;import java.util.TreeMap;import org.apache.log4j.Priority;import org.exolab.castor.xml.MarshalException;import org.exolab.castor.xml.ValidationException;import org.opennms.core.utils.ThreadCategory;import org.opennms.netmgt.config.CatFactory;import org.opennms.netmgt.config.CategoryFactory;import org.opennms.netmgt.config.DatabaseConnectionFactory;import org.opennms.netmgt.config.categories.Categorygroup;import org.opennms.netmgt.config.categories.Catinfo;import org.opennms.netmgt.filter.Filter;import org.opennms.netmgt.filter.FilterParseException;import org.opennms.report.datablock.Node;import org.opennms.report.datablock.Outage;import org.opennms.report.datablock.OutageSvcTimesList;/** * AvailabilityData collects all the outages for all node/ip/service combination * and stores it appropriately in the m_nodes structure. *  * @author <A HREF="mailto:jacinta@oculan.com">Jacinta Remedios </A> * @author <A HREF="http://www.oculan.com">Oculan </A> */public class AvailabilityData extends Object {    /**     * The log4j category used to log debug messsages and statements.     */    private static final String LOG4J_CATEGORY = "OpenNMS.Report";    /**     * Database connection handle.     */    static java.sql.Connection m_availConn;    /**     * List of Node objects that satisfy the filter rule for the category.     */    private List m_nodes;    /**     * Common Rule for the category group.     */    private String m_commonRule;    /**     * Category Name     */    private String m_categoryName;    /**     * Category Comments     */    private String m_catComment;    /**     * End Time of the report.     */    private long m_endTime;    /**     * End Time of the report.     */    private long m_12MonthsBack;    /**     * End Time of the last month.     */    private long m_lastMonthEndTime;    /**     * Number of days in the last month     */    private int m_daysInLastMonth;    /**     * Category Factory     */    CatFactory m_catFactory;    /**     * Rolling window of the last year.     */    private static long LAST_YEAR_ROLLING_WINDOW;    /**     * Section Index     */    private int m_sectionIndex = 0;    /**     * Constructor     *      */    public AvailabilityData(String categoryName, Report report, String format, String monthFormat, Calendar calendar, String startMonth, String startDate, String startYear) throws IOException, MarshalException, ValidationException, Exception {        ThreadCategory.setPrefix(LOG4J_CATEGORY);        org.apache.log4j.Category log = ThreadCategory.getInstance(this.getClass());        if (log.isDebugEnabled())            log.debug("Inside AvailabilityData");        m_nodes = new ArrayList();        initialiseInterval(calendar, startMonth, startDate, startYear);        m_categoryName = categoryName;        Catinfo config = null;        try {            CategoryFactory.init();            m_catFactory = CategoryFactory.getInstance();            config = m_catFactory.getConfig();        } catch (IOException ioe) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("IOException " + ioe);            throw ioe;        } catch (MarshalException marshex) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("Exception " + marshex);            throw marshex;        } catch (ValidationException ex) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("Exception " + ex);            throw ex;        }        if (log.isDebugEnabled())            log.debug("CATEGORY " + categoryName);        if (categoryName.equals("") || categoryName.equals("all")) {            Enumeration enumCG = config.enumerateCategorygroup();            int catCount = 0;			if (log.isDebugEnabled())                log.debug("catCount " + catCount);            while (enumCG.hasMoreElements()) {                Categorygroup cg = (Categorygroup) enumCG.nextElement();                // go through the categories                org.opennms.netmgt.config.categories.Categories cats = cg.getCategories();                Enumeration enumCat = cats.enumerateCategory();                while (enumCat.hasMoreElements()) {                    org.opennms.netmgt.config.categories.Category cat = (org.opennms.netmgt.config.categories.Category) enumCat.nextElement();                    Enumeration enumMonitoredSvc = cat.enumerateService();                    List monitoredServices = new ArrayList();                    while (enumMonitoredSvc.hasMoreElements()) {                        String service = (String) enumMonitoredSvc.nextElement();                        monitoredServices.add(service);                    }                    if (log.isDebugEnabled())                        log.debug("CATEGORY " + cat.getLabel());                    catCount++;                    populateDataStructures(cat, report, format, monthFormat, catCount);                }            }			if (log.isDebugEnabled())                log.debug("catCount " + catCount);        } else {            org.opennms.netmgt.config.categories.Category cat = (org.opennms.netmgt.config.categories.Category) m_catFactory.getCategory(categoryName);            if (log.isDebugEnabled())                log.debug("CATEGORY - now populate data structures " + cat.getLabel());            populateDataStructures(cat, report, format, monthFormat, 1);        }        SimpleDateFormat simplePeriod = new SimpleDateFormat("MMMMMMMMMMM dd, yyyy");        String reportPeriod = simplePeriod.format(new java.util.Date(m_12MonthsBack)) + " - " + simplePeriod.format(new java.util.Date(m_endTime));        Created created = report.getCreated();        if (created == null)            created = new Created();        created.setPeriod(reportPeriod);        report.setCreated(created);        if (log.isDebugEnabled())            log.debug("After availCalculations");    }    /**     * Populates the data structure for this category. This method only computes     * for monitored services in this category.     *      * @param cat     *            Category     * @param report     *            Report Castor class     * @param format     *            SVG-specific/all reports     */    private void populateDataStructures(org.opennms.netmgt.config.categories.Category cat, Report report, String format, String monthFormat, int catIndex) throws Exception {        org.apache.log4j.Category log = ThreadCategory.getInstance(this.getClass());		if (log.isDebugEnabled())			log.debug("Inside populate data Structures" + catIndex);		report.setCatCount(catIndex);		if (log.isDebugEnabled())			log.debug("Inside populate data Structures");        try {            String categoryName = cat.getLabel();            m_commonRule = m_catFactory.getEffectiveRule(categoryName);            Enumeration enumMonitoredSvc = cat.enumerateService();            List monitoredServices = new ArrayList();            while (enumMonitoredSvc.hasMoreElements()) {                String service = (String) enumMonitoredSvc.nextElement();				if (log.isDebugEnabled())	                log.debug("adding service" + service);                monitoredServices.add(service);            }            populateNodesFromDB(cat, monitoredServices);            ViewInfo viewInfo = report.getViewInfo();            if (log.isDebugEnabled()) {                log.debug("Nodes " + m_nodes);            }            ListIterator cleanNodes = m_nodes.listIterator();            while (cleanNodes.hasNext()) {                Node node = (Node) cleanNodes.next();                if (node != null && !node.hasOutages()) {					if (log.isDebugEnabled())		                log.debug("Removing node: " + node);					cleanNodes.remove();                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -