Search in sources :

Example 6 with NetworkBuilder

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

the class NsclientCollectorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    startServer("None&8&", "10");
    // Initialize Mocks
    m_transactionManager = new MockPlatformTransactionManager();
    m_ipInterfaceDao = EasyMock.createMock(IpInterfaceDao.class);
    m_eventProxy = EasyMock.createMock(EventProxy.class);
    NetworkBuilder builder = new NetworkBuilder();
    builder.addNode("winsrv");
    builder.addInterface(getServer().getInetAddress().getHostAddress()).addSnmpInterface(1).setCollectionEnabled(true);
    builder.getCurrentNode().setId(1);
    OnmsIpInterface iface = builder.getCurrentNode().getIpInterfaces().iterator().next();
    iface.setIsSnmpPrimary(PrimaryType.PRIMARY);
    iface.setId(1);
    EasyMock.expect(m_ipInterfaceDao.load(1)).andReturn(iface).anyTimes();
    EasyMock.replay(m_ipInterfaceDao, m_eventProxy);
    // Initialize NSClient Configuration
    String nsclient_config = "<nsclient-config port=\"" + getServer().getLocalPort() + "\" retry=\"1\" timeout=\"3000\" />";
    NSClientPeerFactory.setInstance(new NSClientPeerFactory(new ByteArrayInputStream(nsclient_config.getBytes())));
    NSClientDataCollectionConfigFactory.setInstance(new NSClientDataCollectionConfigFactory("src/test/resources/nsclient-datacollection-config.xml"));
    // Initialize Collection Agent
    m_collectionAgent = DefaultCollectionAgent.create(1, m_ipInterfaceDao, m_transactionManager);
}
Also used : NSClientPeerFactory(org.opennms.protocols.nsclient.config.NSClientPeerFactory) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) NSClientDataCollectionConfigFactory(org.opennms.protocols.nsclient.config.NSClientDataCollectionConfigFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) EventProxy(org.opennms.netmgt.events.api.EventProxy) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) Before(org.junit.Before)

Example 7 with NetworkBuilder

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

the class SnmpHardwareInventoryProvisioningAdapterIT method setUp.

/**
     * Sets the up.
     *
     * @throws Exception the exception
     */
@BeforeTransaction
public void setUp() throws Exception {
    MockLogAppender.setupLogging(true);
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode("R1").setForeignSource("Cisco").setForeignId("1").setSysObjectId(".1.3.6.1.4.1.9.1.222");
    nb.addInterface("192.168.0.1").setIsSnmpPrimary("P").setIsManaged("P");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("R2").setForeignSource("Cisco").setForeignId("2").setSysObjectId(".1.3.6.1.4.1.9.1.222");
    nb.addInterface("192.168.0.2").setIsSnmpPrimary("P").setIsManaged("P");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("R3").setForeignSource("Cisco").setForeignId("3").setSysObjectId(".1.3.6.1.4.1.9.1.222");
    nb.addInterface("192.168.0.3").setIsSnmpPrimary("P").setIsManaged("P");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("R4").setForeignSource("Cisco").setForeignId("4").setSysObjectId(".1.3.6.1.4.1.9.1.222");
    nb.addInterface("192.168.0.4").setIsSnmpPrimary("P").setIsManaged("P");
    m_nodeDao.save(nb.getCurrentNode());
    m_nodeDao.flush();
    m_adapter.afterPropertiesSet();
    for (int i = 1; i <= 4; i++) {
        Integer nodeId = m_nodeDao.findByForeignId("Cisco", Integer.toString(i)).getId();
        AdapterOperationSchedule ops = new AdapterOperationSchedule(0, 1, 1, TimeUnit.SECONDS);
        AdapterOperation op = m_adapter.new AdapterOperation(nodeId, AdapterOperationType.ADD, ops);
        m_operations.add(new TestOperation(nodeId, op));
    }
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) AdapterOperationSchedule(org.opennms.netmgt.provision.SimpleQueuedProvisioningAdapter.AdapterOperationSchedule) AdapterOperation(org.opennms.netmgt.provision.SimpleQueuedProvisioningAdapter.AdapterOperation) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction)

Example 8 with NetworkBuilder

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

the class AbstractSingleHardwareAdapterTest method setUp.

/**
     * Sets the up.
     *
     * @throws Exception the exception
     */
@BeforeTransaction
public void setUp() throws Exception {
    MockLogAppender.setupLogging(true);
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode("Test").setForeignSource("Test").setForeignId("1").setSysObjectId(".1.3.6.1.4.1.9.1.1196");
    nb.addInterface("192.168.0.1").setIsSnmpPrimary("P").setIsManaged("P");
    m_nodeDao.save(nb.getCurrentNode());
    m_nodeDao.flush();
    m_adapter.afterPropertiesSet();
    m_nodeId = m_nodeDao.findByForeignId("Test", "1").getId();
    AdapterOperationSchedule ops = new AdapterOperationSchedule(0, 1, 1, TimeUnit.SECONDS);
    m_operation = m_adapter.new AdapterOperation(m_nodeId, AdapterOperationType.ADD, ops);
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) AdapterOperationSchedule(org.opennms.netmgt.provision.SimpleQueuedProvisioningAdapter.AdapterOperationSchedule) AdapterOperation(org.opennms.netmgt.provision.SimpleQueuedProvisioningAdapter.AdapterOperation) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction)

