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