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);
}
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);
}
});
}
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);
}
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);
}
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();
}
Aggregations