@NotNull
public InventoryReport call() {
String target = (rootResource != null) ? this.rootResource.toString() : "platform";
log.info("Executing runtime discovery scan rooted at [" + target + "]...");
InventoryReport report = new InventoryReport(inventoryManager.getAgent());
try {
report.setRuntimeReport(true);
report.setStartTime(System.currentTimeMillis());
runtimeDiscover(report);
report.setEndTime(System.currentTimeMillis());
if (log.isDebugEnabled()) {
log.debug(String.format("Runtime discovery scan took %d ms.",
(report.getEndTime() - report.getStartTime())));
}
// TODO: This is always zero for embedded because we don't populate the report.
int numAddedRoots = report.getAddedRoots().size();
int numNewDescendants = (report.getResourceCount() - numAddedRoots);
log.info("Scanned " + target + " and " + numAddedRoots + " server(s) and discovered " + numNewDescendants
+ " new descendant Resource(s).");
// TODO GH: This is principally valuable only until we work out the last of the data transfer situations.
if (log.isTraceEnabled()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(10000);
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(report);
log.trace("Runtime report contains " + report.getResourceCount() + " Resources with a size of "
+ baos.size() + " bytes");
}
// If no child resources were discovered then don't send the empty report. This avoids some
// major overhead in that each each report sent triggers a full inventory sync.
if (numNewDescendants > 0) {
this.inventoryManager.handleReport(report);
} else {
log.info("Not sending inventory report because no new descendent resources were discovered.");
}
} catch (Exception e) {
log.warn("Exception caught while executing runtime discovery scan rooted at [" + target + "].", e);
report.addError(new ExceptionPackage(Severity.Warning, e));
}
return report;
}