Search in sources :

Example 1 with RpcbenchPayloadService

use of org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.RpcbenchPayloadService in project controller by opendaylight.

the class RpcbenchmarkProvider method startTest.

@Override
public Future<RpcResult<StartTestOutput>> startTest(final StartTestInput input) {
    LOG.debug("startTest {}", input);
    final RTCClient client;
    final List<RoutedRpcRegistration<?>> rpcRegs = new ArrayList<>();
    switch(input.getOperation()) {
        case ROUTEDRTC:
            List<InstanceIdentifier<?>> routeIid = new ArrayList<>();
            for (int i = 0; i < input.getNumServers().intValue(); i++) {
                GlobalBindingRTCServer server = new GlobalBindingRTCServer();
                RoutedRpcRegistration<RpcbenchPayloadService> routedReg = providerRegistry.addRoutedRpcImplementation(RpcbenchPayloadService.class, server);
                KeyedInstanceIdentifier<RpcRoute, RpcRouteKey> iid = InstanceIdentifier.create(RpcbenchRpcRoutes.class).child(RpcRoute.class, new RpcRouteKey(Integer.toString(i)));
                routeIid.add(iid);
                routedReg.registerPath(NodeContext.class, iid);
                rpcRegs.add(routedReg);
            }
            client = new RoutedBindingRTClient(providerRegistry, input.getPayloadSize().intValue(), routeIid);
            break;
        case GLOBALRTC:
            client = new GlobalBindingRTCClient(providerRegistry, input.getPayloadSize().intValue());
            break;
        default:
            LOG.error("Unsupported server/client type {}", input.getOperation());
            throw new IllegalArgumentException("Unsupported server/client type" + input.getOperation());
    }
    try {
        ExecutorService executor = Executors.newFixedThreadPool(input.getNumClients().intValue());
        final Runnable testRun = () -> client.runTest(input.getIterations().intValue());
        LOG.info("Test Started");
        long startTime = System.nanoTime();
        for (int i = 0; i < input.getNumClients().intValue(); i++) {
            executor.submit(testRun);
        }
        executor.shutdown();
        try {
            executor.awaitTermination(testTimeout, TimeUnit.MINUTES);
        } catch (final InterruptedException e) {
            LOG.error("Out of time: test did not finish within the {} min deadline ", testTimeout);
        }
        long endTime = System.nanoTime();
        LOG.info("Test Done");
        long elapsedTime = endTime - startTime;
        StartTestOutput output = new StartTestOutputBuilder().setRate((long) 0).setGlobalRtcClientError(client.getRpcError()).setGlobalRtcClientOk(client.getRpcOk()).setExecTime(TimeUnit.NANOSECONDS.toMillis(elapsedTime)).setRate((client.getRpcOk() + client.getRpcError()) * 1000000000 / elapsedTime).build();
        return RpcResultBuilder.success(output).buildFuture();
    } finally {
        for (RoutedRpcRegistration<?> routedRpcRegistration : rpcRegs) {
            routedRpcRegistration.close();
        }
    }
}
Also used : RpcRoute(org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.rpcbench.rpc.routes.RpcRoute) RpcbenchRpcRoutes(org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.RpcbenchRpcRoutes) ArrayList(java.util.ArrayList) RoutedRpcRegistration(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration) RpcbenchPayloadService(org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.RpcbenchPayloadService) ExecutorService(java.util.concurrent.ExecutorService) StartTestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rpcbenchmark.rev150702.StartTestOutput) StartTestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rpcbenchmark.rev150702.StartTestOutputBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) RpcRouteKey(org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.rpcbench.rpc.routes.RpcRouteKey)

Aggregations

ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 RoutedRpcRegistration (org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration)1 RpcbenchPayloadService (org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.RpcbenchPayloadService)1 RpcbenchRpcRoutes (org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.RpcbenchRpcRoutes)1 RpcRoute (org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.rpcbench.rpc.routes.RpcRoute)1 RpcRouteKey (org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.rpcbench.rpc.routes.RpcRouteKey)1 StartTestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rpcbenchmark.rev150702.StartTestOutput)1 StartTestOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rpcbenchmark.rev150702.StartTestOutputBuilder)1 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)1 KeyedInstanceIdentifier (org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)1