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();
}
}
}
Aggregations