Search in sources :

Example 6 with EchoResponse

use of org.opennms.core.rpc.echo.EchoResponse in project opennms by OpenNMS.

the class EchoRpcIT method canExecuteRpcViaAnotherLocation.

@Test(timeout = 60000)
public void canExecuteRpcViaAnotherLocation() 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("HELLO!!!");
    request.setLocation(REMOTE_LOCATION_NAME);
    EchoResponse expectedResponse = new EchoResponse("HELLO!!!");
    EchoResponse actualResponse = echoClient.execute(request).get();
    assertEquals(expectedResponse, actualResponse);
    routeManager.unbind(echoRpcModule);
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) EchoResponse(org.opennms.core.rpc.echo.EchoResponse) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test)

Example 7 with EchoResponse

use of org.opennms.core.rpc.echo.EchoResponse in project opennms by OpenNMS.

the class StressCommand method execute.

@Override
public Object execute() throws Exception {
    // Create the client
    final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.getClient(EchoRpcModule.INSTANCE);
    // Create metrics to capture the results
    final MetricRegistry metrics = new MetricRegistry();
    final Histogram responseTimes = metrics.histogram("response-times");
    final Counter successes = metrics.counter("successes");
    final Counter failures = metrics.counter("failures");
    // Build and issue the requests
    System.out.printf("Executing %d requests.\n", count);
    final String message = Strings.repeat("*", messageSize);
    final CountDownLatch doneSignal = new CountDownLatch(count);
    long beforeExec = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        client.execute(buildRequest(message)).whenComplete((r, e) -> {
            if (e != null) {
                failures.inc();
            } else {
                responseTimes.update(System.currentTimeMillis() - r.getId());
                successes.inc();
            }
            doneSignal.countDown();
        });
    }
    long afterExec = System.currentTimeMillis();
    // Wait for the responses...
    System.out.printf("Waiting for responses.\n");
    while (true) {
        try {
            if (doneSignal.await(1, TimeUnit.SECONDS)) {
                // Done!
                System.out.printf("\nDone!\n");
                break;
            }
        } catch (InterruptedException e) {
            System.out.println("\nInterrupted!");
            break;
        }
        System.out.print(".");
        System.out.flush();
    }
    long afterResponse = System.currentTimeMillis();
    System.out.println();
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertRatesTo(TimeUnit.MILLISECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.report();
    reporter.close();
    System.out.printf("Total miliseconds elapsed: %d\n", afterResponse - beforeExec);
    System.out.printf("Miliseconds spent generating requests: %d\n", afterExec - beforeExec);
    System.out.printf("Miliseconds spent waiting for responses: %d\n", afterResponse - afterExec);
    return null;
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) MetricRegistry(com.codahale.metrics.MetricRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 8 with EchoResponse

use of org.opennms.core.rpc.echo.EchoResponse in project opennms by OpenNMS.

the class MinionRpcMonitor method poll.

@Override
public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) {
    Long ttlInMs = ParameterMap.getKeyedLong(parameters, "ttl", DEFAULT_TTL_IN_MS);
    if (ttlInMs < 1) {
        // Use the global default
        ttlInMs = null;
    }
    int messageSize = ParameterMap.getKeyedInteger(parameters, "message-size", DEFAULT_MESSAGE_SIZE);
    if (messageSize < 0) {
        messageSize = 0;
    }
    // Create the client
    final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.get().getClient(EchoRpcModule.INSTANCE);
    // Build the request
    final OnmsNode node = nodeDao.get().get(svc.getNodeId());
    final EchoRequest request = new EchoRequest();
    request.setId(System.currentTimeMillis());
    request.setMessage(Strings.repeat("*", messageSize));
    request.setLocation(node.getLocation().getLocationName());
    request.setSystemId(node.getForeignId());
    request.setTimeToLiveMs(ttlInMs);
    try {
        final EchoResponse response = client.execute(request).get();
        final Long responseTime = System.currentTimeMillis() - response.getId();
        return PollStatus.available(responseTime.doubleValue());
    } catch (InterruptedException | ExecutionException t) {
        return RpcExceptionUtils.handleException(t, this);
    }
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) OnmsNode(org.opennms.netmgt.model.OnmsNode) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with EchoResponse

use of org.opennms.core.rpc.echo.EchoResponse in project opennms by OpenNMS.

the class EchoRpcBlueprintIT method canExecuteRpcViaCurrentLocation.

@Test(timeout = 60000)
public void canExecuteRpcViaCurrentLocation() throws Exception {
    // Execute a request via the current location
    EchoRequest request = new EchoRequest("HELLO!");
    EchoResponse expectedResponse = new EchoResponse("HELLO!");
    EchoResponse actualResponse = echoClient.execute(request).get();
    assertEquals(expectedResponse, actualResponse);
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 10 with EchoResponse

use of org.opennms.core.rpc.echo.EchoResponse in project opennms by OpenNMS.

the class EchoRpcIT method canExecuteRpcViaCurrentLocation.

@Test(timeout = 60000)
public void canExecuteRpcViaCurrentLocation() throws InterruptedException, ExecutionException {
    EchoRequest request = new EchoRequest("HELLO!");
    EchoResponse expectedResponse = new EchoResponse("HELLO!");
    EchoResponse actualResponse = echoClient.execute(request).get();
    assertEquals(expectedResponse, actualResponse);
}
Also used : EchoResponse(org.opennms.core.rpc.echo.EchoResponse) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) Test(org.junit.Test)

Aggregations

EchoRequest (org.opennms.core.rpc.echo.EchoRequest)11 EchoResponse (org.opennms.core.rpc.echo.EchoResponse)11 Test (org.junit.Test)8 CamelContext (org.apache.camel.CamelContext)5 EchoRpcModule (org.opennms.core.rpc.echo.EchoRpcModule)5 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 Counter (com.codahale.metrics.Counter)2 Histogram (com.codahale.metrics.Histogram)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)2 ExecutionException (java.util.concurrent.ExecutionException)1 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1