Search in sources :

Example 36 with Requisition

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

the class ProvisionerIT method testVisit.

@Test(timeout = 300000)
public void testVisit() throws Exception {
    final Requisition requisition = m_foreignSourceRepository.importResourceRequisition(new ClassPathResource("/NewFile2.xml"));
    final CountingVisitor visitor = new CountingVisitor();
    requisition.visit(visitor);
    verifyBasicImportCounts(visitor);
}
Also used : OnmsNodeCategoryRequisition(org.opennms.netmgt.provision.persist.OnmsNodeCategoryRequisition) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) OnmsMonitoredServiceRequisition(org.opennms.netmgt.provision.persist.OnmsMonitoredServiceRequisition) OnmsServiceCategoryRequisition(org.opennms.netmgt.provision.persist.OnmsServiceCategoryRequisition) OnmsIpInterfaceRequisition(org.opennms.netmgt.provision.persist.OnmsIpInterfaceRequisition) OnmsAssetRequisition(org.opennms.netmgt.provision.persist.OnmsAssetRequisition) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 37 with Requisition

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

the class CoreImportActivities method loadSpecFile.

@Activity(lifecycle = "import", phase = "validate", schedulingHint = "import")
public RequisitionImport loadSpecFile(final Resource resource) {
    final RequisitionImport ri = new RequisitionImport();
    info("Loading requisition from resource {}", resource);
    try {
        final Requisition specFile = m_provisionService.loadRequisition(resource);
        ri.setRequisition(specFile);
        debug("Finished loading requisition.");
    } catch (final Throwable t) {
        ri.abort(t);
    }
    return ri;
}
Also used : RequisitionImport(org.opennms.netmgt.provision.service.operations.RequisitionImport) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Activity(org.opennms.netmgt.provision.service.lifecycle.annotations.Activity)

Example 38 with Requisition

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

the class CoreImportActivities method relateNodes.

@Activity(lifecycle = "import", phase = "relate", schedulingHint = "import")
public void relateNodes(final BatchTask currentPhase, final RequisitionImport ri) {
    if (ri.isAborted()) {
        info("The import has been aborted, skipping relate phase.");
        return;
    }
    info("Running relate phase");
    final Requisition requisition = ri.getRequisition();
    RequisitionVisitor visitor = new AbstractRequisitionVisitor() {

        @Override
        public void visitNode(final OnmsNodeRequisition nodeReq) {
            LOG.debug("Scheduling relate of node {}", nodeReq);
            currentPhase.add(parentSetter(m_provisionService, nodeReq, requisition.getForeignSource()));
        }
    };
    requisition.visit(visitor);
    LOG.info("Finished Running relate phase");
}
Also used : AbstractRequisitionVisitor(org.opennms.netmgt.provision.persist.AbstractRequisitionVisitor) RequisitionVisitor(org.opennms.netmgt.provision.persist.RequisitionVisitor) AbstractRequisitionVisitor(org.opennms.netmgt.provision.persist.AbstractRequisitionVisitor) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Activity(org.opennms.netmgt.provision.service.lifecycle.annotations.Activity)

Example 39 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition 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 40 with Requisition

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

the class RequisitionFileUtilsTest method testCreateTemporaryRequisition.

@Test
public void testCreateTemporaryRequisition() throws Exception {
    final File file = RequisitionFileUtils.createSnapshot(m_repository, "test", new Date());
    assertNotNull(file);
    assertTrue(file.getPath().contains(m_importDirectory + File.separator + "test"));
    assertTrue(file.getParentFile().getName().equals("imports"));
    assertTrue(file.getName().matches("test\\.xml\\.\\d+"));
    final List<File> snapshots = RequisitionFileUtils.findSnapshots(m_repository, "test");
    assertNotNull(snapshots);
    assertEquals(1, snapshots.size());
    Thread.sleep(1);
    RequisitionFileUtils.createSnapshot(m_repository, "test", new Date());
    assertEquals(2, RequisitionFileUtils.findSnapshots(m_repository, "test").size());
    m_repository.save(new Requisition("test2"));
    RequisitionFileUtils.createSnapshot(m_repository, "test2", new Date());
    assertEquals(1, RequisitionFileUtils.findSnapshots(m_repository, "test2").size());
    assertEquals(2, RequisitionFileUtils.findSnapshots(m_repository, "test").size());
}
Also used : File(java.io.File) Date(java.util.Date) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Aggregations

Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)70 Test (org.junit.Test)31 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)16 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)11 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)11 UrlResource (org.springframework.core.io.UrlResource)10 File (java.io.File)9 OnmsNodeRequisition (org.opennms.netmgt.provision.persist.OnmsNodeRequisition)8 Resource (org.springframework.core.io.Resource)8 IOException (java.io.IOException)6 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)6 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)5 InetAddress (java.net.InetAddress)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 InputStream (java.io.InputStream)3 RemoteException (java.rmi.RemoteException)3 Date (java.util.Date)3