use of org.opennms.netmgt.provision.NodePolicy in project opennms by OpenNMS.
the class NodeInfoScan method collectNodeInfo.
private void collectNodeInfo() {
Assert.notNull(getAgentConfigFactory(), "agentConfigFactory was not injected");
InetAddress primaryAddress = getAgentAddress();
SnmpAgentConfig agentConfig = getAgentConfig(primaryAddress);
SystemGroup systemGroup = new SystemGroup(primaryAddress);
try {
try {
m_provisionService.getLocationAwareSnmpClient().walk(agentConfig, systemGroup).withDescription("systemGroup").withLocation(getLocationName()).execute().get();
systemGroup.updateSnmpDataForNode(getNode());
} catch (ExecutionException e) {
abort("Aborting node scan : Agent failed while scanning the system table: " + e.getMessage());
}
List<NodePolicy> nodePolicies = getProvisionService().getNodePoliciesForForeignSource(getEffectiveForeignSource());
OnmsNode node = null;
if (isAborted()) {
if (getNodeId() != null && nodePolicies.size() > 0) {
restoreCategories = true;
node = m_provisionService.getDbNodeInitCat(getNodeId());
LOG.debug("collectNodeInfo: checking {} node policies for restoration of categories", nodePolicies.size());
}
} else {
node = getNode();
}
for (NodePolicy policy : nodePolicies) {
if (node != null) {
LOG.info("Applying NodePolicy {}({}) to {}", policy.getClass(), policy, node.getLabel());
node = policy.apply(node);
}
}
if (node == null) {
restoreCategories = false;
if (!isAborted()) {
String reason = "Aborted scan of node due to configured policy";
abort(reason);
}
} else {
setNode(node);
}
} catch (final InterruptedException e) {
abort("Aborting node scan : Scan thread interrupted!");
Thread.currentThread().interrupt();
}
}
Aggregations