Search in sources :

Example 11 with NodeDao

use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.

the class WSManCollectorTest method canSuccesfullyCollectFromGroupWithNoAttributes.

@Test
public void canSuccesfullyCollectFromGroupWithNoAttributes() throws CollectionInitializationException, CollectionException {
    OnmsNode node = mock(OnmsNode.class);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.get(0)).thenReturn(node);
    WSManConfigDao configDao = mock(WSManConfigDao.class);
    when(configDao.getAgentConfig(any())).thenReturn(new Definition());
    Collection collection = new Collection();
    WSManDataCollectionConfigDao dataCollectionConfigDao = mock(WSManDataCollectionConfigDao.class);
    when(dataCollectionConfigDao.getCollectionByName("default")).thenReturn(collection);
    WsManCollector collector = new WsManCollector();
    collector.setWSManClientFactory(mock(WSManClientFactory.class));
    collector.setWSManConfigDao(configDao);
    collector.setWSManDataCollectionConfigDao(dataCollectionConfigDao);
    collector.setNodeDao(nodeDao);
    CollectionAgent agent = mock(CollectionAgent.class);
    when(agent.getAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
    when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
    Map<String, Object> collectionParams = Maps.newHashMap();
    collectionParams.put("collection", "default");
    collectionParams.putAll(collector.getRuntimeAttributes(agent, collectionParams));
    CollectionSet collectionSet = collector.collect(agent, collectionParams);
    assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    assertEquals(0, CollectionSetUtils.getAttributesByName(collectionSet).size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Definition(org.opennms.netmgt.config.wsman.Definition) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) NodeDao(org.opennms.netmgt.dao.api.NodeDao) Collection(org.opennms.netmgt.config.wsman.Collection) WSManDataCollectionConfigDao(org.opennms.netmgt.dao.WSManDataCollectionConfigDao) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) Test(org.junit.Test)

Example 12 with NodeDao

use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.

the class CollectdTest method setUp.

@Before
public void setUp() throws Exception {
    EventIpcManager m_eventIpcManager;
    NodeDao m_nodeDao;
    MockLogAppender.setupLogging();
    Resource threshdResource = new ClassPathResource("/etc/thresholds.xml");
    File homeDir = threshdResource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    // Test setup
    m_eventIpcManager = m_easyMockUtils.createMock(EventIpcManager.class);
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_nodeDao = m_easyMockUtils.createMock(NodeDao.class);
    m_ipIfDao = m_easyMockUtils.createMock(IpInterfaceDao.class);
    m_scheduler = new MockScheduler();
    m_eventIpcManager.addEventListener(isA(EventListener.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.addEventListener(isA(EventListener.class), isACollection(String.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.addEventListener(isA(EventListener.class), isA(String.class));
    expectLastCall().anyTimes();
    m_eventIpcManager.removeEventListener(isA(EventListener.class));
    expectLastCall().anyTimes();
    // Mock the FilterDao without using EasyMockUtils so that it can be verified separately
    m_filterDao = EasyMock.createMock(FilterDao.class);
    List<InetAddress> allIps = new ArrayList<InetAddress>();
    allIps.add(addr("192.168.1.1"));
    allIps.add(addr("192.168.1.2"));
    allIps.add(addr("192.168.1.3"));
    allIps.add(addr("192.168.1.4"));
    allIps.add(addr("192.168.1.5"));
    expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE *.*.*.*")).andReturn(allIps).anyTimes();
    expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE 1.1.1.1")).andReturn(new ArrayList<InetAddress>(0)).anyTimes();
    EasyMock.replay(m_filterDao);
    FilterDaoFactory.setInstance(m_filterDao);
    // This call will also ensure that the poll-outages.xml file can parse IPv4
    // and IPv6 addresses.
    Resource resource = new ClassPathResource("etc/poll-outages.xml");
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
    factory.afterPropertiesSet();
    PollOutagesConfigFactory.setInstance(factory);
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd = new Collectd();
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setIpInterfaceDao(m_ipIfDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setScheduler(m_scheduler);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(ConfigurationTestUtils.getInputStreamForConfigFile("thresholds.xml")));
}
Also used : MockScheduler(org.opennms.netmgt.poller.mock.MockScheduler) DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) ArrayList(java.util.ArrayList) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) NodeDao(org.opennms.netmgt.dao.api.NodeDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) EventIpcManager(org.opennms.netmgt.events.api.EventIpcManager) EventListener(org.opennms.netmgt.events.api.EventListener) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) File(java.io.File) InetAddress(java.net.InetAddress) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Before(org.junit.Before)

Example 13 with NodeDao

use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.

the class RrdSummaryControllerTest method canGenerateEmptySummary.

/**
     * Verifies that an empty summary can be generated so an existing
     * node without any resources.
     */
@Test
public void canGenerateEmptySummary() {
    // Return a single node when called using the given filter
    String rule = "ipaddr iplike 172.20.1.1";
    FilterDao filterDao = mock(FilterDao.class);
    when(filterDao.getNodeMap(rule)).thenReturn(ImmutableSortedMap.of(1, "node1"));
    OnmsNode node = mock(OnmsNode.class);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.load(1)).thenReturn(node);
    OnmsResource resource = mock(OnmsResource.class);
    ResourceDao resourceDao = mock(ResourceDao.class);
    when(resourceDao.getResourceForNode(node)).thenReturn(resource);
    // Use our mocks
    m_rrdSummaryService.setFilterDao(filterDao);
    m_rrdSummaryService.setNodeDao(nodeDao);
    m_rrdSummaryService.setResourceDao(resourceDao);
    // Building the summary spec.
    SummarySpecification summarySpec = new SummarySpecification();
    summarySpec.setFilterRule("ipaddr iplike 172.20.1.1");
    summarySpec.setStartTime(1472746964);
    summarySpec.setEndTime(1473265364);
    summarySpec.setAttributeSieve(".*");
    // Invoke the controller
    HttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mv = m_controller.processFormSubmission(response, summarySpec);
    Summary summary = (Summary) mv.getModel().get("summary");
    // Verify the response
    assertEquals(0, summary.getResources().size());
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) ModelAndView(org.springframework.web.servlet.ModelAndView) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Summary(org.opennms.netmgt.config.attrsummary.Summary) ResourceDao(org.opennms.netmgt.dao.api.ResourceDao) SummarySpecification(org.opennms.web.svclayer.model.SummarySpecification) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 14 with NodeDao

