Search in sources :

Example 1 with BatchTask

use of org.opennms.core.tasks.BatchTask in project opennms by OpenNMS.

the class NodeScan method run.

/**
 * {@inheritDoc}
 */
@Override
public void run(final BatchTask parent) {
    LOG.info("Scanning node {}/{}/{}", m_nodeId, m_foreignSource, m_foreignId);
    parent.getBuilder().addSequence(new RunInBatch() {

        @Override
        public void run(final BatchTask phase) {
            loadNode(phase);
        }
    }, new RunInBatch() {

        @Override
        public void run(final BatchTask phase) {
            detectAgents(phase);
        }
    }, new RunInBatch() {

        @Override
        public void run(final BatchTask phase) {
            handleAgentUndetected(phase);
        }
    }, new RunInBatch() {

        @Override
        public void run(final BatchTask phase) {
            scanCompleted(phase);
        }
    });
}
Also used : RunInBatch(org.opennms.core.tasks.RunInBatch) BatchTask(org.opennms.core.tasks.BatchTask)

Example 2 with BatchTask

use of org.opennms.core.tasks.BatchTask in project opennms by OpenNMS.

the class IpInterfaceScan method servicePersister.

/**
 * <p>servicePersister</p>
 *
 * @param currentPhase a {@link org.opennms.core.tasks.BatchTask} object.
 * @param serviceName a {@link java.lang.String} object.
 * @return a {@link org.opennms.core.tasks.Callback} object.
 */
public static Callback<Boolean> servicePersister(final BatchTask currentPhase, final ProvisionService service, final PluginConfig detectorConfig, final int nodeId, final InetAddress address) {
    return new Callback<Boolean>() {

        @Override
        public void accept(final Boolean serviceDetected) {
            final String hostAddress = str(address);
            final String serviceName = detectorConfig.getName();
            LOG.info("Attempted to detect service {} on address {}: {}", serviceName, hostAddress, serviceDetected);
            if (serviceDetected) {
                /*
                     * TODO: Convert this sequence into a chain of CompletableFutures 
                     */
                currentPhase.getBuilder().addSequence(new RunInBatch() {

                    @Override
                    public void run(final BatchTask batch) {
                        if ("SNMP".equals(serviceName)) {
                            service.setIsPrimaryFlag(nodeId, hostAddress);
                        }
                    }
                }, new RunInBatch() {

                    @Override
                    public void run(final BatchTask batch) {
                        service.addMonitoredService(nodeId, hostAddress, serviceName);
                    }
                }, new RunInBatch() {

                    @Override
                    public void run(final BatchTask batch) {
                        // NMS-3906
                        service.updateMonitoredServiceState(nodeId, hostAddress, serviceName);
                    }
                });
            }
        }

        @Override
        public Boolean apply(final Throwable t) {
            LOG.info("Exception occurred while trying to detect service {} on address {}", detectorConfig.getName(), str(address), t);
            return false;
        }
    };
}
Also used : RunInBatch(org.opennms.core.tasks.RunInBatch) Callback(org.opennms.core.tasks.Callback) BatchTask(org.opennms.core.tasks.BatchTask)

Example 3 with BatchTask

use of org.opennms.core.tasks.BatchTask in project opennms by OpenNMS.

the class NewSuspectScan method scanUndiscoveredNode.

/**
 * <p>scanUndiscoveredNode</p>
 *
 * @param phase a {@link org.opennms.core.tasks.BatchTask} object.
 */
protected void scanUndiscoveredNode(final BatchTask phase) {
    final String addrString = str(m_ipAddress);
    LOG.info("Attempting to scan new suspect address {} for foreign source {}", addrString, m_foreignSource);
    final OnmsNode node = m_provisionService.createUndiscoveredNode(addrString, m_foreignSource, m_location);
    if (node != null) {
        phase.getBuilder().addSequence(new NodeInfoScan(node, m_ipAddress, null, node.getLocation(), createScanProgress(), m_agentConfigFactory, m_provisionService, null), new IpInterfaceScan(node.getId(), m_ipAddress, null, node.getLocation(), m_provisionService), new NodeScan(node.getId(), null, null, node.getLocation(), m_provisionService, m_eventForwarder, m_agentConfigFactory, m_taskCoordinator), new RunInBatch() {

            @Override
            public void run(BatchTask batch) {
                LOG.info("Done scanning scan new suspect address {} for foreign source {}", addrString, m_foreignSource);
            }
        });
    } else {
        LOG.info("A node already exists with address {} in foreign source {}. No node scan will be performed.", addrString, m_foreignSource);
    }
}
Also used : RunInBatch(org.opennms.core.tasks.RunInBatch) OnmsNode(org.opennms.netmgt.model.OnmsNode) BatchTask(org.opennms.core.tasks.BatchTask)

Aggregations

BatchTask (org.opennms.core.tasks.BatchTask)3 RunInBatch (org.opennms.core.tasks.RunInBatch)3 Callback (org.opennms.core.tasks.Callback)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1