@Override protected String getId(final OnmsDistPoller dp) { return dp == null? null : dp.getId(); }
public DistPollerDaoDistributed(Identity identity) { Objects.requireNonNull(identity); m_distPoller = new OnmsDistPoller(); m_distPoller.setId(identity.getId()); m_distPoller.setLabel(identity.getId()); m_distPoller.setLastUpdated(new Date()); m_distPoller.setLocation(identity.getLocation()); m_distPoller.setType(identity.getType()); }
@Override public OnmsDistPoller whoami() { final OnmsDistPoller defaultDistPoller = get(DEFAULT_DIST_POLLER_ID); if (defaultDistPoller != null) { return defaultDistPoller; } final OnmsDistPoller whoami = new OnmsDistPoller(); whoami.setId(DEFAULT_DIST_POLLER_ID); whoami.setLabel("localhost"); whoami.setLocation(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID); return whoami; } }
/** * <p>Constructor for NetworkBuilder.</p> * * @param distPollerId a {@link java.lang.String} object. */ public NetworkBuilder() { // org.opennms.netmgt.dao.api.MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID m_location = new OnmsMonitoringLocation("Default", "Default"); // org.opennms.netmgt.dao.api.DistPollerDao.DEFAULT_DIST_POLLER_ID m_distPoller = new OnmsDistPoller("00000000-0000-0000-0000-000000000000"); m_distPoller.setLabel("localhost"); // org.opennms.netmgt.dao.api.MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID m_distPoller.setLocation("Default"); m_distPoller.setType(OnmsMonitoringSystem.TYPE_OPENNMS); }
@Override public AggregationPolicy<TelemetryMessage, TelemetryProtos.TelemetryMessageLog, TelemetryProtos.TelemetryMessageLog.Builder> getAggregationPolicy() { final String systemId = distPollerDao.whoami().getId(); final String systemLocation = distPollerDao.whoami().getLocation(); return new AggregationPolicy<TelemetryMessage, TelemetryProtos.TelemetryMessageLog, TelemetryProtos.TelemetryMessageLog.Builder>() { @Override
@Test(timeout=60000) public void canProcessManyRequestsAsynchronously() throws Exception { // Execute a request via a remote location assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation()); // Lock the run method in our RPC module, we want to validate // the number of threads that are "running" the module CompletableFuture<Integer> runLockedFuture = lockingRpcModule.getRunLocker().waitForThreads(NTHREADS); // Fire off NTHREADS request ThreadLockingEchoClient client = new ThreadLockingEchoClient(rpcClientFactory, lockingRpcModule); List<CompletableFuture<EchoResponse>> futures = new ArrayList<>(); for (int i = 0; i < NTHREADS; i++) { EchoRequest request = new EchoRequest("ping"); request.setTimeToLiveMs(30000L); request.setLocation(REMOTE_LOCATION_NAME); futures.add(client.execute(request)); } // Wait for all the threads calling run() to be locked runLockedFuture.get(); // Release and verify that all the futures return lockingRpcModule.getRunLocker().release(); CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[NTHREADS])).get(); }
public OnmsDistPoller doInTransaction(TransactionStatus status) { OnmsDistPoller distPoller = m_distPollerDao.get("localhost"); if (distPoller == null) { distPoller = new OnmsDistPoller("localhost", "127.0.0.1"); m_distPollerDao.save(distPoller); } return distPoller; }
@Override protected void generateId(final OnmsDistPoller dp) { dp.setId(UUID.randomUUID().toString()); }
/** * Used for testing. */ public SyslogMessageLogDTO toMessageLog(SyslogConnection... connections) { final String systemId = distPollerDao.whoami().getId(); final String systemLocation = distPollerDao.whoami().getLocation(); if (connections.length < 1) { throw new IllegalArgumentException("One or more connection are required."); } final SyslogMessageLogDTO messageLog = new SyslogMessageLogDTO(systemLocation, systemId, connections[0].getSource()); for (SyslogConnection connection : connections) { final SyslogMessageDTO messageDTO = new SyslogMessageDTO(connection.getBuffer()); messageLog.getMessages().add(messageDTO); } return messageLog; }
@Override public OnmsDistPoller whoami() { final OnmsDistPoller defaultDistPoller = get(DEFAULT_DIST_POLLER_ID); if (defaultDistPoller != null) { return defaultDistPoller; } final OnmsDistPoller whoami = new OnmsDistPoller(); whoami.setId(DEFAULT_DIST_POLLER_ID); whoami.setLabel("localhost"); whoami.setLocation(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID); return whoami; } }
@Test(timeout=60000) public void canExecuteRpcViaRemoteLocation() throws Exception { // Execute a request via a remote location assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation()); EchoRequest request = new EchoRequest("HELLO!!!"); request.setLocation(REMOTE_LOCATION_NAME); EchoResponse expectedResponse = new EchoResponse("HELLO!!!"); EchoResponse actualResponse = echoClient.execute(request).get(); assertEquals(expectedResponse, actualResponse); } }
@Override protected void generateId(final OnmsDistPoller dp) { dp.setId(UUID.randomUUID().toString()); }
public DistPollerDaoDistributed(Identity identity) { Objects.requireNonNull(identity); m_distPoller = new OnmsDistPoller(); m_distPoller.setId(identity.getId()); m_distPoller.setLabel(identity.getId()); m_distPoller.setLastUpdated(new Date()); m_distPoller.setLocation(identity.getLocation()); m_distPoller.setType(identity.getType()); }
@Override public AggregationPolicy<SyslogConnection, SyslogMessageLogDTO, SyslogMessageLogDTO> getAggregationPolicy() { final String systemId = distPollerDao.whoami().getId(); final String systemLocation = distPollerDao.whoami().getLocation(); return new AggregationPolicy<SyslogConnection, SyslogMessageLogDTO, SyslogMessageLogDTO>() { @Override
/** * Verifies that the future fails with a {@code RequestRejectedException} when * when the client context is stopped. */ @Test(timeout=60000) public void futureFailsWithRequestRejectedExceptionWhenClientContextIsStopped() throws Exception { assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation()); // Stop the client context, this will happen when OpenNMS is shutting down getClientContext().stop(); // Now issue an RPC EchoRequest request = new EchoRequest("Helló"); request.setLocation(REMOTE_LOCATION_NAME); try { echoClient.execute(request).get(); fail(); } catch (ExecutionException e) { assertEquals(RequestRejectedException.class, e.getCause().getClass()); } }
@Override protected String getId(final OnmsDistPoller dp) { return dp == null? null : dp.getId(); }
@Override public TrapLogDTO aggregate(TrapLogDTO accumulator, TrapInformationWrapper newMessage) { final TrapInformation trapInfo = newMessage.getTrapInformation(); TrapDTO trapDTO; InetAddress trapAddress; if(trapInfo != null) { trapDTO = transformTrapInfo(trapInfo); trapAddress = TrapUtils.getEffectiveTrapAddress(trapInfo, config.shouldUseAddressFromVarbind()); } else { trapDTO = newMessage.getTrapDTO(); trapAddress = newMessage.getTrapAddress(); } if (accumulator == null) { // no log created yet accumulator = new TrapLogDTO(distPoller.getId(), distPoller.getLocation(), trapAddress); } accumulator.addMessage(trapDTO); return accumulator; }
/** * Verifies that the future fails with a {@code RemoteExecutionException} when * if an error occurs when executing remotely. */ @Test(timeout=60000) public void futureFailsWithRemoteExecutionExceptionWhenExecutingRemotely() throws Exception { assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation()); EchoRpcModule echoRpcModule = new EchoRpcModule(); CamelContext context = getContext(); context.start(); CamelRpcServerRouteManager routeManager = getRouteManager(context); routeManager.bind(echoRpcModule); EchoRequest request = new EchoRequest("Oops!"); request.shouldThrow(true); request.setLocation(REMOTE_LOCATION_NAME); try { echoClient.execute(request).get(); fail(); } catch (ExecutionException e) { assertTrue(e.getCause().getMessage(), e.getCause().getMessage().contains("Oops!")); assertEquals(RemoteExecutionException.class, e.getCause().getClass()); } routeManager.unbind(echoRpcModule); context.stop(); }
@Override public OnmsDistPoller get(String id) { if (m_distPoller.getId().equals(id)) { return m_distPoller; } else { return null; } }
@Override public TrapLogDTO aggregate(TrapLogDTO accumulator, TrapInformationWrapper newMessage) { final TrapInformation trapInfo = newMessage.getTrapInformation(); TrapDTO trapDTO; InetAddress trapAddress; if(trapInfo != null) { trapDTO = transformTrapInfo(trapInfo); trapAddress = TrapUtils.getEffectiveTrapAddress(trapInfo, config.shouldUseAddressFromVarbind()); } else { trapDTO = newMessage.getTrapDTO(); trapAddress = newMessage.getTrapAddress(); } if (accumulator == null) { // no log created yet accumulator = new TrapLogDTO(distPoller.getId(), distPoller.getLocation(), trapAddress); } accumulator.addMessage(trapDTO); return accumulator; }