Search in sources :

Example 1 with ResourceStorageDao

use of org.opennms.netmgt.dao.api.ResourceStorageDao in project opennms by OpenNMS.

the class DeleteNodesServlet method init.

/**
 * {@inheritDoc}
 */
@Override
public void init() throws ServletException {
    WebApplicationContext webAppContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
    m_resourceStorageDao = webAppContext.getBean("resourceStorageDao", ResourceStorageDao.class);
}
Also used : ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 2 with ResourceStorageDao

use of org.opennms.netmgt.dao.api.ResourceStorageDao in project opennms by OpenNMS.

the class TcaCollectorComplianceIT method getRequiredBeans.

@Override
public Map<String, Object> getRequiredBeans() {
    TcaDataCollectionConfig config = mock(TcaDataCollectionConfig.class);
    RrdRepository rrdRepository = new RrdRepository();
    rrdRepository.setRrdBaseDir(new File("target"));
    when(config.buildRrdRepository(COLLECTION)).thenReturn(rrdRepository);
    TcaDataCollectionConfigDao tcaDataCollectionConfigDao = mock(TcaDataCollectionConfigDao.class);
    when(tcaDataCollectionConfigDao.getConfig()).thenReturn(config);
    ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
    ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
    ResourceType resourceType = TcaCollectorIT.getJuniperTcaEntryResourceType();
    when(resourceTypesDao.getResourceTypeByName(TcaCollectionHandler.RESOURCE_TYPE_NAME)).thenReturn(resourceType);
    return new ImmutableMap.Builder<String, Object>().put("tcaDataCollectionConfigDao", tcaDataCollectionConfigDao).put("resourceStorageDao", resourceStorageDao).put("resourceTypesDao", resourceTypesDao).put("locationAwareSnmpClient", m_client).build();
}
Also used : ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) TcaDataCollectionConfigDao(org.opennms.netmgt.collectd.tca.dao.TcaDataCollectionConfigDao) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) File(java.io.File) TcaDataCollectionConfig(org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with ResourceStorageDao

use of org.opennms.netmgt.dao.api.ResourceStorageDao in project opennms by OpenNMS.

the class PollableServiceConfigTest 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));
}
Also used : RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) LocationAwarePollerClient(org.opennms.netmgt.poller.LocationAwarePollerClient) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) PollStatus(org.opennms.netmgt.poller.PollStatus) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PersisterFactory(org.opennms.netmgt.collection.api.PersisterFactory) PollerConfig(org.opennms.netmgt.config.PollerConfig) Service(org.opennms.netmgt.config.poller.Service) RequestTimedOutException(org.opennms.core.rpc.api.RequestTimedOutException) CompletableFuture(java.util.concurrent.CompletableFuture) Timer(org.opennms.netmgt.scheduler.Timer) Package(org.opennms.netmgt.config.poller.Package) PollerResponse(org.opennms.netmgt.poller.PollerResponse) PollOutagesConfig(org.opennms.netmgt.config.PollOutagesConfig) Test(org.junit.Test)

Example 4 with ResourceStorageDao

use of org.opennms.netmgt.dao.api.ResourceStorageDao in project opennms by OpenNMS.

the class PollableServiceConfigTest 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")));
}
Also used : FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) PollStatus(org.opennms.netmgt.poller.PollStatus) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PersisterFactory(org.opennms.netmgt.collection.api.PersisterFactory) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) FileInputStream(java.io.FileInputStream) FilterDao(org.opennms.netmgt.filter.api.FilterDao) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) Timer(org.opennms.netmgt.scheduler.Timer) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) PollOutagesConfig(org.opennms.netmgt.config.PollOutagesConfig) Test(org.junit.Test)

Example 5 with ResourceStorageDao

use of org.opennms.netmgt.dao.api.ResourceStorageDao in project opennms by OpenNMS.

the class CollectableServiceTest method createCollectableService.

private void createCollectableService() throws CollectionInitializationException, IOException {
    // Mock it all!
    OnmsIpInterface iface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS);
    IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
    spec = mock(CollectionSpecification.class);
    scheduler = mock(Scheduler.class);
    SchedulingCompletedFlag schedulingCompletedFlag = mock(SchedulingCompletedFlag.class);
    PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
    RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
    persisterFactory.setRrdStrategy(rrdStrategy);
    ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class);
    // Disable thresholding
    Map<String, Object> paramsMap = new HashMap<>();
    paramsMap.put("thresholding-enabled", Boolean.FALSE.toString());
    ServiceParameters params = new ServiceParameters(paramsMap);
    when(iface.getNode().getId()).thenReturn(1);
    when(spec.getServiceParameters()).thenReturn(params);
    when(spec.getRrdRepository(any())).thenReturn(createRrdRepository());
    when(ifaceDao.load(any())).thenReturn(iface);
    when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
    service = new CollectableService(iface, ifaceDao, spec, scheduler, schedulingCompletedFlag, transMgr, persisterFactory, resourceStorageDao);
}
Also used : ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) HashMap(java.util.HashMap) Scheduler(org.opennms.netmgt.scheduler.Scheduler) CollectionSpecification(org.opennms.netmgt.collection.core.CollectionSpecification) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SchedulingCompletedFlag(org.opennms.netmgt.collectd.Collectd.SchedulingCompletedFlag)

Aggregations

ResourceStorageDao (org.opennms.netmgt.dao.api.ResourceStorageDao)7 Test (org.junit.Test)4 PersisterFactory (org.opennms.netmgt.collection.api.PersisterFactory)4 PollOutagesConfig (org.opennms.netmgt.config.PollOutagesConfig)4 Package (org.opennms.netmgt.config.poller.Package)4 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)4 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)4 PollStatus (org.opennms.netmgt.poller.PollStatus)4 Timer (org.opennms.netmgt.scheduler.Timer)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 RequestTimedOutException (org.opennms.core.rpc.api.RequestTimedOutException)2 PollerConfig (org.opennms.netmgt.config.PollerConfig)2 PollerConfigFactory (org.opennms.netmgt.config.PollerConfigFactory)2 Service (org.opennms.netmgt.config.poller.Service)2 FilterDao (org.opennms.netmgt.filter.api.FilterDao)2 LocationAwarePollerClient (org.opennms.netmgt.poller.LocationAwarePollerClient)2 PollerResponse (org.opennms.netmgt.poller.PollerResponse)2