Search in sources :

Example 21 with ForeignSource

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

the class RequisitionImplementationTest method testForeignSourceWithSlash.

@Test
public void testForeignSourceWithSlash() {
    runTest(fsr -> {
        final ForeignSource fs = fsr.getForeignSource("foo/bar");
        fs.setDefault(false);
        fsr.save(fs);
        fsr.flush();
        final ForeignSource saved = fsr.getForeignSource("foo/bar");
        assertNotNull(saved);
        assertEquals(fs, saved);
    }, ForeignSourceRepositoryException.class);
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Test(org.junit.Test)

Example 22 with ForeignSource

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

the class RequisitionImplementationTest method testForeignSourceWithSpace.

@Test
public void testForeignSourceWithSpace() {
    runTest(fsr -> {
        final ForeignSource fs = fsr.getForeignSource("foo bar");
        fs.setDefault(false);
        fsr.save(fs);
        fsr.flush();
        final ForeignSource saved = fsr.getForeignSource("foo bar");
        assertNotNull(saved);
        assertEquals(fs, saved);
    }, null);
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Test(org.junit.Test)

Example 23 with ForeignSource

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

the class RequisitionImplementationTest method testCreateSimpleForeignSource.

@Test
public void testCreateSimpleForeignSource() {
    runTest(fsr -> {
        ForeignSource fs = fsr.getForeignSource("blah");
        fs.setDefault(false);
        fsr.save(fs);
        fsr.flush();
        fs = fsr.getForeignSource("blah");
        assertNotNull(fs);
        assertNotNull(fs.getScanInterval());
    }, null);
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Test(org.junit.Test)

Example 24 with ForeignSource

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

the class FasterFilesystemForeignSourceRepository method getForeignSources.

/* (non-Javadoc)
     * @see org.opennms.netmgt.provision.persist.FilesystemForeignSourceRepository#getForeignSources()
     */
@Override
public Set<ForeignSource> getForeignSources() throws ForeignSourceRepositoryException {
    m_readLock.lock();
    try {
        final Set<ForeignSource> foreignSources = new TreeSet<ForeignSource>();
        for (String baseName : getForeignSourcesDirectoryWatcher().getBaseNamesWithExtension(".xml")) {
            try {
                ForeignSource contents = getForeignSourcesDirectoryWatcher().getContents(baseName + ".xml");
                foreignSources.add(contents);
            } catch (FileNotFoundException e) {
                LOG.info("Unable to load foreignSource {}: It must have been deleted by another thread", baseName, e);
            }
        }
        return foreignSources;
    } finally {
        m_readLock.unlock();
    }
}
Also used : TreeSet(java.util.TreeSet) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) FileNotFoundException(java.io.FileNotFoundException)

Example 25 with ForeignSource

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

the class CachingForeignSourceRepository method getForeignSourceMap.

private Map<String, ForeignSource> getForeignSourceMap() {
    readLock();
    try {
        if (m_foreignSources == null) {
            writeLock();
            try {
                final Map<String, ForeignSource> fses = new TreeMap<String, ForeignSource>();
                for (final ForeignSource fs : m_foreignSourceRepository.getForeignSources()) {
                    fses.put(fs.getName(), fs);
                }
                m_foreignSources = fses;
            } finally {
                readLock();
                writeUnlock();
            }
        }
        return m_foreignSources;
    } finally {
        readUnlock();
    }
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) TreeMap(java.util.TreeMap)

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