Search in sources :

Example 26 with ForeignSource

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

the class DefaultForeignSourceService method deletePolicy.

/** {@inheritDoc} */
@Override
public ForeignSource deletePolicy(String foreignSource, String name) {
    ForeignSource fs = getForeignSource(foreignSource);
    List<PluginConfig> policies = fs.getPolicies();
    for (Iterator<PluginConfig> i = policies.iterator(); i.hasNext(); ) {
        PluginConfig pc = i.next();
        if (pc.getName().equals(name)) {
            i.remove();
            break;
        }
    }
    m_pendingForeignSourceRepository.save(fs);
    return fs;
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Example 27 with ForeignSource

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

the class FilesystemForeignSourceRepository method getForeignSources.

/**
     * <p>getForeignSources</p>
     *
     * @return a {@link java.util.Set} object.
     * @throws org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException if any.
     */
@Override
public Set<ForeignSource> getForeignSources() throws ForeignSourceRepositoryException {
    m_readLock.lock();
    try {
        final File directory = new File(m_foreignSourcePath);
        final TreeSet<ForeignSource> foreignSources = new TreeSet<ForeignSource>();
        if (directory.exists()) {
            for (final File file : directory.listFiles()) {
                if (file.getName().endsWith(".xml")) {
                    foreignSources.add(RequisitionFileUtils.getForeignSourceFromFile(file));
                }
            }
        }
        return foreignSources;
    } finally {
        m_readLock.unlock();
    }
}
Also used : TreeSet(java.util.TreeSet) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) File(java.io.File)

Example 28 with ForeignSource

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

the class DefaultForeignSourceService method deleteForeignSource.

/** {@inheritDoc} */
@Override
public void deleteForeignSource(String name) {
    if (name.equals("default")) {
        m_pendingForeignSourceRepository.resetDefaultForeignSource();
        m_deployedForeignSourceRepository.resetDefaultForeignSource();
    } else {
        ForeignSource fs = getForeignSource(name);
        m_pendingForeignSourceRepository.delete(fs);
        m_deployedForeignSourceRepository.delete(fs);
    }
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Example 29 with ForeignSource

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

the class ProvisionerRescanExistingFalseIT method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging(true, "ERROR");
    SnmpPeerFactory.setInstance(m_snmpPeerFactory);
    assertTrue(m_snmpPeerFactory instanceof ProxySnmpAgentConfigFactory);
    m_eventAnticipator = m_mockEventIpcManager.getEventAnticipator();
    //((TransactionAwareEventForwarder)m_provisioner.getEventForwarder()).setEventForwarder(m_mockEventIpcManager);
    m_provisioner.start();
    m_foreignSource = new ForeignSource();
    m_foreignSource.setName("noRescanOnImport");
    m_foreignSource.setScanInterval(Duration.standardDays(1));
    final PluginConfig icmpDetector = new PluginConfig("ICMP", IcmpDetector.class.getName());
    icmpDetector.addParameter("timeout", "500");
    icmpDetector.addParameter("retries", "0");
    m_foreignSource.addDetector(icmpDetector);
    final PluginConfig snmpDetector = new PluginConfig("SNMP", SnmpDetector.class.getName());
    snmpDetector.addParameter("timeout", "500");
    snmpDetector.addParameter("retries", "0");
    m_foreignSource.addDetector(snmpDetector);
    m_foreignSourceRepository = new MockForeignSourceRepository();
    m_foreignSourceRepository.save(m_foreignSource);
    m_foreignSourceRepository.flush();
    m_provisionService.setForeignSourceRepository(m_foreignSourceRepository);
    m_scheduledExecutor.pause();
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) IcmpDetector(org.opennms.netmgt.provision.detector.icmp.IcmpDetector) SnmpDetector(org.opennms.netmgt.provision.detector.snmp.SnmpDetector) ProxySnmpAgentConfigFactory(org.opennms.core.test.snmp.ProxySnmpAgentConfigFactory) MockForeignSourceRepository(org.opennms.netmgt.provision.persist.MockForeignSourceRepository) Before(org.junit.Before)

Example 30 with ForeignSource

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

the class ForeignSourceRestService method deletePendingForeignSource.

/**
     * <p>deletePendingForeignSource</p>
     *
     * @param foreignSource a {@link java.lang.String} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("{foreignSource}")
@Transactional
public Response deletePendingForeignSource(@PathParam("foreignSource") final String foreignSource) {
    writeLock();
    try {
        ForeignSource fs = getForeignSource(foreignSource);
        LOG.debug("deletePendingForeignSource: deleting foreign source {}", foreignSource);
        m_pendingForeignSourceRepository.delete(fs);
        return Response.accepted().build();
    } finally {
        writeUnlock();
    }
}
Also used : 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

ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)72 PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)31 Test (org.junit.Test)23 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)11 Before (org.junit.Before)10 MockForeignSourceRepository (org.opennms.netmgt.provision.persist.MockForeignSourceRepository)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 Transactional (org.springframework.transaction.annotation.Transactional)8 TreeSet (java.util.TreeSet)6 File (java.io.File)4 DELETE (javax.ws.rs.DELETE)4 Date (java.util.Date)3 Consumes (javax.ws.rs.Consumes)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 DateTime (org.joda.time.DateTime)2 Duration (org.joda.time.Duration)2