Search in sources :

Example 26 with NetworkBuilder

use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterIT method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging(true);
    // Set the operation delay to 1 second so that queued operations execute immediately
    m_adapter.setDelay(1);
    m_adapter.setTimeUnit(TimeUnit.SECONDS);
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode("test.example.com").setForeignSource("rancid").setForeignId("1").setSysObjectId(".1.3");
    nb.addInterface("192.168.0.1");
    m_nodeDao.save(nb.getCurrentNode());
    m_nodeDao.flush();
    // Make sure that the localhost SNMP connection config factory has overridden
    // the normal config factory
    assertTrue(m_adapter.getSnmpPeerFactory() instanceof ProxySnmpAgentConfigFactory);
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) ProxySnmpAgentConfigFactory(org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory) Before(org.junit.Before)

Example 27 with NetworkBuilder

use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.

the class DnsProvisioningAdapterTest method setUp.

@Before
public void setUp() throws Exception {
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode("test.example.com").setForeignSource("dns").setForeignId("1");
    nb.addInterface("192.168.0.1");
    m_nodeDao.save(nb.getCurrentNode());
    m_nodeDao.flush();
    // Call afterPropertiesSet() again so that the adapter is
    // aware of the node that we just added.
    m_adapter.afterPropertiesSet();
    m_addOperation = m_adapter.new AdapterOperation(m_nodeDao.findByForeignId("dns", "1").getId(), AdapterOperationType.ADD, new SimpleQueuedProvisioningAdapter.AdapterOperationSchedule(0, 1, 1, TimeUnit.SECONDS));
    m_deleteOperation = m_adapter.new AdapterOperation(m_nodeDao.findByForeignId("dns", "1").getId(), AdapterOperationType.DELETE, new SimpleQueuedProvisioningAdapter.AdapterOperationSchedule(0, 1, 1, TimeUnit.SECONDS));
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) AdapterOperation(org.opennms.netmgt.provision.SimpleQueuedProvisioningAdapter.AdapterOperation) Before(org.junit.Before)

Example 28 with NetworkBuilder

use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.

the class ProvisionerIT method resourcesAreNotDeletedWhenNodeScanIsAborted.

/**
 * Test for NMS-7636
 */
@Test(timeout = 300000)
public void resourcesAreNotDeletedWhenNodeScanIsAborted() throws InterruptedException, ExecutionException, UnknownHostException {
    // Setup a node with a single interface and service
    NetworkBuilder builder = new NetworkBuilder();
    builder.addNode("node1");
    builder.addInterface("192.168.0.1").getInterface().setIpLastCapsdPoll(new Date(new Date().getTime() - 60 * 60 * 1000));
    builder.addService(new OnmsServiceType());
    OnmsNode node = builder.getCurrentNode();
    getNodeDao().save(node);
    // Preliminary check
    assertEquals(1, node.getIpInterfaces().size());
    // Issue a scan without setting up the requisition
    // Expect a nodeScanAborted event
    m_eventAnticipator.anticipateEvent(nodeScanAborted(node.getId()));
    m_eventAnticipator.setDiscardUnanticipated(true);
    final NodeScan scan = m_provisioner.createNodeScan(node.getId(), "should_not_exist", "1", node.getLocation());
    runScan(scan);
    m_eventAnticipator.verifyAnticipated();
    m_eventAnticipator.reset();
    // The interface should remain
    assertEquals(1, node.getIpInterfaces().size());
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Date(java.util.Date) Test(org.junit.Test)

Example 29 with NetworkBuilder

use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.

the class CollectdIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_mockUtils = new EasyMockUtils();
    m_filterDao = m_mockUtils.createMock(FilterDao.class);
    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);
    File homeDir = resource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    resource = new ClassPathResource("/test-thresholds.xml");
    ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(resource.getInputStream()));
    // set up test using a string key
    m_key = m_testName.getMethodName() + System.nanoTime();
    m_tests.put(m_key, this);
    // create a collector definition
    Collector collector = new Collector();
    collector.setService("SNMP");
    collector.setClassName(MockServiceCollector.class.getName());
    // pass the key to the collector definition so it can look up the associated test
    Parameter param = new Parameter();
    param.setKey(TEST_KEY_PARM_NAME);
    param.setValue(m_key);
    collector.addParameter(param);
    m_collectdConfigFactory = m_mockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class);
    EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(1).anyTimes();
    m_ifaceDao = m_mockUtils.createMock(IpInterfaceDao.class);
    m_nodeDao = m_mockUtils.createMock(NodeDao.class);
    m_collectd = new Collectd() {

        @Override
        protected void handleInsufficientInfo(InsufficientInformationException e) {
            fail("Invalid event received: " + e.getMessage());
        }
    };
    OnmsServiceType snmp = new OnmsServiceType("SNMP");
    NetworkBuilder netBuilder = new NetworkBuilder();
    NodeBuilder nodeBuilder = netBuilder.addNode("node1").setId(1);
    InterfaceBuilder ifaceBlder = netBuilder.addInterface("192.168.1.1").setId(2).setIsSnmpPrimary("P");
    ifaceBlder.addSnmpInterface(1);
    OnmsMonitoredService svc = netBuilder.addService(snmp);
    List<OnmsIpInterface> initialIfs = Collections.emptyList();
    EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expect(m_nodeDao.load(1)).andReturn(nodeBuilder.getNode()).anyTimes();
    createGetPackagesExpectation(svc);
    EasyMock.expect(m_ifaceDao.load(2)).andReturn(ifaceBlder.getInterface()).anyTimes();
    m_mockUtils.replayAll();
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setIpInterfaceDao(m_ifaceDao);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    // Inits the class
    m_collectd.afterPropertiesSet();
