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