Search in sources :

Example 26 with Requisition

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

the class ProvisionerIT method testDnsVisit.

/**
 * We have to ignore this test until there is a DNS service available in the test harness
 *
 * @throws ForeignSourceRepositoryException
 * @throws MalformedURLException
 */
@Test(timeout = 300000)
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "opennms.com.", v4address = "1.2.3.4", entries = { @DNSEntry(hostname = "www", data = "1.2.3.4"), @DNSEntry(hostname = "www", data = "::1:2:3:4", type = "AAAA") }) })
public void testDnsVisit() throws ForeignSourceRepositoryException, MalformedURLException {
    final Requisition requisition = m_foreignSourceRepository.importResourceRequisition(new UrlResource("dns://localhost:9153/opennms.com"));
    final CountingVisitor visitor = new CountingVisitor() {

        @Override
        public void visitNode(final OnmsNodeRequisition req) {
            LOG.debug("visitNode: {}/{} {}", req.getForeignSource(), req.getForeignId(), req.getNodeLabel());
            m_nodes.add(req);
            m_nodeCount++;
        }

        @Override
        public void visitInterface(final OnmsIpInterfaceRequisition req) {
            LOG.debug("visitInterface: {}", req.getIpAddr());
            m_ifaces.add(req);
            m_ifaceCount++;
        }
    };
    requisition.visit(visitor);
    verifyDnsImportCounts(visitor);
}
Also used : OnmsIpInterfaceRequisition(org.opennms.netmgt.provision.persist.OnmsIpInterfaceRequisition) UrlResource(org.springframework.core.io.UrlResource) 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) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 27 with Requisition

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

the class DnsRequisitionUrlConnectionIT method dwoUrlAsResource.

@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", data = "72.14.204.99") }) })
public void dwoUrlAsResource() throws IOException, JAXBException {
    Resource resource = new UrlResource(TEST_URL);
    Assert.assertEquals(TEST_URL, resource.getURL().toString());
    Requisition req = null;
    Assert.assertNotNull(resource);
    InputStream resourceStream = resource.getInputStream();
    JAXBContext context = JAXBContext.newInstance(Requisition.class);
    Unmarshaller um = context.createUnmarshaller();
    um.setSchema(null);
    req = (Requisition) um.unmarshal(resourceStream);
    Assert.assertEquals("should have 2 A records: 1 for example.com, and 1 for www.example.com", 2, req.getNodeCount());
    resourceStream.close();
}
Also used : UrlResource(org.springframework.core.io.UrlResource) InputStream(java.io.InputStream) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 28 with Requisition

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

the class DnsRequisitionUrlConnectionIT method dwoUrlAsResourceUsingNonMatchingExpression.

@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", data = "72.14.204.99"), @DNSEntry(hostname = "monkey", data = "72.14.204.99") }) })
public void dwoUrlAsResourceUsingNonMatchingExpression() throws IOException, JAXBException {
    String urlString = "dns://localhost:9153/example.com/?expression=Local.*";
    Resource resource = new UrlResource(urlString);
    Assert.assertEquals(urlString, resource.getURL().toString());
    Requisition req = null;
    Assert.assertNotNull(resource);
    InputStream resourceStream = resource.getInputStream();
    JAXBContext context = JAXBContext.newInstance(Requisition.class);
    Unmarshaller um = context.createUnmarshaller();
    um.setSchema(null);
    req = (Requisition) um.unmarshal(resourceStream);
    Assert.assertEquals(0, req.getNodeCount());
    resourceStream.close();
}
Also used : UrlResource(org.springframework.core.io.UrlResource) InputStream(java.io.InputStream) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) JUnitDNSServer(org.opennms.core.test.dns.annotations.JUnitDNSServer) Test(org.junit.Test)

Example 29 with Requisition

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

the class AbstractForeignSourceRepository method importResourceRequisition.

/**
 * {@inheritDoc}
 */
@Override
public Requisition importResourceRequisition(final Resource resource) throws ForeignSourceRepositoryException {
    Assert.notNull(resource);
    LOG.debug("importing requisition from {}", resource);
    final Requisition requisition = JaxbUtils.unmarshal(Requisition.class, resource);
    requisition.setResource(resource);
    save(requisition);
    return requisition;
}
Also used : Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 30 with Requisition

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

the class FasterFilesystemForeignSourceRepository method getRequisitions.

/* (non-Javadoc)
     * @see org.opennms.netmgt.provision.persist.FilesystemForeignSourceRepository#getRequisitions()
     */
@Override
public Set<Requisition> getRequisitions() throws ForeignSourceRepositoryException {
    m_readLock.lock();
    try {
        final Set<Requisition> requisitions = new TreeSet<>();
        for (String baseName : getRequisitionsDirectoryWatcher().getBaseNamesWithExtension(".xml")) {
            try {
                Requisition contents = getRequisitionsDirectoryWatcher().getContents(baseName + ".xml");
                requisitions.add(contents);
            } catch (FileNotFoundException e) {
                LOG.info("Unable to load requisition {}: It must have been deleted by another thread", baseName, e);
            }
        }
        return requisitions;
    } finally {
        m_readLock.unlock();
    }
}
Also used : TreeSet(java.util.TreeSet) FileNotFoundException(java.io.FileNotFoundException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

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