package org.opendaylight.controller.md.sal.binding.impl;
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.Collection;
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
private static boolean isObjectMethod(final Method m) {
switch (m.getName()) {
case "toString":
- return (m.getReturnType().equals(String.class) && m.getParameterTypes().length == 0);
+ return m.getReturnType().equals(String.class) && m.getParameterTypes().length == 0;
case "hashCode":
- return (m.getReturnType().equals(int.class) && m.getParameterTypes().length == 0);
+ return m.getReturnType().equals(int.class) && m.getParameterTypes().length == 0;
case "equals":
- return (m.getReturnType().equals(boolean.class) && m.getParameterTypes().length == 1 && m
- .getParameterTypes()[0] == Object.class);
+ return m.getReturnType().equals(boolean.class) && m.getParameterTypes().length == 1 && m
+ .getParameterTypes()[0] == Object.class;
default:
return false;
}
case "hashCode":
return System.identityHashCode(self);
case "equals":
- return (self == args[0]);
+ return self == args[0];
default:
return null;
}
private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc,
final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
- return Futures.transform(domFuture, (Function<DOMRpcResult, RpcResult<?>>) input -> {
+ return Futures.transform(domFuture, input -> {
final NormalizedNode<?, ?> domData = input.getResult();
final DataObject bindingResult;
if (domData != null) {
} else {
bindingResult = null;
}
- return RpcResult.class.cast(RpcResultBuilder.success(bindingResult).build());
- });
+
+ // 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());
}
private abstract class RpcInvocationStrategy {