Example 9 with NetworkBuilder

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

the class EnLinkdIT method testDeleteBridgeB.

@Test
public void testDeleteBridgeB() {
    ABCTopology topology = new ABCTopology();
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode("nodeA").setForeignSource("linkd").setForeignId("nodeA").setSysObjectId("0.0").setSysName("nodeA").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.1").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("nodeB").setForeignSource("linkd").setForeignId("nodeB").setSysObjectId("0.0").setSysName("nodeB").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.2").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("nodeC").setForeignSource("linkd").setForeignId("nodeC").setSysObjectId("0.0").setSysName("nodeC").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.3").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    OnmsNode nodeA = m_nodeDao.findByForeignId("linkd", "nodeA");
    OnmsNode nodeB = m_nodeDao.findByForeignId("linkd", "nodeB");
    OnmsNode nodeC = m_nodeDao.findByForeignId("linkd", "nodeC");
    topology.nodeAId = nodeA.getId();
    topology.nodeBId = nodeB.getId();
    topology.nodeCId = nodeC.getId();
    topology.nodeA = nodeA;
    topology.nodeB = nodeB;
    topology.nodeC = nodeC;
    BridgeBridgeLink ablink = new BridgeBridgeLink();
    ablink.setNode(nodeB);
    ablink.setBridgePort(topology.portBA);
    ablink.setDesignatedNode(nodeA);
    ablink.setDesignatedPort(topology.portAB);
    ablink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(ablink);
    BridgeBridgeLink bclink = new BridgeBridgeLink();
    bclink.setNode(nodeC);
    bclink.setBridgePort(topology.portCB);
    bclink.setDesignatedNode(nodeB);
    bclink.setDesignatedPort(topology.portBC);
    bclink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(bclink);
    BridgeMacLink mac1 = new BridgeMacLink();
    mac1.setNode(nodeA);
    mac1.setBridgePort(topology.portA);
    mac1.setMacAddress(topology.mac1);
    mac1.setBridgeMacLinkLastPollTime(mac1.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac1);
    BridgeMacLink mac2 = new BridgeMacLink();
    mac2.setNode(nodeB);
    mac2.setBridgePort(topology.portB);
    mac2.setMacAddress(topology.mac2);
    mac2.setBridgeMacLinkLastPollTime(mac2.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac2);
    BridgeMacLink mac3 = new BridgeMacLink();
    mac3.setNode(nodeC);
    mac3.setBridgePort(topology.portC);
    mac3.setMacAddress(topology.mac3);
    mac3.setBridgeMacLinkLastPollTime(mac3.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac3);
    m_bridgeMacLinkDao.flush();
    m_bridgeBridgeLinkDao.flush();
    assertEquals(3, m_bridgeMacLinkDao.countAll());
    assertEquals(2, m_bridgeBridgeLinkDao.countAll());
    assertNotNull(m_bridgeTopologyDao);
    m_linkd.getQueryManager().loadBridgeTopology();
    assertEquals(1, m_bridgeTopologyDao.getAll().size());
    BroadcastDomain nodeAbd = m_linkd.getQueryManager().getBroadcastDomain(nodeA.getId().intValue());
    assertNotNull(nodeAbd);
    BroadcastDomain nodeBbd = m_linkd.getQueryManager().getBroadcastDomain(nodeB.getId().intValue());
    BroadcastDomain nodeCbd = m_linkd.getQueryManager().getBroadcastDomain(nodeC.getId().intValue());
    assertEquals(nodeAbd, nodeBbd);
    assertEquals(nodeAbd, nodeCbd);
    assertNull(nodeAbd.getRootBridgeId());
    assertTrue(nodeAbd.containBridgeId(nodeA.getId()));
    assertTrue(nodeAbd.containBridgeId(nodeB.getId()));
    assertTrue(nodeAbd.containBridgeId(nodeC.getId()));
    nodeAbd.hierarchySetUp(nodeAbd.getBridge(nodeA.getId()));
    assertNotNull(nodeAbd.getRootBridgeId());
    topology.check(nodeAbd);
    assertTrue(m_linkd.scheduleNodeCollection(nodeB.getId()));
    m_linkd.deleteNode(nodeB.getId());
    assertEquals(1, m_bridgeTopologyDao.getAll().size());
    BroadcastDomain domain = m_bridgeTopologyDao.getAll().iterator().next();
    topology.checkAC(domain);
}
Also used : Nms10205bNetworkBuilder(org.opennms.netmgt.nb.Nms10205bNetworkBuilder) Nms17216NetworkBuilder(org.opennms.netmgt.nb.Nms17216NetworkBuilder) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Test(org.junit.Test)

