Search in sources :

Example 46 with ForeignSource

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

the class DefaultForeignSourceService method getAllForeignSources.

/**
 * <p>getAllForeignSources</p>
 *
 * @return a {@link java.util.Set} object.
 */
@Override
public Set<ForeignSource> getAllForeignSources() {
    Set<ForeignSource> foreignSources = new TreeSet<>();
    foreignSources.addAll(m_pendingForeignSourceRepository.getForeignSources());
    for (ForeignSource fs : m_deployedForeignSourceRepository.getForeignSources()) {
        if (!foreignSources.contains(fs)) {
            foreignSources.add(fs);
        }
    }
    return foreignSources;
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) TreeSet(java.util.TreeSet)

Example 47 with ForeignSource

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

the class DefaultForeignSourceService method addDetectorToForeignSource.

/**
 * {@inheritDoc}
 */
@Override
public ForeignSource addDetectorToForeignSource(String foreignSource, String name) {
    ForeignSource fs = getForeignSource(foreignSource);
    PluginConfig pc = new PluginConfig(name, "unknown");
    fs.addDetector(pc);
    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 48 with ForeignSource

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

the class DefaultForeignSourceService method cloneForeignSource.

/**
 * {@inheritDoc}
 */
@Override
public ForeignSource cloneForeignSource(String name, String target) {
    ForeignSource fs = getForeignSource(name);
    fs.setDefault(false);
    fs.setName(target);
    m_deployedForeignSourceRepository.save(fs);
    m_pendingForeignSourceRepository.delete(fs);
    return m_deployedForeignSourceRepository.getForeignSource(target);
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Example 49 with ForeignSource

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

the class FilesystemForeignSourceRepository method getForeignSource.

/**
 * {@inheritDoc}
 */
@Override
public ForeignSource getForeignSource(final String foreignSourceName) throws ForeignSourceRepositoryException {
    if (foreignSourceName == null) {
        throw new ForeignSourceRepositoryException("can't get a foreign source with a null name!");
    }
    m_readLock.lock();
    try {
        final File inputFile = RequisitionFileUtils.encodeFileName(m_foreignSourcePath, foreignSourceName);
        if (inputFile != null && inputFile.exists()) {
            return RequisitionFileUtils.getForeignSourceFromFile(inputFile);
        } else {
            final ForeignSource fs = getDefaultForeignSource();
            fs.setName(foreignSourceName);
            return fs;
        }
    } finally {
        m_readLock.unlock();
    }
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) File(java.io.File)

Example 50 with ForeignSource

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

the class CachingForeignSourceRepositoryTest method testDefaultForeignSource.

@Test
public void testDefaultForeignSource() throws Exception {
    createRequisition();
    List<String> detectorList = Arrays.asList(new String[] { "DNS", "FTP", "HTTP", "HTTPS", "ICMP", "IMAP", "LDAP", "NRPE", "POP3", "SMTP", "SNMP", "SSH" });
    String uuid = UUID.randomUUID().toString();
    ForeignSource defaultForeignSource = m_foreignSourceRepository.getForeignSource(uuid);
    assertEquals("name must match requested foreign source repository name", uuid, defaultForeignSource.getName());
    assertEquals("scan-interval must be 1 day", 86400000, defaultForeignSource.getScanInterval().getMillis());
    assertEquals("foreign source must have no default policies", 0, defaultForeignSource.getPolicies().size());
    List<String> fsNames = new ArrayList<>();
    for (PluginConfig config : defaultForeignSource.getDetectors()) {
        fsNames.add(config.getName());
    }
    assertEquals("detector list must match expected defaults", detectorList, fsNames);
    assertTrue("foreign source must be tagged as default", defaultForeignSource.isDefault());
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

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