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