use of org.opennms.netmgt.collection.api.CollectionInitializationException in project opennms by OpenNMS.
the class CollectCommand method doExecute.
@Override
protected Void doExecute() {
final ServiceCollector collector = serviceCollectorRegistry.getCollectorByClassName(className);
if (collector == null) {
System.out.printf("No collector found with class name '%s'. Aborting.\n", className);
return null;
}
try {
// The collector may not have been initialized - initialize it
collector.initialize();
} catch (CollectionInitializationException e) {
System.out.println("Failed to initialize the collector. Aborting.");
e.printStackTrace();
return null;
}
final CollectionAgent agent = getCollectionAgent();
final CompletableFuture<CollectionSet> future = locationAwareCollectorClient.collect().withAgent(agent).withCollector(collector).withTimeToLive(ttlInMs).withAttributes(parse(attributes)).execute();
while (true) {
try {
try {
CollectionSet collectionSet = future.get(1, TimeUnit.SECONDS);
if (CollectionStatus.SUCCEEDED.equals(collectionSet.getStatus())) {
printCollectionSet(collectionSet);
} else {
System.out.printf("\nThe collector returned a collection set with status: %s\n", collectionSet.getStatus());
}
} catch (InterruptedException e) {
System.out.println("\nInterrupted.");
} catch (ExecutionException e) {
System.out.printf("\nCollect failed with:", e);
e.printStackTrace();
System.out.println();
}
break;
} catch (TimeoutException e) {
// pass
}
System.out.print(".");
System.out.flush();
}
return null;
}
use of org.opennms.netmgt.collection.api.CollectionInitializationException in project opennms by OpenNMS.
the class CollectableService method processUpdates.
/**
* Process any outstanding updates.
*
* @return true if update indicates that collection should be aborted (for
* example due to deletion flag being set), false otherwise.
*/
private boolean processUpdates() {
//
synchronized (this) {
if (!m_updates.hasUpdates())
return !ABORT_COLLECTION;
//
if (m_updates.isDeletionFlagSet()) {
// Deletion flag is set, simply return without polling
// or rescheduling this collector.
//
LOG.debug("Collector for {} is marked for deletion...skipping collection, will not reschedule.", getHostAddress());
return ABORT_COLLECTION;
}
OnmsIpInterface newIface = m_updates.isReinitializationNeeded();
//
if (newIface != null) {
// Reinitialization flag is set, call initialize() to
// reinit the collector for this interface
//
LOG.debug("ReinitializationFlag set for {}", getHostAddress());
try {
reinitialize(newIface);
LOG.debug("Completed reinitializing {} collector for {}/{}/{}", this.getServiceName(), m_nodeId, getHostAddress(), m_spec.getServiceName());
} catch (CollectionInitializationException rE) {
LOG.warn("Unable to initialize {}/{} for {} collection, reason: {}", m_nodeId, getHostAddress(), m_spec.getServiceName(), rE.getMessage());
} catch (Throwable t) {
LOG.error("Uncaught exception, failed to intialize interface {}/{} for {} data collection", m_nodeId, getHostAddress(), m_spec.getServiceName(), t);
}
}
//
if (m_updates.isReparentingFlagSet()) {
LOG.debug("ReparentingFlag set for {}", getHostAddress());
// The interface has been reparented under a different node
// (with
// a different nodeId).
//
// If the new directory doesn't already exist simply need to
// rename the old
// directory:
// /opt/OpenNMS/share/rrd/snmp/<oldNodeId>
// to the new directory:
// /opt/OpenNMS/share/rrd/snmp/<newNodeId>
//
// Otherwise must iterate over each of the files/dirs in the
// <oldNodeId>
// directory and move/rename them under the <newNodeId>
// directory.
// Get path to RRD repository
//
String rrdPath = DataCollectionConfigFactory.getInstance().getRrdPath();
// Does the <newNodeId> directory already exist?
File newNodeDir = new File(rrdPath + File.separator + m_updates.getReparentNewNodeId());
if (!newNodeDir.isDirectory()) {
// New directory does not exist yet so simply rename the old
// directory to
// the new directory.
//
// <oldNodeId> directory
File oldNodeDir = new File(rrdPath + File.separator + m_updates.getReparentOldNodeId());
try {
// Rename <oldNodeId> dir to <newNodeId> dir.
LOG.debug("Attempting to rename {} to {}", oldNodeDir, newNodeDir);
if (!oldNodeDir.renameTo(newNodeDir)) {
LOG.warn("Could not rename file: {}", oldNodeDir.getPath());
}
LOG.debug("Rename successful!!");
} catch (SecurityException se) {
LOG.error("Insufficient authority to rename RRD directory.", se);
} catch (Throwable t) {
LOG.error("Unexpected exception while attempting to rename RRD directory.", t);
}
} else {
// New node directory already exists so we must move/rename
// each of the
// old node directory contents under the new node directory.
//
// Get list of files to be renamed/moved
File oldNodeDir = new File(rrdPath + File.separator + m_updates.getReparentOldNodeId());
String[] filesToMove = oldNodeDir.list();
if (filesToMove != null) {
// Iterate over the file list and rename/move each one
for (int i = 0; i < filesToMove.length; i++) {
File srcFile = new File(oldNodeDir.toString() + File.separator + filesToMove[i]);
File destFile = new File(newNodeDir.toString() + File.separator + filesToMove[i]);
try {
LOG.debug("Attempting to move {} to {}", srcFile, destFile);
srcFile.renameTo(destFile);
} catch (SecurityException se) {
LOG.error("Insufficient authority to move RRD files.", se);
break;
} catch (Throwable t) {
LOG.warn("Unexpected exception while attempting to move {} to {}", srcFile, destFile, t);
}
}
}
}
// Convert new nodeId to integer value
int newNodeId = -1;
try {
newNodeId = Integer.parseInt(m_updates.getReparentNewNodeId());
} catch (NumberFormatException nfE) {
LOG.warn("Unable to convert new nodeId value to an int while processing reparenting update: {}", m_updates.getReparentNewNodeId());
}
// Set this collector's nodeId to the value of the interface's
// new parent nodeid.
m_nodeId = newNodeId;
//
try {
LOG.debug("Reinitializing collector for {}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName());
reinitialize(m_updates.getUpdatedInterface());
LOG.debug("Completed reinitializing collector for {}/{}/{}", m_nodeId, getHostAddress(), m_spec.getServiceName());
} catch (CollectionInitializationException rE) {
LOG.warn("Unable to initialize {}/{} for {} collection, reason: {}", m_nodeId, getHostAddress(), m_spec.getServiceName(), rE.getMessage());
} catch (Throwable t) {
LOG.error("Uncaught exception, failed to initialize interface {}/{} for {} data collection", m_nodeId, getHostAddress(), m_spec.getServiceName(), t);
}
}
// Updates have been applied. Reset CollectorUpdates object.
// .
m_updates.reset();
}
return !ABORT_COLLECTION;
}
Aggregations