Search in sources :

Example 16 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class DefaultProvisionService method createUpdateRequistion.

private boolean createUpdateRequistion(final String addrString, final OnmsNode node, final String locationName, String m_foreignSource) {
    LOG.debug("Creating/Updating requistion {} for newSuspect {}...", m_foreignSource, addrString);
    try {
        Requisition r = null;
        if (m_foreignSource != null) {
            r = m_foreignSourceRepository.getRequisition(m_foreignSource);
            if (r == null) {
                r = new Requisition(m_foreignSource);
            }
        }
        r.updateDateStamp();
        RequisitionNode rn = new RequisitionNode();
        RequisitionInterface iface = new RequisitionInterface();
        iface.setDescr("disc-if");
        iface.setIpAddr(addrString);
        iface.setManaged(true);
        iface.setSnmpPrimary(PrimaryType.PRIMARY);
        iface.setStatus(Integer.valueOf(1));
        RequisitionInterfaceCollection ric = new RequisitionInterfaceCollection();
        ric.add(iface);
        rn.setInterfaces(ric.getObjects());
        rn.setBuilding(m_foreignSource);
        rn.setForeignId(node.getForeignId());
        rn.setNodeLabel(node.getLabel());
        rn.setLocation(locationName);
        r.putNode(rn);
        m_foreignSourceRepository.save(r);
        m_foreignSourceRepository.flush();
    } catch (ForeignSourceRepositoryException e) {
        LOG.error("Couldn't create/update requistion for newSuspect " + addrString, e);
        return false;
    }
    LOG.debug("Created/Updated requistion {} for newSuspect {}.", m_foreignSource, addrString);
    return true;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 17 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class RequisitionFrom18Test method test18Requisitions.

@Test
public void test18Requisitions() {
    final Set<Requisition> requisitions = m_foreignSourceRepository.getRequisitions();
    assertEquals(11, requisitions.size());
    int nodeCount = 0;
    int interfaceCount = 0;
    for (final Requisition r : requisitions) {
        LOG.debug("got requisition: {}", r);
        nodeCount += r.getNodeCount();
        for (RequisitionNode node : r.getNode()) {
            interfaceCount += node.getInterfaceCount();
            if ("pgvip-master.somemediathing.net".equals(node.getNodeLabel())) {
                // Make sure that parent-foreign-source and parent-foreign-id work
                assertEquals("postgres", node.getParentForeignSource());
                assertEquals("1241674181872", node.getParentForeignId());
                assertEquals("barbacoa.somemediathing.net", node.getParentNodeLabel());
            }
        }
    }
    assertEquals("There is an unexpected number of nodes in the test requisitions", 49, nodeCount);
    assertEquals("There is an unexpected number of interfaces in the test requisitions", 60, interfaceCount);
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 18 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class FastFilesystemForeignSourceRepositoryTest method modifyRequisition.

private void modifyRequisition() throws Exception {
    Requisition r = JaxbUtils.unmarshal(Requisition.class, getRequisitionFile());
    Assert.assertNotNull(r);
    // Modify existing node
    r.getNode("4243").setNodeLabel("apknd_2");
    RequisitionNode n = new RequisitionNode();
    n.setForeignId("R2D2");
    n.setNodeLabel("utility-robot");
    n.getCategories().add(new RequisitionCategory("StarWars"));
    n.getCategories().add(new RequisitionCategory("Rebels"));
    // Add a new node
    r.getNodes().add(n);
    JaxbUtils.marshal(r, new FileWriter(getRequisitionFile()));
    // Give enough time to watcher's thread to cache the requisition
    Thread.sleep(2000);
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) FileWriter(java.io.FileWriter) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 19 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class FasterFilesystemForeignSourceRepositoryTest method testGetRequisition.

@Test
public void testGetRequisition() throws Exception {
    FileSystemBuilder bldr = new FileSystemBuilder("target", "testGetForeignSource");
    File fsDir = bldr.dir("foreignSource").file("test.xml", fs("test")).file("noreq.xml", fs("noreq")).pop();
    File reqDir = bldr.dir("requisitions").file("test.xml", req("test")).file("pending.xml", req("pending")).pop();
    FasterFilesystemForeignSourceRepository repo = repo(fsDir, reqDir);
    Requisition testReq = repo.getRequisition("test");
    assertEquals("test", testReq.getForeignSource());
    RequisitionNode node = testReq.getNode("1234");
    assertNotNull(node);
    assertEquals("node1", node.getNodeLabel());
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) File(java.io.File) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Example 20 with RequisitionNode

use of org.opennms.netmgt.provision.persist.requisition.RequisitionNode in project opennms by OpenNMS.

the class RequisitionBuilder method withContainer.

public RequisitionBuilder withContainer(final ContainerAlias alias, final String... services) {
    // We're assuming that the Minion container is on the same
    // host as the service containers
    final ContainerInfo containerInfo = minionSystem.getContainerInfo(alias);
    final String containerIpAddr = containerInfo.networkSettings().ipAddress();
    RequisitionNode node = new RequisitionNode();
    node.setNodeLabel(alias.toString());
    node.setForeignId(alias.toString());
    RequisitionInterface iface = new RequisitionInterface();
    iface.setSnmpPrimary(PrimaryType.PRIMARY);
    iface.setIpAddr(containerIpAddr);
    for (String svcName : services) {
        RequisitionMonitoredService svc = new RequisitionMonitoredService();
        svc.setServiceName(svcName);
        iface.putMonitoredService(svc);
    }
    node.putInterface(iface);
    requisition.putNode(node);
    return this;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

Aggregations

RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)20 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)15 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)14 RequisitionMonitoredService (org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)7 Test (org.junit.Test)6 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)6 ArrayList (java.util.ArrayList)5 InetAddress (java.net.InetAddress)4 RequisitionAsset (org.opennms.netmgt.provision.persist.requisition.RequisitionAsset)4 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)3 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)3 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)3 VirtualMachineRuntimeInfo (com.vmware.vim25.VirtualMachineRuntimeInfo)3 Datastore (com.vmware.vim25.mo.Datastore)3 DistributedVirtualPortgroup (com.vmware.vim25.mo.DistributedVirtualPortgroup)3 HostSystem (com.vmware.vim25.mo.HostSystem)3 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)3 Network (com.vmware.vim25.mo.Network)3 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3