Search in sources :

Example 11 with SimpleWebTable

use of org.opennms.web.svclayer.model.SimpleWebTable in project opennms by OpenNMS.

the class SurveillanceViewController method handleRequestInternal.

/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    if (!m_service.isViewName(req.getParameter(VIEW_NAME_PARAMETER))) {
        SurveillanceViewError viewError = createSurveillanceViewError(WebSecurityUtils.sanitizeString(req.getParameter(VIEW_NAME_PARAMETER)));
        return new ModelAndView("surveillanceViewError", "error", viewError);
    }
    HttpSession session = req.getSession();
    resp.setHeader("Refresh", String.valueOf(m_service.getHeaderRefreshSeconds(WebSecurityUtils.sanitizeString(req.getParameter(VIEW_NAME_PARAMETER)))));
    ProgressMonitor progressMonitor = (ProgressMonitor) session.getAttribute(PROGRESS_MONITOR_KEY);
    if (progressMonitor == null) {
        progressMonitor = createProgressMonitor(WebSecurityUtils.sanitizeString(req.getParameter(VIEW_NAME_PARAMETER)));
        session.setAttribute(PROGRESS_MONITOR_KEY, progressMonitor);
    }
    if (progressMonitor.isError()) {
        session.removeAttribute(PROGRESS_MONITOR_KEY);
        Throwable t = progressMonitor.getThrowable();
        throw new Exception("SurveillanceView Builder Thread threw exception: [" + t.getClass().getName() + "] " + t.getMessage(), t);
    }
    if (progressMonitor.isFinished()) {
        session.removeAttribute(PROGRESS_MONITOR_KEY);
        SimpleWebTable table = (SimpleWebTable) progressMonitor.getResult();
        ModelAndView modelAndView = new ModelAndView("surveillanceView", "webTable", table);
        modelAndView.addObject("viewNames", m_service.getViewNames());
        return modelAndView;
    }
    return new ModelAndView("progressBar", "progress", progressMonitor);
}
Also used : ProgressMonitor(org.opennms.web.svclayer.model.ProgressMonitor) HttpSession(javax.servlet.http.HttpSession) ModelAndView(org.springframework.web.servlet.ModelAndView) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable)

Example 12 with SimpleWebTable

use of org.opennms.web.svclayer.model.SimpleWebTable in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method testCreateFacilityStatusTableOneApplicationOneOfTwoLocationsReporting.

/*
     * XXX need to check sorting
     */
public void testCreateFacilityStatusTableOneApplicationOneOfTwoLocationsReporting() throws Exception {
    OnmsApplication app = m_application2;
    // No need to shuffle, since this is a list
    List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
    locationDefinitions.add(m_locationDefinition1);
    locationDefinitions.add(m_locationDefinition2);
    OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
    Collection<OnmsLocationSpecificStatus> mostRecentStatuses = new LinkedList<>();
    mostRecentStatuses.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061011-00:00:00"));
    Collection<OnmsLocationSpecificStatus> statusChanges = new LinkedList<>();
    statusChanges.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061011-00:00:00"));
    Date startDate = s_dbDate.parse("2006-10-12 00:00:00.0");
    Date endDate = s_dbDate.parse("2006-10-13 00:00:00.0");
    expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
    expect(m_applicationDao.findAll()).andReturn(Collections.singletonList(app));
    expect(m_locationMonitorDao.getAllMostRecentStatusChanges()).andReturn(mostRecentStatuses);
    expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(0))).andReturn(Collections.singleton(m_locationMonitor1_1));
    expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(1))).andReturn(Collections.singleton(m_locationMonitor2_1));
    expect(m_locationMonitorDao.getStatusChangesBetween(startDate, endDate)).andReturn(statusChanges);
    expect(m_locationMonitorDao.getAllStatusChangesAt(startDate)).andReturn(new HashSet<OnmsLocationSpecificStatus>());
    expect(m_monitoredServiceDao.findByApplication(app)).andReturn(m_applicationServices2).times(2);
    m_easyMockUtils.replayAll();
    SimpleWebTable table = m_service.createFacilityStatusTable(startDate, endDate);
    m_easyMockUtils.verifyAll();
    SimpleWebTable expectedTable = new SimpleWebTable();
    expectedTable.setTitle("Distributed Status Summary");
    expectedTable.addColumn("Area", "");
    expectedTable.addColumn("Location", "");
    expectedTable.addColumn(app.getName(), "");
    expectedTable.newRow();
    expectedTable.addCell("OpenNMS NC", "");
    expectedTable.addCell("Raleigh", "");
    expectedTable.addCell("100.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+2");
    expectedTable.newRow();
    expectedTable.addCell("OpenNMS NC", "");
    expectedTable.addCell("Durham", "");
    expectedTable.addCell("No data", "Indeterminate");
    assertTableEquals(expectedTable, table);
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) LinkedList(java.util.LinkedList) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 13 with SimpleWebTable

use of org.opennms.web.svclayer.model.SimpleWebTable in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method testCreateFacilityStatusTable.

