Search in sources :

Example 46 with OnmsCategory

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

the class DefaultAdminCategoryService method removeCategory.

/** {@inheritDoc} */
@Override
public void removeCategory(String categoryIdString) {
    OnmsCategory category = findCategory(categoryIdString);
    CategoryAndMemberNodes cat = getCategory(categoryIdString);
    for (OnmsNode adriftNode : cat.getMemberNodes()) {
        notifyCategoryChange(adriftNode, new String[0], new String[] { category.getName() });
    }
    m_categoryDao.delete(category);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 47 with OnmsCategory

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

the class DefaultSiteStatusServiceIT method createOutageForNodeInCategory.

private void createOutageForNodeInCategory(String categoryName) {
    OnmsCategory category = m_categoryDao.findByName(categoryName);
    Collection<OnmsNode> nodes = m_nodeDao.findByCategory(category);
    assertNotNull(nodes);
    assertFalse(nodes.isEmpty());
    /*
         * There should only be 1 node per category based on the set of
         * default nodes that are stored in {@link DatabasePopulator}
         */
    assertEquals(1, nodes.size());
    OnmsNode node = nodes.iterator().next();
    node.visit(new AbstractEntityVisitor() {

        @Override
        public void visitMonitoredService(OnmsMonitoredService monSvc) {
            createOutageForService(monSvc);
        }
    });
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 48 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory 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 49 with OnmsCategory

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

Example 50 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory 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>();
    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

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)54 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)6 Path (javax.ws.rs.Path)6 HashSet (java.util.HashSet)4 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)4 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)4 Transactional (org.springframework.transaction.annotation.Transactional)4 StringReader (java.io.StringReader)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)3 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)3 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)3 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2