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

📄 availabilitydata.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            }            if (log.isDebugEnabled()) {                log.debug("Cleaned Nodes " + m_nodes);            }            TreeMap topOffenders = new TreeMap();            topOffenders = getPercentNode();            if (log.isDebugEnabled())                log.debug("TOP OFFENDERS " + topOffenders);            if (m_nodes.size() <= 0)                m_nodes = null;            if (m_nodes != null) {                AvailCalculations availCalculations = new AvailCalculations(m_nodes, m_endTime, m_lastMonthEndTime, monitoredServices, report, topOffenders, cat.getWarning(), cat.getNormal(), cat.getComment(), cat.getLabel(), format, monthFormat, catIndex, m_sectionIndex);                m_sectionIndex = availCalculations.getSectionIndex();                report.setSectionCount(m_sectionIndex - 1);            } else {                org.opennms.report.availability.Category category = new org.opennms.report.availability.Category();                category.setCatComments(cat.getComment());                category.setCatName(cat.getLabel());                category.setCatIndex(catIndex);                category.setNodeCount(0);                category.setIpaddrCount(0);                category.setServiceCount(0);                Section section = new Section();                section.setSectionIndex(m_sectionIndex);                org.opennms.report.availability.CatSections catSections = new org.opennms.report.availability.CatSections();                catSections.addSection(section);                category.addCatSections(catSections);                org.opennms.report.availability.Categories categories = report.getCategories();                categories.addCategory(category);                report.setCategories(categories);                report.setSectionCount(m_sectionIndex);                m_sectionIndex++;            }        } catch (Exception e) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("Exception has occured " + e);            e.printStackTrace();            throw e;        }    }    /**     * Initialise the endTime, last Months end time and number of days in the     * last month.     */    private void initialiseInterval(Calendar calendar, String startMonth, String startDate, String startYear) {        org.apache.log4j.Category log = ThreadCategory.getInstance(this.getClass());        int month = Integer.parseInt(startMonth);        int day = Integer.parseInt(startDate);        int year = Integer.parseInt(startYear);        // int month = calendar.get(Calendar.MONTH);        // int day = calendar.get(Calendar.DAY_OF_MONTH);        // int year = calendar.get(Calendar.YEAR);        calendar.set(year, month, day - 1, 23, 59, 59); // Set the end Time        m_endTime = calendar.getTime().getTime();        calendar.add(Calendar.YEAR, -1);        LAST_YEAR_ROLLING_WINDOW = m_endTime - calendar.getTime().getTime();        m_12MonthsBack = m_endTime - LAST_YEAR_ROLLING_WINDOW;        calendar = new GregorianCalendar();        calendar.setTime(new java.util.Date(m_12MonthsBack));        month = calendar.get(Calendar.MONTH);        day = calendar.get(Calendar.DAY_OF_MONTH);        year = calendar.get(Calendar.YEAR);        calendar.set(year, month, 1, 0, 0, 0); // Set the end Time        m_12MonthsBack = calendar.getTime().getTime();        if (log.isDebugEnabled()) {            log.debug("last Year " + new java.util.Date(m_12MonthsBack));            log.debug("End Year " + new java.util.Date(m_endTime));            log.debug("Rolling window of the last year " + LAST_YEAR_ROLLING_WINDOW);        }        Calendar lastMonthCalendar = new GregorianCalendar();        lastMonthCalendar.setTime(new java.util.Date((new Double(m_endTime)).longValue()));        month = lastMonthCalendar.get(Calendar.MONTH) - 1;        year = lastMonthCalendar.get(Calendar.YEAR);        lastMonthCalendar.set(year, month, 1, 0, 0, 0);        m_daysInLastMonth = getDaysForMonth(lastMonthCalendar.getTime().getTime()); // Number                                                                                    // of                                                                                    // days                                                                                    // in                                                                                    // the                                                                                    // last                                                                                    // month        lastMonthCalendar.set(year, month, m_daysInLastMonth, 23, 59, 59); // Set                                                                            // the                                                                            // end                                                                            // Time                                                                            // of                                                                            // the                                                                            // last                                                                            // month        m_lastMonthEndTime = lastMonthCalendar.getTime().getTime();    }    /**     * Returns the number of days in the month, also considers checks for leap     * year.     *      * @param isLeap     *            the leap year flag.     * @param month     *            The month whose days count is reqd     */    private static synchronized int getDays(boolean isLeap, int month) {        switch (month) {        case 0:        case 2:        case 4:        case 6:        case 7:        case 9:        case 11:            return 31;        case 3:        case 5:        case 8:        case 10:            return 30;        case 1:            if (isLeap)                return 29;            else                return 28;        }        return -1;    }    /**     * Returns the number of Days in the month     *      * @param endTime     *            The end of the month (time in milliseconds)     */    private int getDaysForMonth(long endTime) {        GregorianCalendar calendar = new GregorianCalendar();        calendar.setTime(new java.util.Date(endTime));        int month = calendar.get(Calendar.MONTH);        int year = calendar.get(Calendar.YEAR);        int days = getDays(calendar.isLeapYear(year), month);        return (getDays(calendar.isLeapYear(year), month));    }    /**     * Returns the nodes.     */    public List getNodes() {        return m_nodes;    }    /**     * Initialises the database connection.     */    public void initialiseConnection() throws IOException, MarshalException, ValidationException, ClassNotFoundException, SQLException {        org.apache.log4j.Category log = ThreadCategory.getInstance(this.getClass());        //        // Initialize the DataCollectionConfigFactory        //        try {            DatabaseConnectionFactory.init();            m_availConn = DatabaseConnectionFactory.getInstance().getConnection();        } catch (MarshalException ex) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("initialize: Failed to load data collection configuration", ex);            throw new UndeclaredThrowableException(ex);        } catch (ValidationException ex) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("initialize: Failed to load data collection configuration", ex);            throw new UndeclaredThrowableException(ex);        } catch (IOException ex) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("initialize: Failed to load data collection configuration", ex);            throw new UndeclaredThrowableException(ex);        } catch (ClassNotFoundException cnfE) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("initialize: Failed loading database driver.", cnfE);            throw new UndeclaredThrowableException(cnfE);        } catch (SQLException sqlE) {            if (log.isEnabledFor(Priority.FATAL))                log.fatal("initialize: Failed getting connection to the database.", sqlE);            throw new UndeclaredThrowableException(sqlE);        }    }    /**     * Closes the database connection.     */    public void closeConnection() {        org.apache.log4j.Category log = ThreadCategory.getInstance(this.getClass());        if (m_availConn != null) {            try {                m_availConn.close();                m_availConn = null;            } catch (Throwable t) {                if (log.isEnabledFor(Priority.WARN))                    log.warn("initialize: an exception occured while closing the JDBC connection", t);            }        }    }    /**     * Returns percent/node combinations for the last month. This is used to get     * the last months top 20 offenders     */    public TreeMap getPercentNode() {        org.apache.log4j.Category log = ThreadCategory.getInstance(this.getClass());        int days = m_daysInLastMonth;        long endTime = m_lastMonthEndTime;        Calendar cal = new GregorianCalendar();        cal.setTimeInMillis(endTime);        cal.add(Calendar.DATE, -1 * days);        long rollingWindow = endTime - cal.getTime().getTime();        long startTime = cal.getTime().getTime();        if (log.isDebugEnabled()) {            log.debug("getPercentNode: Start time " + new java.util.Date(startTime));            log.debug("getPercentNode: End time " + new java.util.Date(endTime));        }        TreeMap percentNode = new TreeMap();        Iterator nodeIter = m_nodes.iterator();        while (nodeIter.hasNext()) {            Node node = (Node) nodeIter.next();            if (node != null) {                double percent = node.getPercentAvail(endTime, rollingWindow);                String nodeName = node.getName();                if (log.isDebugEnabled())                    log.debug("Node " + nodeName + " " + percent + "%");                if (percent < 100.0) {                    List tmp = (List) percentNode.get(new Double(percent));                    if (tmp == null)                        tmp = new ArrayList();                    tmp.add(nodeName);                    percentNode.put(new Double(percent), tmp);                }            }        }        if (log.isDebugEnabled())            log.debug("Percent node " + percentNode);        return percentNode;    }    /**     * For each category in the categories list, this reads the services and     * outage tables to get the initial data, creates objects that are added to     * the map and and to the appropriate category     *      * @throws SQLException     *             if the database read fails due to an SQL error     * @throws FilterParseException     *             if filtering the data against the category rule fails due to     *             the rule being incorrect     */    private void populateNodesFromDB(org.opennms.netmgt.config.categories.Category cat, List monitoredServices) throws SQLException, FilterParseException, Exception {        m_nodes = new ArrayList();		org.apache.log4j.Category log = ThreadCategory.getInstance(AvailabilityData.class);		if (log.isDebugEnabled())            log.debug("in populateNodesFromDB");        // Create the filter

⌨️ 快捷键说明

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