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());
}
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());
}
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));
}
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;
}
}
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();
}
Aggregations