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