public <T extends RpcService> BindingDOMRpcImplementationAdapter(final BindingNormalizedNodeCodecRegistry codec, final Class<T> type ,final T delegate) {
this.codec = codec;
this.delegate = delegate;
- this.invoker = RpcServiceInvoker.from(type);
- this.module = BindingReflections.getQNameModule(type);
+ invoker = RpcServiceInvoker.from(type);
+ module = BindingReflections.getQNameModule(type);
}
public QNameModule getQNameModule() {
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
final SchemaPath schemaPath = rpc.getType();
- final DataObject bindingInput = deserilialize(rpc.getType(),input);
+ final DataObject bindingInput = input != null ? deserilialize(rpc.getType(),input) : null;
final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath,bindingInput);
return transformResult(schemaPath,bindingResult);
}
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.JdkFutureAdapters;
import com.google.common.util.concurrent.ListenableFuture;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation;
private static final Function<? super Exception, DOMRpcException> EXCEPTION_MAPPER = new Function<Exception, DOMRpcException>() {
@Override
- public DOMRpcException apply(Exception input) {
+ public DOMRpcException apply(final Exception input) {
// FIXME: Return correct exception
return null;
}
private final RpcService delegate;
private final QNameModule module;
- private Function<RpcResult<?>,DOMRpcResult> lazySerializedMapper = new Function<RpcResult<?>,DOMRpcResult>() {
+ private final Function<RpcResult<?>,DOMRpcResult> lazySerializedMapper = new Function<RpcResult<?>,DOMRpcResult>() {
@Override
public DOMRpcResult apply(final RpcResult<?> input) {
}
};
- public <T extends RpcService> BindingRpcImplementationAdapter(BindingNormalizedNodeCodecRegistry codec, Class<T> type ,T delegate) {
+ public <T extends RpcService> BindingRpcImplementationAdapter(final BindingNormalizedNodeCodecRegistry codec, final Class<T> type ,final T delegate) {
this.codec = codec;
this.delegate = delegate;
- this.invoker = RpcServiceInvoker.from(type);
- this.module = BindingReflections.getQNameModule(type);
+ invoker = RpcServiceInvoker.from(type);
+ module = BindingReflections.getQNameModule(type);
}
public QNameModule getQNameModule() {
}
@Override
- public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(DOMRpcIdentifier rpc, NormalizedNode<?, ?> input) {
- SchemaPath schemaPath = rpc.getType();
- DataObject bindingInput = deserilialize(rpc.getType(),input);
- ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath,bindingInput);
+ public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final DOMRpcIdentifier rpc, @Nullable final NormalizedNode<?, ?> input) {
+ final SchemaPath schemaPath = rpc.getType();
+ final DataObject bindingInput = input != null ? deserilialize(rpc.getType(),input) : null;
+ final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath, bindingInput);
return transformResult(schemaPath,bindingResult);
}
- private DataObject deserilialize(SchemaPath rpcPath, NormalizedNode<?, ?> input) {
+ private DataObject deserilialize(final SchemaPath rpcPath, final NormalizedNode<?, ?> input) {
if(input instanceof LazySerializedContainerNode) {
return ((LazySerializedContainerNode) input).bindingData();
}
- SchemaPath inputSchemaPath = rpcPath.createChild(QName.create(module,"input"));
+ final SchemaPath inputSchemaPath = rpcPath.createChild(QName.create(module,"input"));
return codec.fromNormalizedNodeRpcData(inputSchemaPath, (ContainerNode) input);
}
- private ListenableFuture<RpcResult<?>> invoke(SchemaPath schemaPath, DataObject input) {
+ private ListenableFuture<RpcResult<?>> invoke(final SchemaPath schemaPath, final DataObject input) {
return JdkFutureAdapters.listenInPoolThread(invoker.invokeRpc(delegate, schemaPath.getLastComponent(), input));
}
- private CheckedFuture<DOMRpcResult, DOMRpcException> transformResult(SchemaPath schemaPath,
- ListenableFuture<RpcResult<?>> bindingResult) {
- ListenableFuture<DOMRpcResult> transformed = Futures.transform(bindingResult, lazySerializedMapper);
+ private CheckedFuture<DOMRpcResult, DOMRpcException> transformResult(final SchemaPath schemaPath,
+ final ListenableFuture<RpcResult<?>> bindingResult) {
+ final ListenableFuture<DOMRpcResult> transformed = Futures.transform(bindingResult, lazySerializedMapper);
return Futures.makeChecked(transformed, EXCEPTION_MAPPER);
}
import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
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;
public interface MessageTransformer<M> {
ContainerNode toNotification(M message);
- M toRpcRequest(SchemaPath rpc, ContainerNode node);
+ M toRpcRequest(SchemaPath rpc, NormalizedNode<?, ?> node);
DOMRpcResult toRpcResult(M message, SchemaPath rpc);
package org.opendaylight.controller.sal.connect.netconf.sal;
import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import org.opendaylight.controller.sal.connect.api.RemoteDeviceCommunicator;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.common.RpcResult;
-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.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@Nonnull
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final SchemaPath type, @Nullable final NormalizedNode<?, ?> input) {
- Preconditions.checkArgument(input instanceof ContainerNode, "Epc payload has to be a %s, was %s", ContainerNode.class, input);
-
- final NetconfMessage message = transformer.toRpcRequest(type, (ContainerNode) input);
+ final NetconfMessage message = transformer.toRpcRequest(type, input);
final ListenableFuture<RpcResult<NetconfMessage>> delegateFutureWithPureResult = listener.sendRequest(message, type.getLastComponent());
final ListenableFuture<DOMRpcResult> transformed = Futures.transform(delegateFutureWithPureResult, new Function<RpcResult<NetconfMessage>, DOMRpcResult>() {
}
@Override
- public NetconfMessage toRpcRequest(SchemaPath rpc, final ContainerNode payload) {
+ public NetconfMessage toRpcRequest(SchemaPath rpc, final NormalizedNode<?, ?> payload) {
// In case no input for rpc is defined, we can simply construct the payload here
final QName rpcQName = rpc.getLastComponent();
Map<QName, RpcDefinition> currentMappedRpcs = mappedRpcs;
return new NetconfMessage(document);
}
+ Preconditions.checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpcQName);
+ Preconditions.checkArgument(payload instanceof ContainerNode,
+ "Transforming an rpc with input: %s, payload has to be a container, but was: %s", rpcQName, payload);
+
// Set the path to the input of rpc for the node stream writer
rpc = rpc.createChild(QName.cachedReference(QName.create(rpcQName, "input")));
final DOMResult result = prepareDomResultForRpcRequest(rpcQName);
try {
// If the schema context for netconf device does not contain model for base netconf operations, use default pre build context with just the base model
// This way operations like lock/unlock are supported even if the source for base model was not provided
- writeNormalizedRpc(payload, result, rpc, needToUseBaseCtx ? BASE_NETCONF_CTX : schemaContext);
+ writeNormalizedRpc(((ContainerNode) payload), result, rpc, needToUseBaseCtx ? BASE_NETCONF_CTX : schemaContext);
} catch (final XMLStreamException | IOException | IllegalStateException e) {
throw new IllegalStateException("Unable to serialize " + rpc, e);
}
import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
import org.opendaylight.controller.sal.core.api.RpcImplementation;
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.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public MessageTransformer<NetconfMessage> getMessageTransformer() throws Exception {
final MessageTransformer<NetconfMessage> messageTransformer = mockClass(MessageTransformer.class);
- doReturn(notification).when(messageTransformer).toRpcRequest(any(SchemaPath.class), any(ContainerNode.class));
+ doReturn(notification).when(messageTransformer).toRpcRequest(any(SchemaPath.class), any(NormalizedNode.class));
doReturn(rpcResultC).when(messageTransformer).toRpcResult(any(NetconfMessage.class), any(SchemaPath.class));
doReturn(compositeNode).when(messageTransformer).toNotification(any(NetconfMessage.class));
return messageTransformer;
@Test
public void testDiscardChangesRequest() throws Exception {
- final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME),
- NetconfMessageTransformUtil.DISCARD_CHANGES_RPC_CONTENT);
+ final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME), null);
assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<discard"));
}
"</rpc>");
}
-
@Test
public void tesGetSchemaResponse() throws Exception {
final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true));