Search in sources :

Example 1 with AggregateStatus

use of org.opennms.web.svclayer.model.AggregateStatus 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 AggregateStatus

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

the class DefaultNodeListService method createNodeList.

/**
 * {@inheritDoc}
 */
public NodeListModel createNodeList(NodeListCommand command, boolean sanitizeLabels) {
    Collection<OnmsNode> onmsNodes = null;
    /*
         * All search queries can be done solely with
         * criteria, so we build a common criteria object with common
         * restrictions and sort options.  Each specific search query
         * adds its own criteria restrictions (if any).
         * 
         * A set of booleans is maintained for aliases that might be
         * added in multiple places to ensure we don't add the same alias
         * multiple times.
         */
    OnmsCriteria criteria = new OnmsCriteria(OnmsNode.class, "node");
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    criteria.add(Restrictions.ne("node.type", "D"));
    // Add additional criteria based on the command object
    addCriteriaForCommand(criteria, command);
    criteria.addOrder(Order.asc("node.label"));
    onmsNodes = m_nodeDao.findMatching(criteria);
    if (command.getNodesWithDownAggregateStatus()) {
        AggregateStatus as = new AggregateStatus(onmsNodes);
        onmsNodes = as.getDownNodes();
    }
    if (sanitizeLabels) {
        for (OnmsNode node : onmsNodes) {
            node.setLabel(WebSecurityUtils.sanitizeString(node.getLabel()));
        }
    }
    return createModelForNodes(command, onmsNodes);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus)

Example 3 with AggregateStatus

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

the class DefaultSiteStatusViewService method createAggregateStatusUsingAssetColumn.

/**
 * <p>createAggregateStatusUsingAssetColumn</p>
 *
 * @param statusView a {@link org.opennms.netmgt.model.AggregateStatusView} object.
 * @return a {@link java.util.Collection} object.
 */
public Collection<AggregateStatus> createAggregateStatusUsingAssetColumn(AggregateStatusView statusView) {
    if (statusView == null) {
        throw new IllegalArgumentException("statusView argument cannot be null");
    }
    /*
         * We'll return this collection populated with all the aggregated statuss for the
         * devices in the building (site) by for each group of categories.
         */
    Collection<AggregateStatus> stati = new ArrayList<>();
    /*
         * Iterate over the status definitions and create aggregated statuss
         */
    for (AggregateStatusDefinition statusDef : statusView.getStatusDefinitions()) {
        Collection<OnmsNode> nodes = m_nodeDao.findAllByVarCharAssetColumnCategoryList(statusView.getColumnName(), statusView.getColumnValue(), statusDef.getCategories());
        AggregateStatus status = new AggregateStatus(new HashSet<OnmsNode>(nodes));
        status.setLabel(statusDef.getName());
        status.setLink(createNodePageUrl(statusView, status));
        stati.add(status);
    }
    return stati;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) AggregateStatusDefinition(org.opennms.netmgt.model.AggregateStatusDefinition) ArrayList(java.util.ArrayList) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus)

Example 4 with AggregateStatus

use of org.opennms.web.svclayer.model.AggregateStatus 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 5 with AggregateStatus

use of org.opennms.web.svclayer.model.AggregateStatus 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

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