Search in sources :

Example 1 with AggregateStatusView

use of org.opennms.netmgt.model.AggregateStatusView in project opennms by OpenNMS.

the class SiteStatusViewController method handleRequestInternal.

/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    ModelAndView mav = new ModelAndView("siteStatus");
    String statusView = req.getParameter("statusView");
    String statusSite = req.getParameter("statusSite");
    String nodeId = req.getParameter("nodeid");
    AggregateStatusView view = null;
    try {
        view = m_service.createAggregateStatusView(statusView);
    } catch (ObjectRetrievalFailureException e) {
        SiteStatusViewError viewError = createSiteStatusViewError((String) e.getIdentifier(), e.getMessage());
        return new ModelAndView("siteStatusError", "error", viewError);
    }
    Collection<AggregateStatus> aggrStati;
    if (nodeId != null && WebSecurityUtils.safeParseInt(nodeId) > 0) {
        aggrStati = m_service.createAggregateStatusesUsingNodeId(WebSecurityUtils.safeParseInt(nodeId), statusView);
    } else if (statusSite == null) {
        aggrStati = m_service.createAggregateStatuses(view);
    } else {
        aggrStati = m_service.createAggregateStatuses(view, statusSite);
        // Don't persist this, convenience for display only.
        view.setColumnValue(statusSite);
    }
    mav.addObject("view", view);
    mav.addObject("stati", aggrStati);
    return mav;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView)

Example 2 with AggregateStatusView

use of org.opennms.netmgt.model.AggregateStatusView in project opennms by OpenNMS.

the class DefaultSiteStatusViewService method createAggregateStatusView.

/**
 * {@inheritDoc}
 *
 * This creator looks up a configured status view by name and calls the creator that
 * accepts the AggregateStatusView model object.
 * @see org.opennms.web.svclayer.SiteStatusViewService#createAggregateStatusView(java.lang.String)
 */
@Override
public AggregateStatusView createAggregateStatusView(String statusViewName) {
    AggregateStatusView statusView = new AggregateStatusView();
    statusViewName = (statusViewName == null ? m_siteStatusViewConfigDao.getDefaultView().getName() : statusViewName);
    View view = m_siteStatusViewConfigDao.getView(statusViewName);
    statusView.setName(statusViewName);
    statusView.setColumnName(view.getColumnName());
    statusView.setColumnValue(view.getColumnValue().orElse(null));
    statusView.setTableName(view.getTableName());
    Set<AggregateStatusDefinition> statusDefs = getAggregateStatusDefinitionsForView(view);
    statusView.setStatusDefinitions(statusDefs);
    return statusView;
}
Also used : AggregateStatusDefinition(org.opennms.netmgt.model.AggregateStatusDefinition) View(org.opennms.netmgt.config.siteStatusViews.View) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView)

Example 3 with AggregateStatusView

use of org.opennms.netmgt.model.AggregateStatusView in project opennms by OpenNMS.

the class DefaultSiteStatusViewService method getAggregateStatus.

/**
 * {@inheritDoc}
 */
@Override
public AggregateStatus getAggregateStatus(String statusViewName, String statusSite, String rowLabel) {
    AggregateStatusView statusView = createAggregateStatusView(statusViewName);
    Collection<AggregateStatus> stati = createAggregateStatuses(statusView, statusSite);
    for (AggregateStatus status : stati) {
        if (status.getLabel().equals(rowLabel)) {
            return status;
        }
    }
    throw new DataRetrievalFailureException("Unable to locate row: " + rowLabel + " for status view: " + statusViewName);
}
Also used : AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus) DataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView)

Example 4 with AggregateStatusView

use of org.opennms.netmgt.model.AggregateStatusView in project opennms by OpenNMS.

the class DefaultSiteStatusServiceIT method testCreateAggregateStatusView.

@Test
@Transactional
public void testCreateAggregateStatusView() {
    m_databasePopulator.populateDatabase();
    AggregateStatusView view = m_aggregateService.createAggregateStatusView(null);
    assertNotNull(view);
    assertFalse(view.getStatusDefinitions().isEmpty());
    m_databasePopulator.resetDatabase();
}
Also used : AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with AggregateStatusView

use of org.opennms.netmgt.model.AggregateStatusView in project opennms by OpenNMS.

the class DefaultSiteStatusServiceIT method testCreateAggregateStatusUsingBuilding.

@Test
@Transactional
public void testCreateAggregateStatusUsingBuilding() {
    m_databasePopulator.populateDatabase();
    createOutageForNodeInCategory("Routers");
    createOutageForNodeInCategory("Servers");
    Set<AggregateStatusDefinition> defs = new LinkedHashSet<>();
    AggregateStatusDefinition definition;
    definition = new AggregateStatusDefinition("Routers", Collections.singleton(new OnmsCategory("Routers")));
    defs.add(definition);
    definition = new AggregateStatusDefinition("Switches", Collections.singleton(new OnmsCategory("Switches")));
    defs.add(definition);
    definition = new AggregateStatusDefinition("Servers", Collections.singleton(new OnmsCategory("Servers")));
    defs.add(definition);
    // AggregateStatusDefinition definition;
    // definition = new AggregateStatusDefinition("LB/Router", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[]{ new OnmsCategory("DEV_ROUTER"), new OnmsCategory("DEV_LOADBAL") })));
    // defs.add(definition);
    // definition = new AggregateStatusDefinition("Access Controller", Collections.singleton(new OnmsCategory("DEV_AC")));
    // defs.add(definition);
    // definition = new AggregateStatusDefinition("Switches", Collections.singleton(new OnmsCategory("DEV_SWITCH")));
    // defs.add(definition);
    // definition = new AggregateStatusDefinition("Access Points", Collections.singleton(new OnmsCategory("DEV_AP")));
    // defs.add(definition);
    // definition = new AggregateStatusDefinition("BCPC", Collections.singleton(new OnmsCategory("DEV_BCPC")));
    // defs.add(definition);
    AggregateStatusView view = new AggregateStatusView();
    view.setName("building");
    view.setColumnName("building");
    view.setColumnValue("HQ");
    view.setStatusDefinitions(defs);
    List<AggregateStatus> aggrStati = new ArrayList<AggregateStatus>(m_aggregateService.createAggregateStatuses(view));
    AggregateStatus status;
    status = aggrStati.get(0);
    assertEquals("Routers", status.getLabel());
    assertEquals(AggregateStatus.NODES_ARE_DOWN, status.getStatus());
    status = aggrStati.get(1);
    assertEquals("Switches", status.getLabel());
    assertEquals(AggregateStatus.ALL_NODES_UP, status.getStatus());
    status = aggrStati.get(2);
    assertEquals("Servers", status.getLabel());
    assertEquals(AggregateStatus.NODES_ARE_DOWN, status.getStatus());
    // status = aggrStati.get(3);
    // assertEquals(AggregateStatus.NODES_ARE_DOWN, status.getStatus());
    // assertEquals(new Integer(6), status.getDownEntityCount());
    // 
    // status = aggrStati.get(4);
    // assertEquals(AggregateStatus.ALL_NODES_UP, status.getStatus());
    m_databasePopulator.resetDatabase();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) AggregateStatusDefinition(org.opennms.netmgt.model.AggregateStatusDefinition) ArrayList(java.util.ArrayList) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)6 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)4 Test (org.junit.Test)3 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1 View (org.opennms.netmgt.config.siteStatusViews.View)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 DataRetrievalFailureException (org.springframework.dao.DataRetrievalFailureException)1 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1