use of org.opennms.netmgt.model.AbstractEntityVisitor in project opennms by OpenNMS.
the class Collectd method scheduleNode.
private void scheduleNode(final int nodeId, final boolean existing) {
OnmsNode node = m_nodeDao.getHierarchy(nodeId);
node.visit(new AbstractEntityVisitor() {
@Override
public void visitMonitoredService(OnmsMonitoredService monSvc) {
scheduleInterface(monSvc.getIpInterface(), monSvc.getServiceName(), existing);
}
});
}
use of org.opennms.netmgt.model.AbstractEntityVisitor 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.AbstractEntityVisitor in project opennms by OpenNMS.
the class FilterResourceWalker method walk.
/**
* <p>walk</p>
*/
public void walk() {
EntityVisitor visitor = new AbstractEntityVisitor() {
@Override
public void visitNode(OnmsNode node) {
walk(node);
}
};
SortedMap<Integer, String> map = getFilterDao().getNodeMap(m_filter);
for (final Integer nodeId : map.keySet()) {
final OnmsNode node = getNodeDao().load(nodeId);
visitor.visitNode(node);
}
}
use of org.opennms.netmgt.model.AbstractEntityVisitor in project opennms by OpenNMS.
the class JdbcFilterDaoIT method testWalkNodes.
@Test
public void testWalkNodes() throws Exception {
final List<OnmsNode> nodes = new ArrayList<>();
EntityVisitor visitor = new AbstractEntityVisitor() {
@Override
public void visitNode(OnmsNode node) {
nodes.add(node);
}
};
FilterWalker walker = new FilterWalker();
walker.setFilterDao(m_dao);
walker.setNodeDao(m_nodeDao);
walker.setFilter("ipaddr == '10.1.1.1'");
walker.setVisitor(visitor);
walker.walk();
assertEquals("node list size", 1, nodes.size());
}
use of org.opennms.netmgt.model.AbstractEntityVisitor in project opennms by OpenNMS.
the class DefaultRrdSummaryService method getSummary.
/**
* <p>getSummary</p>
*
* @param filterRule a {@link java.lang.String} object.
* @param startTime a long.
* @param endTime a long.
* @param attributeSieve a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.config.attrsummary.Summary} object.
*/
public Summary getSummary(String filterRule, final long startTime, final long endTime, final String attributeSieve) {
m_stats.begin("getSummary");
try {
final SummaryBuilder bldr = new SummaryBuilder();
FilterWalker walker = new FilterWalker();
walker.setFilterDao(m_filterDao);
walker.setNodeDao(m_nodeDao);
walker.setFilter(filterRule);
walker.setVisitor(new AbstractEntityVisitor() {
@Override
public void visitNode(OnmsNode node) {
OnmsResource nodeResource = getResourceForNode(node);
bldr.pushResource(node.getLabel());
for (OnmsResource child : getChildResources1(nodeResource)) {
if (child.getResourceType() instanceof NodeSnmpResourceType) {
addAttributes(getResourceGraphAttributes(child));
}
}
for (OnmsResource child : getChildResources2(nodeResource)) {
if (!(child.getResourceType() instanceof NodeSnmpResourceType)) {
addResource(child);
}
}
bldr.popResource();
}
private Collection<RrdGraphAttribute> getResourceGraphAttributes(OnmsResource child) {
String op = "getResourceGraphAttributes-" + child.getResourceType().getName();
m_stats.begin(op);
try {
return child.getRrdGraphAttributes().values();
} finally {
m_stats.end(op);
}
}
private List<OnmsResource> getChildResources1(OnmsResource nodeResource) {
m_stats.begin("getChildResources1");
try {
return nodeResource.getChildResources();
} finally {
m_stats.end("getChildResources1");
}
}
private List<OnmsResource> getChildResources2(OnmsResource nodeResource) {
m_stats.begin("getChildResources2");
try {
return nodeResource.getChildResources();
} finally {
m_stats.end("getChildResources2");
}
}
private OnmsResource getResourceForNode(OnmsNode node) {
m_stats.begin("getResourceForNode");
try {
return m_resourceDao.getResourceForNode(node);
} finally {
m_stats.end("getResourceForNode");
}
}
private void addResource(OnmsResource resource) {
addResource(resource, resource.getLabel());
}
private void addResource(OnmsResource resource, String label) {
Collection<RrdGraphAttribute> attrs = getResourceGraphAttributes(resource);
if (attrs.size() > 0) {
bldr.pushResource(label);
addAttributes(attrs);
bldr.popResource();
}
}
private void addAttributes(Collection<RrdGraphAttribute> attrs) {
m_stats.begin("addAttributes");
try {
for (RrdGraphAttribute attr : attrs) {
if (attr.getName().matches(attributeSieve)) {
bldr.addAttribute(attr.getName());
double[] values = getValues(attr);
bldr.setMin(values[0]);
bldr.setAverage(values[1]);
bldr.setMax(values[2]);
}
}
} finally {
m_stats.end("addAttributes");
}
}
private double[] getValues(RrdGraphAttribute attr) {
m_stats.begin("getValues");
try {
return m_rrdDao.getPrintValues(attr, "AVERAGE", startTime * 1000, endTime * 1000, "MIN", "AVERAGE", "MAX");
} finally {
m_stats.end("getValues");
}
}
});
walker.walk();
return bldr.getSummary();
} finally {
m_stats.end("getSummary");
}
}
Aggregations