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);
}
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();
}
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();
}
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;
}
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();
}
}
Aggregations