Search in sources :

Example 1 with RequisitionInterfaceCollection

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);
}
Also used : RequisitionCategoryCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionCategoryCollection) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionMonitoredServiceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredServiceCollection) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) InetAddress(java.net.InetAddress) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

Example 2 with RequisitionInterfaceCollection

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;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Aggregations

Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)2 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)2 RequisitionInterfaceCollection (org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection)2 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)2 InetAddress (java.net.InetAddress)1 ForeignSourceRepositoryException (org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException)1 OnmsNodeRequisition (org.opennms.netmgt.provision.persist.OnmsNodeRequisition)1 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)1 RequisitionCategoryCollection (org.opennms.netmgt.provision.persist.requisition.RequisitionCategoryCollection)1 RequisitionMonitoredService (org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)1 RequisitionMonitoredServiceCollection (org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredServiceCollection)1