// assertNotNull(m_serviceCollector);
}
Also used : DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) InsufficientInformationException(org.opennms.core.utils.InsufficientInformationException) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) NodeBuilder(org.opennms.netmgt.model.NetworkBuilder.NodeBuilder) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) Collector(org.opennms.netmgt.config.collectd.Collector) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) InterfaceBuilder(org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Parameter(org.opennms.netmgt.config.collectd.Parameter) File(java.io.File) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Before(org.junit.Before)

Example 30 with NetworkBuilder

use of org.opennms.netmgt.model.NetworkBuilder in project opennms by OpenNMS.

the class DuplicatePrimaryAddressIT method initialize.

/**
 * Initialize.
 *
 * @param scheduleExistingNodes true, to emulate having data on the database
 * @throws Exception the exception
 */
private void initialize(boolean scheduleExistingNodes) throws Exception {
    MockLogAppender.setupLogging();
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_mockUtils = new EasyMockUtils();
    m_filterDao = m_mockUtils.createMock(FilterDao.class);
    FilterDaoFactory.setInstance(m_filterDao);
    Resource resource = new ClassPathResource("etc/poll-outages.xml");
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
    factory.afterPropertiesSet();
    PollOutagesConfigFactory.setInstance(factory);
    File homeDir = resource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    Collector collector = new Collector();
    collector.setService("SNMP");
    collector.setClassName(MockServiceCollector.class.getName());
    m_collectdConfigFactory = m_mockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class);
    EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(2).anyTimes();
    m_ifaceDao = m_mockUtils.createMock(IpInterfaceDao.class);
    m_nodeDao = m_mockUtils.createMock(NodeDao.class);
    m_collectd = new Collectd() {

        @Override
        protected void handleInsufficientInfo(InsufficientInformationException e) {
            Assert.fail("Invalid event received: " + e.getMessage());
        }
    };
    OnmsServiceType snmp = new OnmsServiceType("SNMP");
    NetworkBuilder netBuilder = new NetworkBuilder();
    OnmsNode n1 = netBuilder.addNode("node1").setId(1).setForeignSource("TestA").setForeignId("node1").getNode();
    OnmsIpInterface ip1 = netBuilder.addSnmpInterface(1).addIpInterface("192.168.1.1").setId(2).setIsSnmpPrimary("P").getInterface();
    netBuilder.addService(snmp);
    OnmsNode n2 = netBuilder.addNode("node2").setId(3).setForeignSource("TestB").setForeignId("node2").getNode();
    OnmsIpInterface ip2 = netBuilder.addSnmpInterface(1).addIpInterface("192.168.1.1").setId(4).setIsSnmpPrimary("P").getInterface();
    netBuilder.addService(snmp);
    Assert.assertNotSame(ip1.getNode().getId(), ip2.getNode().getId());
    List<OnmsIpInterface> initialIfs = new ArrayList<>();
    if (scheduleExistingNodes) {
        initialIfs.add(ip1);
        initialIfs.add(ip2);
    }
    EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(m_nodeDao.load(1)).andReturn(n1).anyTimes();
    EasyMock.expect(m_nodeDao.load(3)).andReturn(n2).anyTimes();
    createGetPackagesExpectation();
    EasyMock.expect(m_ifaceDao.load(2)).andReturn(ip1).anyTimes();
    EasyMock.expect(m_ifaceDao.load(4)).andReturn(ip2).anyTimes();
    m_mockUtils.replayAll();
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setIpInterfaceDao(m_ifaceDao);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    m_collectd.afterPropertiesSet();
    m_collectd.start();
}
Also used : DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) InsufficientInformationException(org.opennms.core.utils.InsufficientInformationException) ArrayList(java.util.ArrayList) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) Collector(org.opennms.netmgt.config.collectd.Collector) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) File(java.io.File)

Aggregations

NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)45 Before (org.junit.Before)21 OnmsNode (org.opennms.netmgt.model.OnmsNode)15 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)9 File (java.io.File)6 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)5 NCSBuilder (org.opennms.netmgt.model.ncs.NCSBuilder)5 Date (java.util.Date)4 Test (org.junit.Test)4 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)4 AdapterOperation (org.opennms.netmgt.provision.SimpleQueuedProvisioningAdapter.AdapterOperation)4 ArrayList (java.util.ArrayList)3 InterfaceBuilder (org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder)3 OnmsAccessPoint (org.opennms.netmgt.model.OnmsAccessPoint)3 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)3 NCSComponent (org.opennms.netmgt.model.ncs.NCSComponent)3 UnknownHostException (java.net.UnknownHostException)2 HashMap (java.util.HashMap)2 MockPlatformTransactionManager (org.opennms.core.test.MockPlatformTransactionManager)2 ProxySnmpAgentConfigFactory (org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory)2