Search in sources :

Example 16 with ForeignSource

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

the class QueueingForeignSourceRepositoryTest method testForeignSource.

@Test
public void testForeignSource() throws Exception {
    createRequisition();
    ForeignSource foreignSource = createForeignSource(m_defaultForeignSourceName);
    Set<ForeignSource> foreignSources = m_foreignSourceRepository.getForeignSources();
    String names = "", separator = "";
    for (ForeignSource fs : foreignSources) {
        names += (separator + "\"" + fs.getName() + "\"");
        separator = ", ";
    }
    assertEquals("number of foreign sources must be 1: " + names, 1, foreignSources.size());
    assertEquals("getAll() foreign source name must match", m_defaultForeignSourceName, foreignSources.iterator().next().getName());
    // check that the foreign source matches
    final ForeignSource newForeignSource = m_foreignSourceRepository.getForeignSource(m_defaultForeignSourceName);
    assertEquals(foreignSource.getName(), newForeignSource.getName());
    assertEquals(foreignSource.getDateStampAsDate(), newForeignSource.getDateStampAsDate());
    assertEquals(foreignSource.getDetectorNames(), newForeignSource.getDetectorNames());
    assertEquals(foreignSource.getScanInterval(), newForeignSource.getScanInterval());
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Test(org.junit.Test)

Example 17 with ForeignSource

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

the class QueueingForeignSourceRepositoryTest 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<String>();
    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)

Example 18 with ForeignSource

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

the class MockForeignSourceRepositoryTest method testForeignSource.

@Test
public void testForeignSource() throws Exception {
    createRequisition();
    ForeignSource foreignSource = createForeignSource(m_defaultForeignSourceName);
    List<ForeignSource> foreignSources = new ArrayList<ForeignSource>(m_foreignSourceRepository.getForeignSources());
    assertEquals("number of foreign sources", 1, foreignSources.size());
    assertEquals("getAll() foreign source name matches", m_defaultForeignSourceName, foreignSources.get(0).getName());
    assertEquals("get() returns the foreign source", foreignSource, m_foreignSourceRepository.getForeignSource(m_defaultForeignSourceName));
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with ForeignSource

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

the class DefaultProvisionService method createScheduleForNode.

private NodeScanSchedule createScheduleForNode(final OnmsNode node, final boolean force) {
    Assert.notNull(node, "Node may not be null");
    final String actualForeignSource = node.getForeignSource();
    if (actualForeignSource == null && !isDiscoveryEnabled()) {
        LOG.info("Not scheduling node {} to be scanned since it has a null foreignSource and handling of discovered nodes is disabled in provisiond", node);
        return null;
    }
    final String effectiveForeignSource = actualForeignSource == null ? "default" : actualForeignSource;
    try {
        final ForeignSource fs = m_foreignSourceRepository.getForeignSource(effectiveForeignSource);
        final Duration scanInterval = fs.getScanInterval();
        if (scanInterval.getMillis() <= 0) {
            LOG.debug("Node ({}/{}/{}) scan interval is zero, skipping schedule.", node.getId(), node.getForeignSource(), node.getForeignId());
            return null;
        }
        Duration initialDelay = Duration.ZERO;
        if (node.getLastCapsdPoll() != null && !force) {
            final DateTime nextPoll = new DateTime(node.getLastCapsdPoll().getTime()).plus(scanInterval);
            final DateTime now = new DateTime();
            if (nextPoll.isAfter(now)) {
                initialDelay = new Duration(now, nextPoll);
            }
        }
        return new NodeScanSchedule(node.getId(), actualForeignSource, node.getForeignId(), node.getLocation(), initialDelay, scanInterval);
    } catch (final ForeignSourceRepositoryException e) {
        LOG.warn("unable to get foreign source '{}' from repository", effectiveForeignSource, e);
        return null;
    }
}
Also used : ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Duration(org.joda.time.Duration) DateTime(org.joda.time.DateTime)

Example 20 with ForeignSource

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

the class DefaultProvisionService method getDetectorsForForeignSource.

/** {@inheritDoc} */
@Override
public List<PluginConfig> getDetectorsForForeignSource(final String foreignSourceName) {
    final ForeignSource foreignSource = m_foreignSourceRepository.getForeignSource(foreignSourceName);
    assertNotNull(foreignSource, "Expected a foreignSource with name %s", foreignSourceName);
    return foreignSource.getDetectors();
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

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