Search in sources :

Example 1 with DistributedStatusHistoryModel

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

the class DistributedStatusHistoryController method handleRequestInternal.

/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String locationName = WebSecurityUtils.sanitizeString(request.getParameter("location"));
    String monitorId = WebSecurityUtils.sanitizeString(request.getParameter("monitorId"));
    String applicationName = WebSecurityUtils.sanitizeString(request.getParameter("application"));
    String timeSpan = WebSecurityUtils.sanitizeString(request.getParameter("timeSpan"));
    String previousLocation = WebSecurityUtils.sanitizeString(request.getParameter("previousLocation"));
    DistributedStatusHistoryModel model = m_distributedStatusService.createHistoryModel(locationName, monitorId, applicationName, timeSpan, previousLocation);
    return new ModelAndView("distributedStatusHistory", "historyModel", model);
}
Also used : DistributedStatusHistoryModel(org.opennms.web.svclayer.model.DistributedStatusHistoryModel) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 2 with DistributedStatusHistoryModel

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

the class DefaultDistributedStatusService method createHistoryModel.

/**
 * {@inheritDoc}
 */
@Override
public DistributedStatusHistoryModel createHistoryModel(String locationName, String monitorId, String applicationName, String timeSpan, String previousLocationName) {
    List<String> errors = new LinkedList<>();
    List<OnmsMonitoringLocation> locationDefinitions = m_monitoringLocationDao.findAll();
    List<RelativeTimePeriod> periods = Arrays.asList(RelativeTimePeriod.getDefaultPeriods());
    Collection<OnmsApplication> applications = m_applicationDao.findAll();
    List<OnmsApplication> sortedApplications = new ArrayList<OnmsApplication>(applications);
    Collections.sort(sortedApplications);
    OnmsMonitoringLocation location = new OnmsMonitoringLocation();
    if (locationName == null) {
        if (!locationDefinitions.isEmpty()) {
            location = locationDefinitions.get(0);
        }
    } else {
        location = m_monitoringLocationDao.get(locationName);
        if (location == null) {
            errors.add("Could not find location definition '" + locationName + "'");
            if (!locationDefinitions.isEmpty()) {
                location = locationDefinitions.get(0);
            }
        }
    }
    OnmsApplication application = new OnmsApplication();
    if (applicationName == null) {
        if (!sortedApplications.isEmpty()) {
            application = sortedApplications.get(0);
        }
    } else {
        application = m_applicationDao.findByName(applicationName);
        if (application == null) {
            errors.add("Could not find application '" + applicationName + "'");
            if (!sortedApplications.isEmpty()) {
                application = sortedApplications.get(0);
            }
        }
    }
    Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByLocationDefinition(location);
    List<OnmsLocationMonitor> sortedMonitors = new LinkedList<OnmsLocationMonitor>(monitors);
    Collections.sort(sortedMonitors);
    OnmsLocationMonitor monitor = null;
    if (monitorId != null && !"".equals(monitorId.trim()) && location.getLocationName().equals(previousLocationName)) {
        for (OnmsLocationMonitor m : sortedMonitors) {
            if (m.getId().equals(monitorId)) {
                monitor = m;
                break;
            }
        }
    }
    if (monitor == null && !sortedMonitors.isEmpty()) {
        monitor = sortedMonitors.get(0);
    }
    RelativeTimePeriod period = RelativeTimePeriod.getPeriodByIdOrDefault(timeSpan);
    /*
         * Initialize the hierarchy under the service so that we don't get
         * a LazyInitializationException later when the JSP page is pulling
         * data out of the model object.
         */
    Collection<OnmsMonitoredService> memberServices = m_monitoredServiceDao.findByApplication(application);
    for (OnmsMonitoredService service : memberServices) {
        m_locationMonitorDao.initialize(service.getIpInterface());
        m_locationMonitorDao.initialize(service.getIpInterface().getNode());
    }
    Collection<OnmsMonitoredService> applicationMemberServices = m_monitoredServiceDao.findByApplication(application);
    if (applicationMemberServices.isEmpty()) {
        errors.add("There are no services in the application '" + applicationName + "'");
    }
    DistributedStatusHistoryModel model = new DistributedStatusHistoryModel(locationDefinitions, sortedApplications, sortedMonitors, periods, location, application, applicationMemberServices, monitor, period, errors);
    initializeGraphUrls(model);
    return model;
}
Also used : ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) LinkedList(java.util.LinkedList) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) DistributedStatusHistoryModel(org.opennms.web.svclayer.model.DistributedStatusHistoryModel) RelativeTimePeriod(org.opennms.web.svclayer.model.RelativeTimePeriod) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 3 with DistributedStatusHistoryModel

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

the class DefaultDistributedStatusServiceTest method testWrongLocationDetails.