Example 10 with NetworkBuilder

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

the class EnLinkdIT method testDeleteBridgeA.

@Test
public void testDeleteBridgeA() {
    ABCTopology topology = new ABCTopology();
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode("nodeA").setForeignSource("linkd").setForeignId("nodeA").setSysObjectId("0.0").setSysName("nodeA").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.1").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("nodeB").setForeignSource("linkd").setForeignId("nodeB").setSysObjectId("0.0").setSysName("nodeB").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.2").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("nodeC").setForeignSource("linkd").setForeignId("nodeC").setSysObjectId("0.0").setSysName("nodeC").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.3").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    OnmsNode nodeA = m_nodeDao.findByForeignId("linkd", "nodeA");
    OnmsNode nodeB = m_nodeDao.findByForeignId("linkd", "nodeB");
    OnmsNode nodeC = m_nodeDao.findByForeignId("linkd", "nodeC");
    topology.nodeAId = nodeA.getId();
    topology.nodeBId = nodeB.getId();
    topology.nodeCId = nodeC.getId();
    topology.nodeA = nodeA;
    topology.nodeB = nodeB;
    topology.nodeC = nodeC;
    BridgeBridgeLink ablink = new BridgeBridgeLink();
    ablink.setNode(nodeB);
    ablink.setBridgePort(topology.portBA);
    ablink.setDesignatedNode(nodeA);
    ablink.setDesignatedPort(topology.portAB);
    ablink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(ablink);
    BridgeBridgeLink bclink = new BridgeBridgeLink();
    bclink.setNode(nodeC);
    bclink.setBridgePort(topology.portCB);
    bclink.setDesignatedNode(nodeB);
    bclink.setDesignatedPort(topology.portBC);
    bclink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(bclink);
    BridgeMacLink mac1 = new BridgeMacLink();
    mac1.setNode(nodeA);
    mac1.setBridgePort(topology.portA);
    mac1.setMacAddress(topology.mac1);
    mac1.setBridgeMacLinkLastPollTime(mac1.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac1);
    BridgeMacLink mac2 = new BridgeMacLink();
    mac2.setNode(nodeB);
    mac2.setBridgePort(topology.portB);
    mac2.setMacAddress(topology.mac2);
    mac2.setBridgeMacLinkLastPollTime(mac2.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac2);
    BridgeMacLink mac3 = new BridgeMacLink();
    mac3.setNode(nodeC);
    mac3.setBridgePort(topology.portC);
    mac3.setMacAddress(topology.mac3);
    mac3.setBridgeMacLinkLastPollTime(mac3.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac3);
    m_bridgeMacLinkDao.flush();
    m_bridgeBridgeLinkDao.flush();
    assertEquals(3, m_bridgeMacLinkDao.countAll());
    assertEquals(2, m_bridgeBridgeLinkDao.countAll());
    assertNotNull(m_bridgeTopologyDao);
    m_linkd.getQueryManager().loadBridgeTopology();
    assertEquals(1, m_bridgeTopologyDao.getAll().size());
    BroadcastDomain nodeAbd = m_linkd.getQueryManager().getBroadcastDomain(nodeA.getId().intValue());
    assertNotNull(nodeAbd);
    BroadcastDomain nodeBbd = m_linkd.getQueryManager().getBroadcastDomain(nodeB.getId().intValue());
    BroadcastDomain nodeCbd = m_linkd.getQueryManager().getBroadcastDomain(nodeC.getId().intValue());
    assertEquals(nodeAbd, nodeBbd);
    assertEquals(nodeAbd, nodeCbd);
    assertNull(nodeAbd.getRootBridgeId());
    assertTrue(nodeAbd.containBridgeId(nodeA.getId()));
    assertTrue(nodeAbd.containBridgeId(nodeB.getId()));
    assertTrue(nodeAbd.containBridgeId(nodeC.getId()));
    nodeAbd.hierarchySetUp(nodeAbd.getBridge(nodeA.getId()));
    assertNotNull(nodeAbd.getRootBridgeId());
    topology.check(nodeAbd);
    assertTrue(m_linkd.scheduleNodeCollection(nodeA.getId()));
    m_linkd.scheduleBridgeTopologyDiscovery(nodeA.getId());
    m_linkd.deleteNode(nodeA.getId());
    assertEquals(1, m_bridgeTopologyDao.getAll().size());
    BroadcastDomain domain = m_bridgeTopologyDao.getAll().iterator().next();
    topology.checkBC(domain);
}
Also used : Nms10205bNetworkBuilder(org.opennms.netmgt.nb.Nms10205bNetworkBuilder) Nms17216NetworkBuilder(org.opennms.netmgt.nb.Nms17216NetworkBuilder) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Test(org.junit.Test)

Aggregations

NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)42 Before (org.junit.Before)20 OnmsNode (org.opennms.netmgt.model.OnmsNode)14 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)9 File (java.io.File)6 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 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)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 InsufficientInformationException (org.opennms.core.utils.InsufficientInformationException)2