Search in sources :

Example 56 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class DnsRequisitionProvider method getRequisitionFor.

@Override
public Requisition getRequisitionFor(DnsRequisitionRequest request) {
    ZoneTransferIn xfer = null;
    List<Record> records = null;
    LOG.debug("connecting to host {}:{}", request.getHost(), request.getPort());
    try {
        try {
            xfer = ZoneTransferIn.newIXFR(new Name(request.getZone()), request.getSerial(), request.getFallback(), request.getHost(), request.getPort(), null);
            records = getRecords(xfer);
        } catch (ZoneTransferException e) {
            // Fallback to AXFR
            String message = "IXFR not supported trying AXFR: " + e;
            LOG.warn(message, e);
            xfer = ZoneTransferIn.newAXFR(new Name(request.getZone()), request.getHost(), null);
            records = getRecords(xfer);
        }
    } catch (IOException | ZoneTransferException e) {
        throw new RuntimeException(e);
    }
    if (records.size() > 0) {
        // for now, set the foreign source to the specified dns zone
        final Requisition r = new Requisition(request.getForeignSource());
        for (Record rec : records) {
            if (matchingRecord(request, rec)) {
                r.insertNode(createRequisitionNode(request, rec));
            }
        }
        return r;
    }
    return null;
}
Also used : ZoneTransferException(org.xbill.DNS.ZoneTransferException) ZoneTransferIn(org.xbill.DNS.ZoneTransferIn) ARecord(org.xbill.DNS.ARecord) AAAARecord(org.xbill.DNS.AAAARecord) Record(org.xbill.DNS.Record) IOException(java.io.IOException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Name(org.xbill.DNS.Name)

Example 57 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class CachingForeignSourceRepository method getRefreshRunnable.

protected Runnable getRefreshRunnable() {
    return new Runnable() {

        @Override
        public void run() {
            writeLock();
            try {
                // clear foreign source name cache
                m_foreignSourceNames = null;
                // clear the foreign source cache
                if (m_dirtyForeignSources.size() > 0) {
                    for (final String dirtyForeignSource : m_dirtyForeignSources) {
                        final ForeignSource fs = getForeignSourceMap().get(dirtyForeignSource);
                        try {
                            if (fs == null) {
                                final ForeignSource current = m_foreignSourceRepository.getForeignSource(dirtyForeignSource);
                                if (current != null) {
                                    m_foreignSourceRepository.delete(current);
                                }
                            } else {
                                m_foreignSourceRepository.save(fs);
                            }
                        } catch (final ForeignSourceRepositoryException e) {
                            LOG.error("Failed to persist foreign source {}", dirtyForeignSource, e);
                        }
                    }
                    m_dirtyForeignSources.clear();
                }
                m_foreignSources = null;
                // clear the requisition cache
                if (m_dirtyRequisitions.size() > 0) {
                    for (final String dirtyRequisition : m_dirtyRequisitions) {
                        final Requisition r = getRequisitionMap().get(dirtyRequisition);
                        try {
                            if (r == null) {
                                final Requisition current = m_foreignSourceRepository.getRequisition(dirtyRequisition);
                                if (current != null) {
                                    m_foreignSourceRepository.delete(r);
                                }
                            } else {
                                m_foreignSourceRepository.save(r);
                            }
                        } catch (final ForeignSourceRepositoryException e) {
                            LOG.error("Failed to persist requisition {}", dirtyRequisition, e);
                        }
                    }
                    m_dirtyForeignSources.clear();
                }
                m_requisitions = null;
            } finally {
                writeUnlock();
            }
        }
    };
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 58 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class QueueingForeignSourceRepository method clear.

@Override
public void clear() throws ForeignSourceRepositoryException {
    m_pendingForeignSources.clear();
    m_pendingRequisitions.clear();
    for (final Requisition req : getRequisitions()) {
        if (req != null)
            delete(req);
    }
    for (final ForeignSource fs : getForeignSources()) {
        if (fs != null)
            delete(fs);
    }
    m_executor.execute(new QueuePersistRunnable());
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 59 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class CachingForeignSourceRepository method getRequisitionMap.

private Map<String, Requisition> getRequisitionMap() {
    readLock();
    try {
        if (m_requisitions == null) {
            writeLock();
            try {
                final Map<String, Requisition> requisitions = new TreeMap<String, Requisition>();
                for (final Requisition requisition : m_foreignSourceRepository.getRequisitions()) {
                    requisitions.put(requisition.getForeignSource(), requisition);
                }
                m_requisitions = requisitions;
            } finally {
                readLock();
                writeUnlock();
            }
        }
        return m_requisitions;
    } finally {
        readUnlock();
    }
}
Also used : TreeMap(java.util.TreeMap) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Example 60 with Requisition

use of org.opennms.netmgt.provision.persist.requisition.Requisition in project opennms by OpenNMS.

the class VmwareImporter method buildVMwareRequisition.

/**
 * Builds the complete requisition object.
 *
 * @return the requisition object
 */
private Requisition buildVMwareRequisition() {
    VmwareViJavaAccess vmwareViJavaAccess = null;
    // for now, set the foreign source to the specified vcenter host
    m_requisition = new Requisition(request.getForeignSource());
    logger.debug("Creating new VIJava access object for host {} ...", request.getHostname());
    if ((request.getHostname() == null || "".equals(request.getHostname())) || (request.getPassword() == null || "".equals(request.getPassword()))) {
        logger.info("No credentials found for connecting to host {}, trying anonymously...", request.getHostname());
        try {
            vmwareViJavaAccess = new VmwareViJavaAccess(request.getHostname());
        } catch (IOException e) {
            logger.warn("Error initialising VMware connection to '{}': '{}'", request.getHostname(), e.getMessage());
            return null;
        }
    } else {
        vmwareViJavaAccess = new VmwareViJavaAccess(request.getHostname(), request.getUsername(), request.getPassword());
    }
    logger.debug("Successfully created new VIJava access object for host {}", request.getHostname());
    logger.debug("Connecting VIJava access for host {} ...", request.getHostname());
    try {
        vmwareViJavaAccess.connect();
    } catch (MalformedURLException e) {
        logger.warn("Error connecting VMware management server '{}': '{}'", request.getHostname(), e.getMessage());
        return null;
    } catch (RemoteException e) {
        logger.warn("Error connecting VMware management server '{}': '{}'", request.getHostname(), e.getMessage());
        return null;
    }
    logger.debug("Successfully connected VIJava access for host {}", request.getHostname());
    logger.debug("Starting to enumerate VMware managed objects from host {} ...", request.getHostname());
    try {
        int apiVersion = vmwareViJavaAccess.getMajorApiVersion();
        logger.debug("Starting to iterate host system managed objects from host {} ...", request.getHostname());
        iterateHostSystems(vmwareViJavaAccess, apiVersion);
        logger.debug("Done iterating host system managed objects from host {}", request.getHostname());
        logger.debug("Starting to iterate VM managed objects from host {} ...", request.getHostname());
        iterateVirtualMachines(vmwareViJavaAccess, apiVersion);
        logger.debug("Done iterating VM managed objects from host {}", request.getHostname());
    } finally {
        vmwareViJavaAccess.disconnect();
    }
    return m_requisition;
}
Also used : MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) VmwareViJavaAccess(org.opennms.protocols.vmware.VmwareViJavaAccess) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Aggregations

Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)70 Test (org.junit.Test)31 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)16 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)11 RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)11 UrlResource (org.springframework.core.io.UrlResource)10 File (java.io.File)9 OnmsNodeRequisition (org.opennms.netmgt.provision.persist.OnmsNodeRequisition)8 Resource (org.springframework.core.io.Resource)8 IOException (java.io.IOException)6 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)6 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)5 InetAddress (java.net.InetAddress)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 InputStream (java.io.InputStream)3 RemoteException (java.rmi.RemoteException)3 Date (java.util.Date)3