import org.opendaylight.controller.remote.rpc.messages.ExecuteAction;
import org.opendaylight.controller.remote.rpc.messages.ExecuteRpc;
import org.opendaylight.controller.remote.rpc.messages.RpcResponse;
-import org.opendaylight.mdsal.dom.api.DOMActionResult;
import org.opendaylight.mdsal.dom.api.DOMActionService;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
/**
* Actor receiving invocation requests from remote nodes, routing them to
@Override
protected void handleReceive(final Object message) {
- if (message instanceof ExecuteRpc) {
+ if (message instanceof ExecuteRpc executeRpc) {
LOG.debug("Handling ExecuteOps Message");
- execute((ExecuteRpc) message);
- } else if (message instanceof ExecuteAction) {
- execute((ExecuteAction) message);
+ execute(executeRpc);
+ } else if (message instanceof ExecuteAction executeAction) {
+ execute(executeAction);
} else {
unknownMessage(message);
}
return;
}
- Futures.addCallback(future, new AbstractCallback<DOMRpcResult>(getSender(), msg.getType()) {
+ Futures.addCallback(future, new AbstractCallback<QName, DOMRpcResult>(getSender(), msg.getType()) {
@Override
- Object nullResponse(final SchemaPath type) {
+ Object nullResponse(final QName type) {
LOG.warn("Execution of {} resulted in null result", type);
return new RpcResponse(null);
}
@Override
- Object response(final SchemaPath type, final DOMRpcResult result) {
- final Collection<? extends RpcError> errors = result.getErrors();
- return errors.isEmpty() ? new RpcResponse(result.getResult())
+ Object response(final QName type, final DOMRpcResult result) {
+ final Collection<? extends RpcError> errors = result.errors();
+ return errors.isEmpty() ? new RpcResponse(result.value())
// This is legacy (wrong) behavior, which ignores the fact that errors may be just warnings,
// discarding any output
: new Failure(new RpcErrorsException(String.format("Execution of rpc %s failed", type),
final ActorRef sender = getSender();
- final ListenableFuture<? extends DOMActionResult> future;
+ final ListenableFuture<? extends DOMRpcResult> future;
try {
future = actionService.invokeAction(msg.getType(), msg.getPath(), msg.getInput());
} catch (final RuntimeException e) {
return;
}
- Futures.addCallback(future, new AbstractCallback<DOMActionResult>(getSender(), msg.getType()) {
+ Futures.addCallback(future, new AbstractCallback<Absolute, DOMRpcResult>(getSender(), msg.getType()) {
@Override
- Object nullResponse(final SchemaPath type) {
+ Object nullResponse(final Absolute type) {
throw new IllegalStateException("Null invocation result of action " + type);
}
@Override
- Object response(final SchemaPath type, final DOMActionResult result) {
- final Collection<? extends RpcError> errors = result.getErrors();
- return errors.isEmpty() ? new ActionResponse(result.getOutput(), result.getErrors())
+ Object response(final Absolute type, final DOMRpcResult result) {
+ final var errors = result.errors();
+ return errors.isEmpty() ? new ActionResponse(result.value(), errors)
// This is legacy (wrong) behavior, which ignores the fact that errors may be just warnings,
// discarding any output
: new Failure(new RpcErrorsException(String.format("Execution of action %s failed", type),
}, MoreExecutors.directExecutor());
}
- private abstract class AbstractCallback<T> implements FutureCallback<T> {
+ private abstract class AbstractCallback<T, R> implements FutureCallback<R> {
private final ActorRef replyTo;
- private final SchemaPath type;
+ private final T type;
- AbstractCallback(final ActorRef replyTo, final SchemaPath type) {
+ AbstractCallback(final ActorRef replyTo, final T type) {
this.replyTo = requireNonNull(replyTo);
this.type = requireNonNull(type);
}
@Override
- public final void onSuccess(final T result) {
+ public final void onSuccess(final R result) {
final Object response;
if (result == null) {
// This shouldn't happen but the FutureCallback annotates the result param with Nullable so handle null
replyTo.tell(new Failure(failure), self());
}
- abstract @NonNull Object nullResponse(@NonNull SchemaPath type);
+ abstract @NonNull Object nullResponse(@NonNull T type);
- abstract @NonNull Object response(@NonNull SchemaPath type, @NonNull T result);
+ abstract @NonNull Object response(@NonNull T type, @NonNull R result);
}
}