use of org.opennms.netmgt.xml.rtc.Node in project opennms by OpenNMS.
the class Category method getServiceCounts.
/**
* Convenience method to count the number of services under a category and
* the number of those services that are currently down.
*
* @param category a {@link org.opennms.netmgt.xml.rtc.Category} object.
* @return an array of long.
*/
protected static long[] getServiceCounts(final org.opennms.netmgt.xml.rtc.Category category) {
if (category == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
long count = 0;
long downCount = 0;
for (Node node : category.getNode()) {
count += node.getNodesvccount();
downCount += node.getNodesvcdowncount();
}
return new long[] { count, downCount };
}
use of org.opennms.netmgt.xml.rtc.Node in project opennms by OpenNMS.
the class LegacyEuiLevelMapper method convertToEuiLevelXML.
/**
* Convert the 'RTCCategory' object to a 'EuiLevel' object.
*
* @param rtcCat
* the RTCCategory to be converted
* @return a {@link org.opennms.netmgt.xml.rtc.EuiLevel} object.
*/
public EuiLevel convertToEuiLevelXML(RTCCategory rtcCat) {
// current time
Date curDate = new Date();
long curTime = curDate.getTime();
// get the rolling window
long rWindow = 24L * 60L * 60L * 1000L;
LOG.debug("curdate: {}", curDate);
// create the data
EuiLevel level = new EuiLevel();
// set created in m_header and add to level
m_header.setCreated(EventConstants.formatToString(curDate));
level.setHeader(m_header);
org.opennms.netmgt.xml.rtc.Category levelCat = new org.opennms.netmgt.xml.rtc.Category();
// get a handle to data
synchronized (m_dataMgr) {
// category label
levelCat.setCatlabel(rtcCat.getLabel());
// availability value for this category
levelCat.setCatvalue(m_dataMgr.getValue(rtcCat, curTime, rWindow));
// nodes in this category
for (int nodeID : m_dataMgr.getNodes(rtcCat)) {
Node levelNode = new Node();
levelNode.setNodeid(nodeID);
// value for this node for this category
levelNode.setNodevalue(m_dataMgr.getValue(nodeID, rtcCat, curTime, rWindow));
// node service count
levelNode.setNodesvccount(m_dataMgr.getServiceCount(nodeID, rtcCat));
// node service down count
levelNode.setNodesvcdowncount(m_dataMgr.getServiceDownCount(nodeID, rtcCat));
// add the node
levelCat.getNode().add(levelNode);
}
}
// add category
level.getCategory().add(levelCat);
return level;
}
use of org.opennms.netmgt.xml.rtc.Node in project opennms by OpenNMS.
the class AvailabilityServiceIT method categoryIsFullyAvailableWhenNoServicesArePresent.
@Test
public void categoryIsFullyAvailableWhenNoServicesArePresent() throws Exception {
final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
EasyMock.expect(rtcCat.getLabel()).andReturn("Routers");
// This nodeid should not exist in the database
EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(99999));
EasyMock.replay(rtcCat);
final EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
assertEquals(1, euiLevel.getCategory().size());
final Category category = euiLevel.getCategory().get(0);
assertEquals(100.0, category.getCatvalue(), 0.001);
assertEquals(1, category.getNode().size());
final Node node = category.getNode().get(0);
assertEquals(100.0, node.getNodevalue(), 0.001);
assertEquals(0, node.getNodesvccount());
assertEquals(0, node.getNodesvcdowncount());
}
use of org.opennms.netmgt.xml.rtc.Node in project opennms by OpenNMS.
the class AvailabilityServiceHibernateImpl method getEuiLevel.
/**
* Optimized method for calculating the category statistics.
*
* We start off by retrieving outages affecting the nodes and services
* in the given category, and group these by node id.
*
* Using the outages, we calculate node-level statistics
* and tally the values to calculate the category statistics.
*/
@Override
@Transactional(readOnly = true)
public synchronized EuiLevel getEuiLevel(RTCCategory category) {
final Header header = new Header();
header.setVer("1.9a");
header.setMstation("");
// current time
final Date curDate = new Date();
final long curTime = curDate.getTime();
// get the rolling window
final long rWindow = 24L * 60L * 60L * 1000L;
LOG.debug("Retrieving availability statistics for {} with current date: {} and rolling window: {}", category.getLabel(), curDate, rWindow);
// create the data
final EuiLevel level = new EuiLevel();
// set created in m_header and add to level
header.setCreated(EventConstants.formatToString(curDate));
level.setHeader(header);
final Category levelCat = new Category();
// category label
levelCat.setCatlabel(category.getLabel());
double outageTimeInCategory = 0.0;
int numServicesInCategory = 0;
// window bounds
final Date windowStart = new Date(curTime - rWindow);
final Date windowEnd = new Date(curTime);
// category specifics
final List<Integer> nodeIds = getNodes(category);
final List<String> serviceNames = category.getServices();
// retrieve the outages associated with the given nodes, only retrieving those that affect our window
final Map<Integer, List<OnmsOutage>> outagesByNode = getOutages(nodeIds, serviceNames, windowStart, windowEnd);
// calculate the node level statistics
for (final int nodeId : nodeIds) {
List<OnmsOutage> outages = outagesByNode.get(nodeId);
if (outages == null) {
outages = Lists.newArrayList();
}
// sum the outage time
final double outageTime = getOutageTimeInWindow(outages, windowStart, windowEnd);
// determine the number of services
final int numServices = getNumServices(nodeId, serviceNames);
// count the number of outstanding outages
final long numServicesDown = outages.stream().filter(outage -> outage.getIfRegainedService() == null).count();
final Node levelNode = new Node();
levelNode.setNodeid(nodeId);
// value for this node for this category
levelNode.setNodevalue(RTCUtils.getOutagePercentage(outageTime, rWindow, numServices));
// node service count
levelNode.setNodesvccount(numServices);
// node service down count
levelNode.setNodesvcdowncount(numServicesDown);
// add the node
levelCat.getNode().add(levelNode);
// update the category statistics
numServicesInCategory += numServices;
outageTimeInCategory += outageTime;
}
// calculate the outage percentage using tallied values
levelCat.setCatvalue(RTCUtils.getOutagePercentage(outageTimeInCategory, rWindow, numServicesInCategory));
// add category
level.getCategory().add(levelCat);
LOG.debug("Done retrieving availability statistics for {} with {} services.", category.getLabel(), numServicesInCategory);
return level;
}
Aggregations