public void testCreateFacilityStatusTable() throws Exception {
    // No need to shuffle, since this is a list
    List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
    locationDefinitions.add(m_locationDefinition1);
    locationDefinitions.add(m_locationDefinition2);
    locationDefinitions.add(m_locationDefinition3);
    List<OnmsApplication> applications = new LinkedList<>();
    applications.add(m_application1);
    applications.add(m_application2);
    Collections.shuffle(applications);
    OnmsMonitoredService httpService = findMonitoredService(m_services, m_ip, "HTTP");
    OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
    OnmsMonitoredService icmpService = findMonitoredService(m_services, m_ip, "ICMP");
    Collection<OnmsLocationSpecificStatus> mostRecentStatuses = new LinkedList<>();
    mostRecentStatuses.add(createStatus(m_locationMonitor1_1, httpService, PollStatus.available(), "20061011-00:00:00"));
    mostRecentStatuses.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
    mostRecentStatuses.add(createStatus(m_locationMonitor2_1, httpService, PollStatus.available(), "20061011-00:00:00"));
    mostRecentStatuses.add(createStatus(m_locationMonitor2_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
    mostRecentStatuses.add(createStatus(m_locationMonitor2_2, httpService, PollStatus.available(), "20061011-00:00:00"));
    mostRecentStatuses.add(createStatus(m_locationMonitor2_2, httpsService, PollStatus.available(), "20061012-06:00:00"));
    Collection<OnmsLocationSpecificStatus> statusChanges = new LinkedList<>();
    statusChanges.add(createStatus(m_locationMonitor1_1, httpService, PollStatus.available(), "20061011-00:00:00"));
    statusChanges.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.unavailable(), "20061012-00:00:00"));
    statusChanges.add(createStatus(m_locationMonitor1_1, httpsService, PollStatus.available(), "20061012-06:00:00"));
    statusChanges.add(createStatus(m_locationMonitor1_1, icmpService, PollStatus.down(), "20061010-06:00:00"));
    Date startDate = s_dbDate.parse("2006-10-12 00:00:00.0");
    Date endDate = s_dbDate.parse("2006-10-13 00:00:00.0");
    expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
    expect(m_applicationDao.findAll()).andReturn(applications);
    expect(m_locationMonitorDao.getAllMostRecentStatusChanges()).andReturn(mostRecentStatuses);
    expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(0))).andReturn(Collections.singleton(m_locationMonitor1_1));
    Collection<OnmsLocationMonitor> monitors2 = new HashSet<>();
    monitors2.add(m_locationMonitor2_1);
    monitors2.add(m_locationMonitor2_2);
    expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(1))).andReturn(monitors2);
    expect(m_locationMonitorDao.findByLocationDefinition(locationDefinitions.get(2))).andReturn(new HashSet<OnmsLocationMonitor>());
    expect(m_locationMonitorDao.getStatusChangesBetween(startDate, endDate)).andReturn(statusChanges);
    expect(m_locationMonitorDao.getAllStatusChangesAt(startDate)).andReturn(new HashSet<OnmsLocationSpecificStatus>());
    expect(m_monitoredServiceDao.findByApplication(m_application1)).andReturn(m_applicationServices1).times(3);
    expect(m_monitoredServiceDao.findByApplication(m_application2)).andReturn(m_applicationServices2).times(3);
    m_easyMockUtils.replayAll();
    SimpleWebTable table = m_service.createFacilityStatusTable(startDate, endDate);
    m_easyMockUtils.verifyAll();
    SimpleWebTable expectedTable = new SimpleWebTable();
    expectedTable.setTitle("Distributed Status Summary");
    expectedTable.addColumn("Area", "");
    expectedTable.addColumn("Location", "");
    expectedTable.addColumn("Application 1", "");
    expectedTable.addColumn("Application 2", "");
    expectedTable.newRow();
    expectedTable.addCell("OpenNMS NC", "");
    expectedTable.addCell("Raleigh", "");
    expectedTable.addCell("75.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+1");
    expectedTable.addCell("75.000%", "Normal", "distributedStatusHistory.htm?location=Raleigh&application=Application+2");
    expectedTable.newRow();
    expectedTable.addCell("OpenNMS NC", "");
    expectedTable.addCell("Durham", "");
    expectedTable.addCell("No data", "Normal");
    expectedTable.addCell("No data", "Normal");
    expectedTable.newRow();
    expectedTable.addCell("OpenNMS OH", "");
    expectedTable.addCell("Columbus", "");
    expectedTable.addCell("No data", "Indeterminate");
    expectedTable.addCell("No data", "Indeterminate");
    assertTableEquals(expectedTable, table);
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) LinkedList(java.util.LinkedList) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) HashSet(java.util.HashSet)

Aggregations

SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)13 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)6 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)5 Date (java.util.Date)4 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)4 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)4 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)4 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 DistributedStatusDetailsCommand (org.opennms.web.svclayer.model.DistributedStatusDetailsCommand)3 BindException (org.springframework.validation.BindException)3 Errors (org.springframework.validation.Errors)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 ProgressMonitor (org.opennms.web.svclayer.model.ProgressMonitor)2 ArrayList (java.util.ArrayList)1 GregorianCalendar (java.util.GregorianCalendar)1 TreeSet (java.util.TreeSet)1 HttpSession (javax.servlet.http.HttpSession)1 Test (org.junit.Test)1 View (org.opennms.netmgt.config.surveillanceViews.View)1