public void testWrongLocationDetails() {
    List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
    locationDefinitions.add(m_locationDefinition1);
    locationDefinitions.add(m_locationDefinition2);
    locationDefinitions.add(m_locationDefinition3);
    expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
    List<OnmsApplication> applications = new ArrayList<>();
    applications.add(m_application1);
    applications.add(m_application2);
    expect(m_applicationDao.findAll()).andReturn(applications);
    expect(m_monitoringLocationDao.get("Raleigh-bad")).andReturn(null);
    expect(m_applicationDao.findByName("Application 2")).andReturn(m_application2);
    List<OnmsLocationMonitor> monitors = new ArrayList<>();
    monitors.add(m_locationMonitor1_1);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition1)).andReturn(monitors);
    for (OnmsMonitoredService service : m_applicationServices2) {
        m_locationMonitorDao.initialize(service.getIpInterface());
        m_locationMonitorDao.initialize(service.getIpInterface().getNode());
    }
    String locationName = "Raleigh-bad";
    String applicationName = m_application2.getName();
    String monitorId = "";
    String previousLocation = "";
    String timeSpan = "";
    expect(m_monitoredServiceDao.findByApplication(m_application2)).andReturn(m_applicationServices2).times(2);
    expectResourceDaoCall(m_locationMonitor1_1, m_applicationServices2);
    m_easyMockUtils.replayAll();
    DistributedStatusHistoryModel summary = m_service.createHistoryModel(locationName, monitorId, applicationName, timeSpan, previousLocation);
    m_easyMockUtils.verifyAll();
    assertNotNull("summary should not be null", summary);
    assertNotNull("summary locations list should not be null", summary.getLocations());
    assertNotNull("summary applications list should not be null", summary.getApplications());
    assertNotNull("summary chosen location should not be null", summary.getChosenLocation());
    assertNotNull("summary chosen application should not be null", summary.getChosenApplication());
    assertNotNull("summary error list should not be null", summary.getErrors());
    assertEquals("summary locations list size", locationDefinitions.size(), summary.getLocations().size());
    assertEquals("summary applications list size", applications.size(), summary.getApplications().size());
    assertEquals("summary error list size", 1, summary.getErrors().size());
    // Verify sorting of applications
    assertEquals("summary applications 1", m_application1, summary.getApplications().get(0));
    assertEquals("summary applications 2", m_application2, summary.getApplications().get(1));
    // Verify errors
    assertEquals("summary error 1", "Could not find location definition 'Raleigh-bad'", summary.getErrors().get(0));
    // Verify chosen ones
    assertEquals("summary chosen location", m_locationDefinition1, summary.getChosenLocation());
    assertEquals("summary chosen application", m_application2, summary.getChosenApplication());
    // And verify that they are in the lists in the right place
    assertEquals("summary chosen location matches list", summary.getLocations().get(0), summary.getChosenLocation());
    assertEquals("summary chosen application matches list", summary.getApplications().get(1), summary.getChosenApplication());
}
Also used : DistributedStatusHistoryModel(org.opennms.web.svclayer.model.DistributedStatusHistoryModel) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) LinkedList(java.util.LinkedList) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 4 with DistributedStatusHistoryModel

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

the class DefaultDistributedStatusServiceTest method testWrongApplicationDetails.

public void testWrongApplicationDetails() {
    List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
    locationDefinitions.add(m_locationDefinition1);
    locationDefinitions.add(m_locationDefinition2);
    locationDefinitions.add(m_locationDefinition3);
    expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
    List<OnmsApplication> applications = new ArrayList<>();
    applications.add(m_application1);
    applications.add(m_application2);
    expect(m_applicationDao.findAll()).andReturn(applications);
    expect(m_monitoringLocationDao.get(m_locationDefinition2.getLocationName())).andReturn(m_locationDefinition2);
    expect(m_applicationDao.findByName("Big Bad Voodoo Daddy Application")).andReturn(null);
    List<OnmsLocationMonitor> monitors = new ArrayList<>();
    monitors.add(m_locationMonitor2_1);
    monitors.add(m_locationMonitor2_2);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition2)).andReturn(monitors);
    for (OnmsMonitoredService service : m_applicationServices1) {
        m_locationMonitorDao.initialize(service.getIpInterface());
        m_locationMonitorDao.initialize(service.getIpInterface().getNode());
    }
    String locationName = m_locationDefinition2.getLocationName();
    String applicationName = "Big Bad Voodoo Daddy Application";
    String monitorId = "";
    String previousLocation = "";
    String timeSpan = "";
    expect(m_monitoredServiceDao.findByApplication(m_application1)).andReturn(m_applicationServices1).times(2);
    expectResourceDaoCall(m_locationMonitor2_1, m_applicationServices1);
    m_easyMockUtils.replayAll();
    DistributedStatusHistoryModel summary = m_service.createHistoryModel(locationName, monitorId, applicationName, timeSpan, previousLocation);
    m_easyMockUtils.verifyAll();
    assertNotNull("summary should not be null", summary);
    assertNotNull("summary locations list should not be null", summary.getLocations());
    assertNotNull("summary applications list should not be null", summary.getApplications());
    assertNotNull("summary chosen location should not be null", summary.getChosenLocation());
    assertNotNull("summary chosen application should not be null", summary.getChosenApplication());
    assertNotNull("summary error list should not be null", summary.getErrors());
    assertEquals("summary locations list size", locationDefinitions.size(), summary.getLocations().size());
    assertEquals("summary applications list size", applications.size(), summary.getApplications().size());
    assertEquals("summary error list size", 1, summary.getErrors().size());
    // Verify sorting of applications
    assertEquals("summary applications 1", m_application1, summary.getApplications().get(0));
    assertEquals("summary applications 2", m_application2, summary.getApplications().get(1));
    // Verify errors
    assertEquals("summary error 1", "Could not find application 'Big Bad Voodoo Daddy Application'", summary.getErrors().get(0));
    // Verify chosen ones
    assertEquals("summary chosen location", m_locationDefinition2, summary.getChosenLocation());
    assertEquals("summary chosen application", m_application1, summary.getChosenApplication());
    // And verify that they are in the lists in the right place
    assertEquals("summary chosen location matches list", summary.getLocations().get(1), summary.getChosenLocation());
    assertEquals("summary chosen application matches list", summary.getApplications().get(0), summary.getChosenApplication());
}
Also used : DistributedStatusHistoryModel(org.opennms.web.svclayer.model.DistributedStatusHistoryModel) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) LinkedList(java.util.LinkedList) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 5 with DistributedStatusHistoryModel

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

