Search in sources :

Example 1 with ServiceDetector

use of org.opennms.netmgt.provision.ServiceDetector in project opennms by OpenNMS.

the class DefaultForeignSourceService method getDetectorTypes.

/**
     * <p>getDetectorTypes</p>
     *
     * @return a {@link java.util.Map} object.
     */
@Override
public Map<String, String> getDetectorTypes() {
    if (m_detectors == null) {
        Map<String, String> detectors = new TreeMap<String, String>();
        for (ServiceDetector d : m_serviceRegistry.findProviders(ServiceDetector.class)) {
            String serviceName = d.getServiceName();
            if (serviceName == null) {
                serviceName = d.getClass().getSimpleName();
            }
            String className = d.getClass().getName();
            // NMS-8119: The class name may be changed when using proxy objects
            if (d instanceof TargetClassAware) {
                className = ((TargetClassAware) d).getTargetClass().getName();
            }
            detectors.put(serviceName, className);
        }
        m_detectors = new LinkedHashMap<String, String>();
        for (Entry<String, String> e : detectors.entrySet()) {
            m_detectors.put(e.getValue(), e.getKey());
        }
    }
    return m_detectors;
}
Also used : ServiceDetector(org.opennms.netmgt.provision.ServiceDetector) TargetClassAware(org.springframework.aop.TargetClassAware) TreeMap(java.util.TreeMap)

Example 2 with ServiceDetector

use of org.opennms.netmgt.provision.ServiceDetector in project opennms by OpenNMS.

the class ServiceDetectorRegistryImpl method createDetector.

private static ServiceDetector createDetector(ServiceDetectorFactory<? extends ServiceDetector> factory, Map<String, String> properties) {
    if (factory == null) {
        return null;
    }
    final ServiceDetector detector = factory.createDetector();
    BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(detector);
    wrapper.setPropertyValues(properties);
    return detector;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) ServiceDetector(org.opennms.netmgt.provision.ServiceDetector)

Example 3 with ServiceDetector

use of org.opennms.netmgt.provision.ServiceDetector in project opennms by OpenNMS.

the class ServiceDetectorRegistryImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    // Register all of the @Autowired ServiceDetectorFactory implementations
    if (m_detectorFactories != null) {
        for (ServiceDetectorFactory<?> factory : m_detectorFactories) {
            // Determine the implementation type
            Map<String, String> props = new HashMap<>();
            ServiceDetector detector = factory.createDetector();
            // Register the factory
            onBind(factory, props);
            // Add the detector to the service registry
            addAllExtensions(Collections.singleton(detector), ServiceDetector.class);
        }
    }
}
Also used : ServiceDetector(org.opennms.netmgt.provision.ServiceDetector) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ServiceDetector

use of org.opennms.netmgt.provision.ServiceDetector in project opennms by OpenNMS.

the class DetectorClientRpcModule method execute.

@Override
public CompletableFuture<DetectorResponseDTO> execute(DetectorRequestDTO request) {
    String className = request.getClassName();
    Map<String, String> attributes = request.getAttributeMap();
    ServiceDetector detector = serviceDetectorRegistry.getDetectorByClassName(className, attributes);
    if (detector == null) {
        throw new IllegalArgumentException("No detector found with class name '" + className + "'.");
    }
    return detectService(detector, request);
}
Also used : SyncServiceDetector(org.opennms.netmgt.provision.SyncServiceDetector) ServiceDetector(org.opennms.netmgt.provision.ServiceDetector) AsyncServiceDetector(org.opennms.netmgt.provision.AsyncServiceDetector)

Example 5 with ServiceDetector

use of org.opennms.netmgt.provision.ServiceDetector in project opennms by OpenNMS.

the class DetectorRequestBuilderImpl method withServiceName.

@Override
public DetectorRequestBuilder withServiceName(String serviceName) {
    final ServiceDetector detector = client.getRegistry().getDetectorByServiceName(serviceName);
    if (detector == null) {
        throw new IllegalArgumentException("No detector found with service name '" + serviceName + "'.");
    }
    this.className = detector.getClass().getCanonicalName();
    return this;
}
Also used : ServiceDetector(org.opennms.netmgt.provision.ServiceDetector)

Aggregations

ServiceDetector (org.opennms.netmgt.provision.ServiceDetector)5 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 AsyncServiceDetector (org.opennms.netmgt.provision.AsyncServiceDetector)1 SyncServiceDetector (org.opennms.netmgt.provision.SyncServiceDetector)1 TargetClassAware (org.springframework.aop.TargetClassAware)1 BeanWrapper (org.springframework.beans.BeanWrapper)1