Search in sources :

Example 1 with AbstractEntityVisitor

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);
        }
    });
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 2 with AbstractEntityVisitor

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);
        }
    });
}
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 3 with AbstractEntityVisitor

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);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor)

Example 4 with AbstractEntityVisitor

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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ArrayList(java.util.ArrayList) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) Test(org.junit.Test)

Example 5 with AbstractEntityVisitor

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");
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) FilterWalker(org.opennms.netmgt.dao.support.FilterWalker) Collection(java.util.Collection) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) List(java.util.List) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) NodeSnmpResourceType(org.opennms.netmgt.dao.support.NodeSnmpResourceType)

Aggregations

AbstractEntityVisitor (org.opennms.netmgt.model.AbstractEntityVisitor)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 EntityVisitor (org.opennms.netmgt.model.EntityVisitor)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Test (org.junit.Test)1 FilterWalker (org.opennms.netmgt.dao.support.FilterWalker)1 NodeSnmpResourceType (org.opennms.netmgt.dao.support.NodeSnmpResourceType)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsResource (org.opennms.netmgt.model.OnmsResource)1 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)1