use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollerConfigManager method createPackageIpListMap.
/**
* This method is used to establish package agaist iplist mapping, with
* which, the iplist is selected per package via the configured filter rules
* from the database.
*/
private void createPackageIpListMap() {
getReadLock().lock();
try {
Map<Package, List<InetAddress>> pkgIpMap = new HashMap<Package, List<InetAddress>>();
for (final Package pkg : packages()) {
//
try {
List<InetAddress> ipList = getIpList(pkg);
LOG.debug("createPackageIpMap: package {}: ipList size = {}", pkg.getName(), ipList.size());
if (ipList.size() > 0) {
pkgIpMap.put(pkg, ipList);
}
} catch (final Throwable t) {
LOG.error("createPackageIpMap: failed to map package: {} to an IP List with filter \"{}\"", pkg.getName(), pkg.getFilter().getContent(), t);
}
}
m_pkgIpMap.set(pkgIpMap);
} finally {
getReadLock().unlock();
}
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollableServiceConfig method refresh.
/**
* Uses the existing package name to try and re-obtain the package from the poller config factory.
* Should be called when the poller config has been reloaded.
*/
@Override
public synchronized void refresh() {
Package newPkg = m_pollerConfig.getPackage(m_pkg.getName());
if (newPkg == null) {
LOG.warn("Package named {} no longer exists.", m_pkg.getName());
}
m_pkg = newPkg;
m_configService = findService(m_pkg);
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollableServiceConfigIT method returnsUnknownOnRequestTimedOutException.
/**
* Verifies that <b>PollStatus.unknown()</b> is returned when the
* {@link LocationAwarePollerClient} fails with a {@link RequestTimedOutException}.
*
* This can happen when no Minions at the given location are available to process
* the request, or the request was not completed in time, in which case we cannot
* ascertain that the service is UP or DOWN.
*/
@Test
public void returnsUnknownOnRequestTimedOutException() throws Exception {
// Create a future that fails with a RequestTimedOutException
CompletableFuture<PollerResponse> future = new CompletableFuture<>();
future.completeExceptionally(new RequestTimedOutException(new Exception("Test")));
// Now mock the client to always return the future we created above
LocationAwarePollerClient client = mock(LocationAwarePollerClient.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(client.poll().withService(any()).withMonitor(any()).withTimeToLive(any()).withAttributes(any()).withAdaptor(any()).withAdaptor(any()).execute()).thenReturn(future);
// Mock all of the required objects required to successfully initialize the PollableServiceConfig
PollableService pollableSvc = mock(PollableService.class);
when(pollableSvc.getSvcName()).thenReturn("SVC");
Service configuredSvc = new Service();
configuredSvc.setName("SVC");
Package pkg = mock(Package.class);
when(pkg.getServices()).thenReturn(Lists.newArrayList(configuredSvc));
PollerConfig pollerConfig = mock(PollerConfig.class);
PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
Timer timer = mock(Timer.class);
PersisterFactory persisterFactory = mock(PersisterFactory.class);
ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
final PollableServiceConfig psc = new PollableServiceConfig(pollableSvc, pollerConfig, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, client);
// Trigger the poll
PollStatus pollStatus = psc.poll();
// Verify
assertThat(pollStatus.isUnknown(), is(true));
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollableServiceConfigIT method testPollableServiceConfig.
@Test
public void testPollableServiceConfig() throws Exception {
final FilterDao fd = mock(FilterDao.class);
FilterDaoFactory.setInstance(fd);
InputStream is = new FileInputStream(new File("src/test/resources/etc/psm-poller-configuration.xml"));
PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
PollerConfigFactory.setInstance(factory);
IOUtils.closeQuietly(is);
PersisterFactory persisterFactory = new MockPersisterFactory();
ResourceStorageDao resourceStorageDao = new FilesystemResourceStorageDao();
final PollContext context = mock(PollContext.class);
final PollableNetwork network = new PollableNetwork(context);
final PollableNode node = network.createNodeIfNecessary(1, "foo", null);
final PollableInterface iface = new PollableInterface(node, InetAddressUtils.addr("127.0.0.1"));
final PollableService svc = new PollableService(iface, "MQ_API_DirectRte_v2");
final PollOutagesConfig pollOutagesConfig = mock(PollOutagesConfig.class);
final Package pkg = factory.getPackage("MapQuest");
final Timer timer = mock(Timer.class);
final PollableServiceConfig psc = new PollableServiceConfig(svc, factory, pollOutagesConfig, pkg, timer, persisterFactory, resourceStorageDao, m_locationAwarePollerClient);
PollStatus pollStatus = psc.poll();
assertThat(pollStatus.getReason(), not(containsString("Unexpected exception")));
}
use of org.opennms.netmgt.config.poller.Package in project opennms by OpenNMS.
the class PollerIT method testIsRemotePackage.
//
// Tests
//
@Test
public void testIsRemotePackage() {
Properties p = new Properties();
p.setProperty("org.opennms.netmgt.ConfigFileConstants", "ERROR");
MockLogAppender.setupLogging(p);
Package pkg = new Package();
pkg.setName("SFO");
pkg.setRemote(true);
Poller poller = new Poller();
assertFalse(poller.pollableServiceInPackage(null, null, pkg));
poller = null;
}
Aggregations