the class DefaultDistributedStatusServiceTest method testDetails.

public void testDetails() {
    List<OnmsMonitoringLocation> locationDefinitions = new LinkedList<>();
    locationDefinitions.add(m_locationDefinition1);
    locationDefinitions.add(m_locationDefinition2);
    locationDefinitions.add(m_locationDefinition3);
    expect(m_monitoringLocationDao.findAll()).andReturn(locationDefinitions);
    List<OnmsApplication> applications = new ArrayList<>();
    applications.add(m_application1);
    applications.add(m_application2);
    expect(m_applicationDao.findAll()).andReturn(applications);
    expect(m_monitoringLocationDao.get("Durham")).andReturn(m_locationDefinition2);
    expect(m_applicationDao.findByName("Application 2")).andReturn(m_application2);
    List<OnmsLocationMonitor> monitors = new ArrayList<>();
    monitors.add(m_locationMonitor2_1);
    monitors.add(m_locationMonitor2_2);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition2)).andReturn(monitors);
    for (OnmsMonitoredService service : m_applicationServices2) {
        m_locationMonitorDao.initialize(service.getIpInterface());
        m_locationMonitorDao.initialize(service.getIpInterface().getNode());
    }
    String locationName = m_locationDefinition2.getLocationName();
    String applicationName = m_application2.getName();
    String monitorId = "";
    String timeSpan = "Last Day";
    String previousLocation = "";
    expect(m_monitoredServiceDao.findByApplication(m_application2)).andReturn(m_applicationServices2).times(2);
    expectResourceDaoCall(m_locationMonitor2_1, m_applicationServices2);
    m_easyMockUtils.replayAll();
    DistributedStatusHistoryModel summary = m_service.createHistoryModel(locationName, monitorId, applicationName, timeSpan, previousLocation);
    m_easyMockUtils.verifyAll();
    assertNotNull("summary should not be null", summary);
    assertNotNull("summary locations list should not be null", summary.getLocations());
    assertNotNull("summary applications list should not be null", summary.getApplications());
    assertNotNull("summary chosen location should not be null", summary.getChosenLocation());
    assertNotNull("summary chosen application should not be null", summary.getChosenApplication());
    assertNotNull("summary error list should not be null", summary.getErrors());
    assertEquals("summary locations list size", locationDefinitions.size(), summary.getLocations().size());
    assertEquals("summary applications list size", applications.size(), summary.getApplications().size());
    assertEquals("summary error list size: " + summary.getErrors(), 0, summary.getErrors().size());
    // Verify sorting of applications
    assertEquals("summary applications 1", m_application1, summary.getApplications().get(0));
    assertEquals("summary applications 2", m_application2, summary.getApplications().get(1));
    // Verify chosen ones
    assertEquals("summary chosen location", m_locationDefinition2, summary.getChosenLocation());
    assertEquals("summary chosen application", m_application2, summary.getChosenApplication());
    // And verify that they are in the lists in the right place
    assertEquals("summary chosen location matches list", summary.getLocations().get(1), summary.getChosenLocation());
    assertEquals("summary chosen application matches list", summary.getApplications().get(1), summary.getChosenApplication());
    assertEquals("graph URL map size", 1, summary.getServiceGraphs().size());
    assertNotNull("graph 0 URL should not be null", summary.getServiceGraphs().iterator().next().getUrl());
}
Also used : DistributedStatusHistoryModel(org.opennms.web.svclayer.model.DistributedStatusHistoryModel) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) LinkedList(java.util.LinkedList) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Aggregations

DistributedStatusHistoryModel (org.opennms.web.svclayer.model.DistributedStatusHistoryModel)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)4 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)4 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)4 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)4 RelativeTimePeriod (org.opennms.web.svclayer.model.RelativeTimePeriod)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1