use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.
the class BindingDOMRpcImplementationAdapter method invokeRpc.
@Nonnull
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
final SchemaPath schemaPath = rpc.getType();
final DataObject bindingInput = input != null ? deserialize(rpc.getType(), input) : null;
final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath, bindingInput);
return transformResult(bindingResult);
}
use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.
the class DOMNotificationRouter method registerNotificationListener.
@Override
public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener, final Collection<SchemaPath> types) {
final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) {
@Override
protected void removeRegistration() {
final ListenerRegistration<T> me = this;
synchronized (DOMNotificationRouter.this) {
replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, input -> input != me)));
}
}
};
if (!types.isEmpty()) {
final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap.builder();
b.putAll(listeners);
for (final SchemaPath t : types) {
b.put(t, reg);
}
replaceListeners(b.build());
}
return reg;
}
use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.
the class RpcInvoker method executeRpc.
@SuppressWarnings("checkstyle:IllegalCatch")
private void executeRpc(final ExecuteRpc msg) {
LOG.debug("Executing rpc {}", msg.getRpc());
final SchemaPath schemaPath = SchemaPath.create(true, msg.getRpc());
final ActorRef sender = getSender();
final ActorRef self = self();
final ListenableFuture<DOMRpcResult> future;
try {
future = rpcService.invokeRpc(schemaPath, msg.getInputNormalizedNode());
} catch (final RuntimeException e) {
LOG.debug("Failed to invoke RPC {}", msg.getRpc(), e);
sender.tell(new akka.actor.Status.Failure(e), sender);
return;
}
Futures.addCallback(future, new FutureCallback<DOMRpcResult>() {
@Override
public void onSuccess(final DOMRpcResult result) {
if (result == null) {
// This shouldn't happen but the FutureCallback annotates the result param with Nullable so
// handle null here to avoid FindBugs warning.
LOG.debug("Got null DOMRpcResult - sending null response for execute rpc : {}", msg.getRpc());
sender.tell(new RpcResponse(null), self);
return;
}
if (!result.getErrors().isEmpty()) {
final String message = String.format("Execution of RPC %s failed", msg.getRpc());
sender.tell(new akka.actor.Status.Failure(new RpcErrorsException(message, result.getErrors())), self);
} else {
LOG.debug("Sending response for execute rpc : {}", msg.getRpc());
sender.tell(new RpcResponse(result.getResult()), self);
}
}
@Override
public void onFailure(final Throwable failure) {
LOG.debug("Failed to execute RPC {}", msg.getRpc(), failure);
LOG.error("Failed to execute RPC {} due to {}. More details are available on DEBUG level.", msg.getRpc(), Throwables.getRootCause(failure));
sender.tell(new akka.actor.Status.Failure(failure), self);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.
the class DOMRpcServiceTestBugfix560 method test.
@Test
public void test() throws ExecutionException, InterruptedException {
// FIXME: This is made to only make sure instance identifier codec for path is instantiated.
domMountPointService.createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {
@Override
public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0, final NormalizedNode<?, ?> arg1) {
final DOMRpcResult result = new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
return Futures.immediateCheckedFuture(result);
}
}).register();
final Optional<MountPoint> mountInstance = bindingMountPointService.getMountPoint(BA_MOUNT_ID);
assertTrue(mountInstance.isPresent());
final Optional<RpcConsumerRegistry> rpcRegistry = mountInstance.get().getService(RpcConsumerRegistry.class);
assertTrue(rpcRegistry.isPresent());
final OpendaylightTestRpcServiceService rpcService = rpcRegistry.get().getRpcService(OpendaylightTestRpcServiceService.class);
assertNotNull(rpcService);
try {
final Future<RpcResult<Void>> result = rpcService.rockTheHouse(new RockTheHouseInputBuilder().build());
assertTrue(result.get().isSuccessful());
} catch (final IllegalStateException ex) {
fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
}
}
use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.
the class RpcServiceAdapter method transformFuture.
private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc, final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
return Futures.transform(domFuture, input -> {
final NormalizedNode<?, ?> domData = input.getResult();
final DataObject bindingResult;
if (domData != null) {
final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
} else {
bindingResult = null;
}
// DOMRpcResult does not have a notion of success, hence we have to reverse-engineer it by looking
// at reported errors and checking whether they are just warnings.
final Collection<RpcError> errors = input.getErrors();
return RpcResult.class.cast(RpcResultBuilder.status(errors.stream().noneMatch(error -> error.getSeverity() == ErrorSeverity.ERROR)).withResult(bindingResult).withRpcErrors(errors).build());
}, MoreExecutors.directExecutor());
}
Aggregations