use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.

the class DefaultProvisionService method createUndiscoveredNode.

/** {@inheritDoc} */
@Transactional
@Override
public OnmsNode createUndiscoveredNode(final String ipAddress, final String foreignSource, final String locationString) {
    final String effectiveForeignSource = foreignSource == null ? FOREIGN_SOURCE_FOR_DISCOVERED_NODES : foreignSource;
    final String effectiveLocationName = MonitoringLocationUtils.isDefaultLocationName(locationString) ? null : locationString;
    final OnmsNode node = new UpsertTemplate<OnmsNode, NodeDao>(m_transactionManager, m_nodeDao) {

        @Override
        protected OnmsNode query() {
            // Find all of the nodes in the target requisition with the given IP address
            return m_nodeDao.findByForeignSourceAndIpAddress(effectiveForeignSource, ipAddress).stream().filter(n -> {
                final String existingLocationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(n);
                return Objects.equals(existingLocationName, effectiveLocationName);
            }).findFirst().orElse(null);
        }

        @Override
        protected OnmsNode doUpdate(OnmsNode existingNode) {
            // we found an existing node so exit by returning null;
            return null;
        }

        @Override
        protected OnmsNode doInsert() {
            final Date now = new Date();
            OnmsMonitoringLocation location = createLocationIfNecessary(locationString);
            // Associate the location with the node
            final OnmsNode node = new OnmsNode(location);
            final String hostname = getHostnameResolver().getHostname(addr(ipAddress), locationString);
            if (hostname == null || ipAddress.equals(hostname)) {
                node.setLabel(ipAddress);
                node.setLabelSource(NodeLabelSource.ADDRESS);
            } else {
                node.setLabel(hostname);
                node.setLabelSource(NodeLabelSource.HOSTNAME);
            }
            node.setForeignSource(effectiveForeignSource);
            node.setType(NodeType.ACTIVE);
            node.setLastCapsdPoll(now);
            final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr(ipAddress), node);
            iface.setIsManaged("M");
            iface.setIpHostName(hostname);
            iface.setIsSnmpPrimary(PrimaryType.NOT_ELIGIBLE);
            iface.setIpLastCapsdPoll(now);
            m_nodeDao.save(node);
            m_nodeDao.flush();
            return node;
        }
    }.execute();
    if (node != null) {
        if (effectiveForeignSource != null) {
            node.setForeignId(node.getNodeId());
            createUpdateRequistion(ipAddress, node, effectiveLocationName, effectiveForeignSource);
        }
        // we do this here rather than in the doInsert method because
        // the doInsert may abort
        node.visit(new AddEventVisitor(m_eventForwarder));
    }
    return node;
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) NodeType(org.opennms.netmgt.model.OnmsNode.NodeType) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) Date(java.util.Date) MonitoringLocationUtils(org.opennms.netmgt.dao.api.MonitoringLocationUtils) UpsertTemplate(org.opennms.netmgt.dao.support.UpsertTemplate) LocationAwareDnsLookupClient(org.opennms.netmgt.provision.LocationAwareDnsLookupClient) InetAddressUtils.str(org.opennms.core.utils.InetAddressUtils.str) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EventUtils(org.opennms.netmgt.model.events.EventUtils) InetAddressUtils.addr(org.opennms.core.utils.InetAddressUtils.addr) IpInterfacePolicy(org.opennms.netmgt.provision.IpInterfacePolicy) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) InetAddress(java.net.InetAddress) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) NodeLabelSource(org.opennms.netmgt.model.OnmsNode.NodeLabelSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Map(java.util.Map) Resource(org.springframework.core.io.Resource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) NodeDao(org.opennms.netmgt.dao.api.NodeDao) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Collection(java.util.Collection) UpdateEventVisitor(org.opennms.netmgt.model.events.UpdateEventVisitor) Set(java.util.Set) CreateIfNecessaryTemplate(org.opennms.netmgt.dao.support.CreateIfNecessaryTemplate) AddEventVisitor(org.opennms.netmgt.model.events.AddEventVisitor) BeanUtils(org.opennms.core.spring.BeanUtils) Objects(java.util.Objects) List(java.util.List) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) PathElement(org.opennms.netmgt.model.PathElement) LocationAwareSnmpClient(org.opennms.netmgt.snmp.proxy.LocationAwareSnmpClient) RequisitionedCategoryAssociation(org.opennms.netmgt.model.RequisitionedCategoryAssociation) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) NodePolicy(org.opennms.netmgt.provision.NodePolicy) Duration(org.joda.time.Duration) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) HashMap(java.util.HashMap) EventConstants(org.opennms.netmgt.events.api.EventConstants) RequisitionedCategoryAssociationDao(org.opennms.netmgt.dao.api.RequisitionedCategoryAssociationDao) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) TreeSet(java.util.TreeSet) InitializingBean(org.springframework.beans.factory.InitializingBean) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) PrimaryType(org.opennms.netmgt.model.PrimaryType) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ServiceTypeDao(org.opennms.netmgt.dao.api.ServiceTypeDao) ForeignSourceRepository(org.opennms.netmgt.provision.persist.ForeignSourceRepository) PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsNode(org.opennms.netmgt.model.OnmsNode) RequisitionFileUtils(org.opennms.netmgt.provision.persist.RequisitionFileUtils) CategoryDao(org.opennms.netmgt.dao.api.CategoryDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DateTime(org.joda.time.DateTime) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) LocationAwareDetectorClient(org.opennms.netmgt.provision.LocationAwareDetectorClient) MonitoringLocationDao(org.opennms.netmgt.dao.api.MonitoringLocationDao) EventForwarder(org.opennms.netmgt.events.api.EventForwarder) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) Collections(java.util.Collections) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) SnmpInterfacePolicy(org.opennms.netmgt.provision.SnmpInterfacePolicy) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) AddEventVisitor(org.opennms.netmgt.model.events.AddEventVisitor) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NodeDao (org.opennms.netmgt.dao.api.NodeDao)14 OnmsNode (org.opennms.netmgt.model.OnmsNode)10 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 VmwareServer (org.opennms.netmgt.config.vmware.VmwareServer)3 VmwareConfigDao (org.opennms.netmgt.dao.VmwareConfigDao)3 InetAddress (java.net.InetAddress)2 Date (java.util.Date)2 Collection (org.opennms.netmgt.config.wsman.Collection)2 Definition (org.opennms.netmgt.config.wsman.Definition)2 WSManConfigDao (org.opennms.netmgt.dao.WSManConfigDao)2 WSManDataCollectionConfigDao (org.opennms.netmgt.dao.WSManDataCollectionConfigDao)2 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)2 FilterDao (org.opennms.netmgt.filter.api.FilterDao)2 Argument (org.opennms.netmgt.model.notifd.Argument)2 BeanFactoryReference (org.springframework.beans.factory.access.BeanFactoryReference)2 Resource (org.springframework.core.io.Resource)2 Strings (com.google.common.base.Strings)1 File (java.io.File)1 IOException (java.io.IOException)1