Search in sources :

Example 1 with AggregateStatusDefinition

use of org.opennms.netmgt.model.AggregateStatusDefinition 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<AggregateStatus>();
    /*
         * 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 2 with AggregateStatusDefinition

use of org.opennms.netmgt.model.AggregateStatusDefinition 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 AggregateStatusDefinition

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

the class DefaultSiteStatusViewService method getAggregateStatusDefinitionsForView.

private Set<AggregateStatusDefinition> getAggregateStatusDefinitionsForView(View view) {
    Set<AggregateStatusDefinition> statusDefs = new LinkedHashSet<AggregateStatusDefinition>();
    //Loop over the defined site status rows
    for (RowDef rowDef : view.getRows()) {
        AggregateStatusDefinition def = new AggregateStatusDefinition();
        def.setName(rowDef.getLabel());
        def.setReportCategory(rowDef.getReportCategory());
        Set<OnmsCategory> categories = getCategoriesForRowDef(rowDef);
        def.setCategories(categories);
        statusDefs.add(def);
    }
    return statusDefs;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) AggregateStatusDefinition(org.opennms.netmgt.model.AggregateStatusDefinition) RowDef(org.opennms.netmgt.config.siteStatusViews.RowDef)

Example 4 with AggregateStatusDefinition

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

the class DefaultSiteStatusServiceTest method testCreateAggregateStatusUsingNodeId.

@Test
public void testCreateAggregateStatusUsingNodeId() {
    Collection<AggregateStatus> aggrStati;
    Collection<AggregateStatusDefinition> defs = new HashSet<AggregateStatusDefinition>();
    OnmsCategory catRouters = new OnmsCategory("routers");
    OnmsCategory catSwitches = new OnmsCategory("switches");
    AggregateStatusDefinition definition = new AggregateStatusDefinition("Routers/Switches", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { catRouters, catSwitches })));
    defs.add(definition);
    OnmsCategory catServers = new OnmsCategory("servers");
    definition = new AggregateStatusDefinition("Servers", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { catServers })));
    defs.add(definition);
    DefaultSiteStatusViewService aggregateSvc = new DefaultSiteStatusViewService();
    aggregateSvc.setNodeDao(m_nodeDao);
    aggregateSvc.setCategoryDao(m_categoryDao);
    aggregateSvc.setSiteStatusViewConfigDao(m_siteStatusViewConfigDao);
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.getAssetRecord().setBuilding("HQ");
    List<OnmsNode> nodes = new ArrayList<OnmsNode>();
    nodes.add(node);
    for (AggregateStatusDefinition def : defs) {
        expect(m_nodeDao.findAllByVarCharAssetColumnCategoryList("building", "HQ", def.getCategories())).andReturn(nodes);
    }
    for (OnmsNode n : nodes) {
        expect(m_nodeDao.load(n.getId())).andReturn(n);
    }
    replay(m_nodeDao);
    expect(m_categoryDao.findByName("switches")).andReturn(catSwitches);
    expect(m_categoryDao.findByName("routers")).andReturn(catRouters);
    expect(m_categoryDao.findByName("servers")).andReturn(catServers);
    replay(m_categoryDao);
    List<RowDef> rows = new ArrayList<>();
    RowDef rowDef = new RowDef();
    Category category = new Category();
    category.setName("servers");
    rowDef.addCategory(category);
    rows.add(rowDef);
    rowDef = new RowDef();
    category = new Category();
    category.setName("switches");
    rowDef.addCategory(category);
    category = new Category();
    category.setName("routers");
    rowDef.addCategory(category);
    rows.add(rowDef);
    View view = new View();
    view.setRows(rows);
    expect(m_siteStatusViewConfigDao.getView("building")).andReturn(view);
    replay(m_siteStatusViewConfigDao);
    aggrStati = aggregateSvc.createAggregateStatusesUsingNodeId(node.getId(), "building");
    verify(m_nodeDao);
    verify(m_categoryDao);
    verify(m_siteStatusViewConfigDao);
    assertNotNull(aggrStati);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Category(org.opennms.netmgt.config.siteStatusViews.Category) ArrayList(java.util.ArrayList) RowDef(org.opennms.netmgt.config.siteStatusViews.RowDef) View(org.opennms.netmgt.config.siteStatusViews.View) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) AggregateStatusDefinition(org.opennms.netmgt.model.AggregateStatusDefinition) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 5 with AggregateStatusDefinition

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

the class DefaultSiteStatusServiceTest method testCreateAggregateStatusUsingBuilding.

@Test
public void testCreateAggregateStatusUsingBuilding() {
    Collection<AggregateStatus> aggrStati;
    Collection<AggregateStatusDefinition> defs = new HashSet<AggregateStatusDefinition>();
    AggregateStatusDefinition definition = new AggregateStatusDefinition("Routers/Switches", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { new OnmsCategory("routers"), new OnmsCategory("switches") })));
    defs.add(definition);
    definition = new AggregateStatusDefinition("Servers", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { new OnmsCategory("servers") })));
    defs.add(definition);
    DefaultSiteStatusViewService aggregateSvc = new DefaultSiteStatusViewService();
    aggregateSvc.setNodeDao(m_nodeDao);
    OnmsNode node = new OnmsNode();
    List<OnmsNode> nodes = new ArrayList<OnmsNode>();
    nodes.add(node);
    for (AggregateStatusDefinition def : defs) {
        expect(m_nodeDao.findAllByVarCharAssetColumnCategoryList("building", "HQ", def.getCategories())).andReturn(nodes);
    }
    replay(m_nodeDao);
    AggregateStatusView view = new AggregateStatusView();
    view.setColumnName("building");
    view.setColumnValue("HQ");
    view.setTableName("assets");
    view.setStatusDefinitions(new LinkedHashSet<AggregateStatusDefinition>(defs));
    aggrStati = aggregateSvc.createAggregateStatusUsingAssetColumn(view);
    verify(m_nodeDao);
    assertNotNull(aggrStati);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ArrayList(java.util.ArrayList) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) AggregateStatusDefinition(org.opennms.netmgt.model.AggregateStatusDefinition) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Aggregations

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