use of org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection in project opennms by OpenNMS.
the class CsvRequisitionParser method createOrUpdateRequistion.
private static void createOrUpdateRequistion(RequisitionData rd) throws UnknownHostException {
Requisition r = null;
RequisitionNode rn = new RequisitionNode();
String foreignSource = rd.getForeignSource();
r = m_fsr.getRequisition(foreignSource);
if (r == null) {
r = new Requisition(foreignSource);
}
System.err.println("Creating/Updating requistion: " + foreignSource);
r.updateDateStamp();
RequisitionMonitoredServiceCollection services = new RequisitionMonitoredServiceCollection();
for (String svc : m_serviceList) {
services.add(new RequisitionMonitoredService(svc));
}
RequisitionInterface iface = new RequisitionInterface();
iface.setDescr("mgmt-if");
iface.setIpAddr(rd.getPrimaryIp());
iface.setManaged(true);
iface.setSnmpPrimary(PrimaryType.PRIMARY);
iface.setStatus(Integer.valueOf(1));
iface.setMonitoredServices(services.getObjects());
RequisitionInterfaceCollection ric = new RequisitionInterfaceCollection();
ric.add(iface);
//add categories requisition level categories
RequisitionCategoryCollection rcc = new RequisitionCategoryCollection();
if (m_categoryList != null && m_categoryList.size() > 0) {
for (String cat : m_categoryList) {
rcc.add(new RequisitionCategory(cat));
}
}
//add categories already on the node to the requisition
if (rd.getCategories() != null) {
for (String cat : rd.getCategories()) {
rcc.add(new RequisitionCategory(cat));
}
}
rn.setBuilding(foreignSource);
if (rcc.size() >= 1) {
rn.setCategories(rcc.getObjects());
}
rn.setForeignId(rd.getForeignId());
rn.setInterfaces(ric.getObjects());
String nodeLabel = rd.getNodeLabel();
if (m_resolveIps) {
InetAddress addr = InetAddress.getByName(rd.getPrimaryIp());
nodeLabel = addr.getCanonicalHostName();
}
rn.setNodeLabel(nodeLabel);
//r.insertNode(rn);
r.putNode(rn);
m_fsr.save(r);
}
use of org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection 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;
}
Aggregations