Search in sources :

Example 31 with PluginConfig

use of org.opennms.netmgt.provision.persist.foreignsource.PluginConfig in project opennms by OpenNMS.

the class DefaultProvisionService method getPluginsForForeignSource.

/**
     * <p>getPluginsForForeignSource</p>
     *
     * @param pluginClass a {@link java.lang.Class} object.
     * @param foreignSourceName a {@link java.lang.String} object.
     * @param <T> a T object.
     * @return a {@link java.util.List} object.
     */
public <T> List<T> getPluginsForForeignSource(final Class<T> pluginClass, final String foreignSourceName) {
    final ForeignSource foreignSource = m_foreignSourceRepository.getForeignSource(foreignSourceName);
    assertNotNull(foreignSource, "Expected a foreignSource with name %s", foreignSourceName);
    final List<PluginConfig> configs = foreignSource.getPolicies();
    if (configs == null) {
        return Collections.emptyList();
    }
    final List<T> plugins = new ArrayList<T>(configs.size());
    for (final PluginConfig config : configs) {
        final T plugin = m_pluginRegistry.getPluginInstance(pluginClass, config);
        if (plugin == null) {
            LOG.trace("Configured plugin is not appropropriate for policy class {}: {}", pluginClass, config);
        } else {
            plugins.add(plugin);
        }
    }
    return plugins;
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList)

Example 32 with PluginConfig

use of org.opennms.netmgt.provision.persist.foreignsource.PluginConfig in project opennms by OpenNMS.

the class ForeignSourceRestService method deleteDetector.

/**
     * <p>deleteDetector</p>
     *
     * @param foreignSource a {@link java.lang.String} object.
     * @param detector a {@link java.lang.String} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("{foreignSource}/detectors/{detector}")
@Transactional
public Response deleteDetector(@PathParam("foreignSource") final String foreignSource, @PathParam("detector") final String detector) {
    writeLock();
    try {
        ForeignSource fs = getActiveForeignSource(foreignSource);
        List<PluginConfig> detectors = fs.getDetectors();
        PluginConfig removed = removeEntry(detectors, detector);
        if (removed != null) {
            fs.updateDateStamp();
            fs.setDetectors(detectors);
            m_pendingForeignSourceRepository.save(fs);
            return Response.accepted().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with PluginConfig

use of org.opennms.netmgt.provision.persist.foreignsource.PluginConfig in project opennms by OpenNMS.

the class ForeignSourceRestService method deletePolicy.

/**
     * <p>deletePolicy</p>
     *
     * @param foreignSource a {@link java.lang.String} object.
     * @param policy a {@link java.lang.String} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("{foreignSource}/policies/{policy}")
@Transactional
public Response deletePolicy(@PathParam("foreignSource") final String foreignSource, @PathParam("policy") final String policy) {
    writeLock();
    try {
        ForeignSource fs = getActiveForeignSource(foreignSource);
        List<PluginConfig> policies = fs.getPolicies();
        PluginConfig removed = removeEntry(policies, policy);
        if (removed != null) {
            fs.updateDateStamp();
            fs.setPolicies(policies);
            m_pendingForeignSourceRepository.save(fs);
            return Response.accepted().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)33 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)30 Before (org.junit.Before)10 MockForeignSourceRepository (org.opennms.netmgt.provision.persist.MockForeignSourceRepository)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 DELETE (javax.ws.rs.DELETE)2 Path (javax.ws.rs.Path)2 ProxySnmpAgentConfigFactory (org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory)2 OnmsDistPoller (org.opennms.netmgt.model.OnmsDistPoller)2 SnmpDetector (org.opennms.netmgt.provision.detector.snmp.SnmpDetector)2 NodeCategorySettingPolicy (org.opennms.netmgt.provision.persist.policies.NodeCategorySettingPolicy)2 Transactional (org.springframework.transaction.annotation.Transactional)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)1 IcmpDetector (org.opennms.netmgt.provision.detector.icmp.IcmpDetector)1 ForeignSourceCollection (org.opennms.netmgt.provision.persist.foreignsource.ForeignSourceCollection)1