import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps.getSourceNode;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
// Keepalive RPC static resources
private static final @NonNull ContainerNode KEEPALIVE_PAYLOAD =
NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID,
- getSourceNode(NETCONF_RUNNING_QNAME), NetconfMessageTransformUtil.EMPTY_FILTER);
+ getSourceNode(NETCONF_RUNNING_NODEID), NetconfMessageTransformUtil.EMPTY_FILTER);
/**
* Invoke keepalive RPC and check the response. In case of any received response the keepalive
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.COMMIT_RPC_CONTENT;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.EDIT_CONTENT_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.GET_RPC_CONTENT;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_SOURCE_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_TARGET_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_UNLOCK_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.ROLLBACK_ON_ERROR_OPTION;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.FutureCallback;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.get.config.input.source.ConfigSource;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
* Provides base operations for NETCONF e.g. {@code get}, {@code get-config}, {@code edit-config}, {@code commit} etc.
* as per <a href="https://www.rfc-editor.org/rfc/rfc6241#section-7">RFC6241 Protocol Operations</a>.
*/
-// FIXME: datastore etc. should require NodeIdentifier instead of QName to reduce GC pressure
// FIXME: turn Optional arguments to @Nullable
public final class NetconfBaseOps {
private static final NodeIdentifier CONFIG_SOURCE_NODEID = NodeIdentifier.create(ConfigSource.QNAME);
}
public ListenableFuture<? extends DOMRpcResult> lock(final FutureCallback<DOMRpcResult> callback,
- final QName datastore) {
+ final NodeIdentifier datastore) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_LOCK_QNAME, getLockContent(datastore)));
}
public ListenableFuture<? extends DOMRpcResult> lockCandidate(final FutureCallback<DOMRpcResult> callback) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_LOCK_QNAME,
- getLockContent(NETCONF_CANDIDATE_QNAME)));
+ getLockContent(NETCONF_CANDIDATE_NODEID)));
}
public ListenableFuture<? extends DOMRpcResult> lockRunning(final FutureCallback<DOMRpcResult> callback) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_LOCK_QNAME,
- getLockContent(NETCONF_RUNNING_QNAME)));
+ getLockContent(NETCONF_RUNNING_NODEID)));
}
public ListenableFuture<? extends DOMRpcResult> unlock(final FutureCallback<DOMRpcResult> callback,
- final QName datastore) {
+ final NodeIdentifier datastore) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_UNLOCK_QNAME,
getUnLockContent(datastore)));
}
public ListenableFuture<? extends DOMRpcResult> unlockRunning(final FutureCallback<DOMRpcResult> callback) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_UNLOCK_QNAME,
- getUnLockContent(NETCONF_RUNNING_QNAME)));
+ getUnLockContent(NETCONF_RUNNING_NODEID)));
}
public ListenableFuture<? extends DOMRpcResult> unlockCandidate(final FutureCallback<DOMRpcResult> callback) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_UNLOCK_QNAME,
- getUnLockContent(NETCONF_CANDIDATE_QNAME)));
+ getUnLockContent(NETCONF_CANDIDATE_NODEID)));
}
public ListenableFuture<? extends DOMRpcResult> discardChanges(final FutureCallback<DOMRpcResult> callback) {
}
public ListenableFuture<? extends DOMRpcResult> validate(final FutureCallback<DOMRpcResult> callback,
- final QName datastore) {
+ final NodeIdentifier datastore) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_VALIDATE_QNAME,
getValidateContent(requireNonNull(datastore))));
}
public ListenableFuture<? extends DOMRpcResult> validateCandidate(final FutureCallback<DOMRpcResult> callback) {
- return validate(callback, NETCONF_CANDIDATE_QNAME);
+ return validate(callback, NETCONF_CANDIDATE_NODEID);
}
public ListenableFuture<? extends DOMRpcResult> validateRunning(final FutureCallback<DOMRpcResult> callback) {
- return validate(callback, NETCONF_RUNNING_QNAME);
+ return validate(callback, NETCONF_RUNNING_NODEID);
}
public ListenableFuture<? extends DOMRpcResult> copyConfig(final FutureCallback<DOMRpcResult> callback,
- final QName source, final QName target) {
+ final NodeIdentifier sourceDatastore, final NodeIdentifier targetDatastore) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_COPY_CONFIG_QNAME,
- getCopyConfigContent(source, target)));
+ getCopyConfigContent(sourceDatastore, targetDatastore)));
}
public ListenableFuture<? extends DOMRpcResult> copyRunningToCandidate(
final FutureCallback<DOMRpcResult> callback) {
- return copyConfig(callback, NETCONF_RUNNING_QNAME, NETCONF_CANDIDATE_QNAME);
+ return copyConfig(callback, NETCONF_RUNNING_NODEID, NETCONF_CANDIDATE_NODEID);
}
public ListenableFuture<? extends DOMRpcResult> getConfig(final FutureCallback<DOMRpcResult> callback,
- final QName datastore, final Optional<YangInstanceIdentifier> filterPath) {
+ final NodeIdentifier datastore, final Optional<YangInstanceIdentifier> filterPath) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_GET_CONFIG_QNAME, nonEmptyFilter(filterPath)
.map(path -> NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID,
getSourceNode(datastore), transformer.toFilterStructure(path)))
}
private ListenableFuture<? extends DOMRpcResult> getConfig(final FutureCallback<DOMRpcResult> callback,
- final QName datastore, final Optional<YangInstanceIdentifier> filterPath,
+ final NodeIdentifier datastore, final Optional<YangInstanceIdentifier> filterPath,
final List<YangInstanceIdentifier> fields) {
final ContainerNode rpcInput;
if (nonEmptyFilter(filterPath).isPresent()) {
public ListenableFuture<? extends DOMRpcResult> getConfigRunning(final FutureCallback<DOMRpcResult> callback,
final Optional<YangInstanceIdentifier> filterPath) {
- return getConfig(callback, NETCONF_RUNNING_QNAME, filterPath);
+ return getConfig(callback, NETCONF_RUNNING_NODEID, filterPath);
}
private ListenableFuture<? extends DOMRpcResult> getConfigRunning(final FutureCallback<DOMRpcResult> callback,
final Optional<YangInstanceIdentifier> filterPath, final List<YangInstanceIdentifier> fields) {
- return getConfig(callback, NETCONF_RUNNING_QNAME, filterPath, fields);
+ return getConfig(callback, NETCONF_RUNNING_NODEID, filterPath, fields);
}
public ListenableFuture<? extends DOMRpcResult> getConfigCandidate(final FutureCallback<DOMRpcResult> callback,
final Optional<YangInstanceIdentifier> filterPath) {
- return getConfig(callback, NETCONF_CANDIDATE_QNAME, filterPath);
+ return getConfig(callback, NETCONF_CANDIDATE_NODEID, filterPath);
}
public ListenableFuture<? extends DOMRpcResult> get(final FutureCallback<DOMRpcResult> callback,
public ListenableFuture<? extends DOMRpcResult> editConfigCandidate(
final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
final ModifyAction modifyAction, final boolean rollback) {
- return editConfig(callback, NETCONF_CANDIDATE_QNAME, editStructure, Optional.of(modifyAction), rollback);
+ return editConfig(callback, NETCONF_CANDIDATE_NODEID, editStructure, Optional.of(modifyAction), rollback);
}
public ListenableFuture<? extends DOMRpcResult> editConfigCandidate(
final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
final boolean rollback) {
- return editConfig(callback, NETCONF_CANDIDATE_QNAME, editStructure, Optional.empty(), rollback);
+ return editConfig(callback, NETCONF_CANDIDATE_NODEID, editStructure, Optional.empty(), rollback);
}
public ListenableFuture<? extends DOMRpcResult> editConfigRunning(
final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
final ModifyAction modifyAction, final boolean rollback) {
- return editConfig(callback, NETCONF_RUNNING_QNAME, editStructure, Optional.of(modifyAction), rollback);
+ return editConfig(callback, NETCONF_RUNNING_NODEID, editStructure, Optional.of(modifyAction), rollback);
}
public ListenableFuture<? extends DOMRpcResult> editConfigRunning(
final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
final boolean rollback) {
- return editConfig(callback, NETCONF_RUNNING_QNAME, editStructure, Optional.empty(), rollback);
+ return editConfig(callback, NETCONF_RUNNING_NODEID, editStructure, Optional.empty(), rollback);
}
public ListenableFuture<? extends DOMRpcResult> editConfig(
- final FutureCallback<? super DOMRpcResult> callback, final QName datastore,
+ final FutureCallback<? super DOMRpcResult> callback, final NodeIdentifier datastore,
final DataContainerChild editStructure, final Optional<ModifyAction> modifyAction,
final boolean rollback) {
return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_EDIT_CONFIG_QNAME,
.build();
}
- private static ContainerNode getEditConfigContent(final QName datastore, final DataContainerChild editStructure,
- final Optional<ModifyAction> defaultOperation, final boolean rollback) {
+ private static ContainerNode getEditConfigContent(final NodeIdentifier datastore,
+ final DataContainerChild editStructure, final Optional<ModifyAction> defaultOperation,
+ final boolean rollback) {
final var editBuilder = Builders.containerBuilder()
.withNodeIdentifier(NETCONF_EDIT_CONFIG_NODEID)
// Target
return editBuilder.withChild(editStructure).build();
}
- public static @NonNull ContainerNode getSourceNode(final QName datastore) {
+ public static @NonNull ContainerNode getSourceNode(final NodeIdentifier datastore) {
return Builders.containerBuilder()
.withNodeIdentifier(NETCONF_SOURCE_NODEID)
.withChild(Builders.choiceBuilder()
.build();
}
- public static @NonNull ContainerNode getLockContent(final QName datastore) {
+ public static @NonNull ContainerNode getLockContent(final NodeIdentifier datastore) {
return Builders.containerBuilder()
.withNodeIdentifier(NETCONF_LOCK_NODEID)
.withChild(getTargetNode(datastore))
.build();
}
- public static @NonNull ContainerNode getTargetNode(final QName datastore) {
+ public static @NonNull ContainerNode getTargetNode(final NodeIdentifier datastore) {
return Builders.containerBuilder()
.withNodeIdentifier(NETCONF_TARGET_NODEID)
.withChild(Builders.choiceBuilder()
.withNodeIdentifier(CONFIG_TARGET_NODEID)
- .withChild(ImmutableNodes.leafNode(toId(datastore), Empty.value()))
+ .withChild(ImmutableNodes.leafNode(datastore, Empty.value()))
.build())
.build();
}
- public static @NonNull ContainerNode getCopyConfigContent(final QName source, final QName target) {
+ public static @NonNull ContainerNode getCopyConfigContent(final NodeIdentifier sourceDatastore,
+ final NodeIdentifier targetDatastore) {
return Builders.containerBuilder()
.withNodeIdentifier(NETCONF_COPY_CONFIG_NODEID)
- .withChild(getTargetNode(target))
- .withChild(getSourceNode(source))
+ .withChild(getTargetNode(targetDatastore))
+ .withChild(getSourceNode(sourceDatastore))
.build();
}
- public static @NonNull ContainerNode getValidateContent(final QName source) {
+ public static @NonNull ContainerNode getValidateContent(final NodeIdentifier sourceDatastore) {
return Builders.containerBuilder()
.withNodeIdentifier(NETCONF_VALIDATE_NODEID)
- .withChild(getSourceNode(source))
+ .withChild(getSourceNode(sourceDatastore))
.build();
}
- public static @NonNull ContainerNode getUnLockContent(final QName datastore) {
+ public static @NonNull ContainerNode getUnLockContent(final NodeIdentifier datastore) {
return Builders.containerBuilder()
.withNodeIdentifier(NETCONF_UNLOCK_NODEID)
.withChild(getTargetNode(datastore))
public static final @NonNull NodeIdentifier NETCONF_ERROR_OPTION_NODEID =
NodeIdentifier.create(NETCONF_ERROR_OPTION_QNAME);
public static final @NonNull QName NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running").intern();
+ public static final @NonNull NodeIdentifier NETCONF_RUNNING_NODEID = NodeIdentifier.create(NETCONF_RUNNING_QNAME);
public static final @NonNull QName NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source").intern();
public static final @NonNull NodeIdentifier NETCONF_SOURCE_NODEID = NodeIdentifier.create(NETCONF_SOURCE_QNAME);
public static final @NonNull QName NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate").intern();
+ public static final @NonNull NodeIdentifier NETCONF_CANDIDATE_NODEID =
+ NodeIdentifier.create(NETCONF_CANDIDATE_QNAME);
public static final @NonNull QName NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target").intern();
public static final @NonNull NodeIdentifier NETCONF_TARGET_NODEID = NodeIdentifier.create(NETCONF_TARGET_QNAME);
public static final @NonNull QName NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config").intern();
ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause());
}
- public static NodeIdentifier toId(final PathArgument qname) {
- return qname instanceof NodeIdentifier ? (NodeIdentifier) qname : toId(qname.getNodeType());
+ public static NodeIdentifier toId(final PathArgument arg) {
+ return arg instanceof NodeIdentifier nodeId ? nodeId : toId(arg.getNodeType());
}
public static NodeIdentifier toId(final QName nodeType) {
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps.getSourceNode;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
import com.google.common.util.concurrent.SettableFuture;
import java.net.InetSocketAddress;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
new RemoteDeviceId("test", new InetSocketAddress("localhost", 22));
private static final @NonNull ContainerNode KEEPALIVE_PAYLOAD =
NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID,
- getSourceNode(NETCONF_RUNNING_QNAME), NetconfMessageTransformUtil.EMPTY_FILTER);
+ getSourceNode(NETCONF_RUNNING_NODEID), NetconfMessageTransformUtil.EMPTY_FILTER);
private KeepaliveSalFacade keepaliveSalFacade;
private ScheduledExecutorService executorService;
//This settable future will be used to check the invokation of keepalive RPC. Should be never invoked.
final SettableFuture<DOMRpcResult> keepaliveSettableFuture = SettableFuture.create();
- final DOMRpcResult keepaliveResult = new DefaultDOMRpcResult(Builders.containerBuilder().withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME)).build());
- keepaliveSettableFuture.set(keepaliveResult);
+ keepaliveSettableFuture.set(new DefaultDOMRpcResult(Builders.containerBuilder()
+ .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID)
+ .build()));
keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
@Test
public void testKeepaliveSuccess() throws Exception {
- final DOMRpcResult result = new DefaultDOMRpcResult(Builders.containerBuilder().withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME)).build());
-
- doReturn(FluentFutures.immediateFluentFuture(result))
- .when(deviceRpc).invokeRpc(any(QName.class), any(ContainerNode.class));
+ doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(Builders.containerBuilder()
+ .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID)
+ .build()))).when(deviceRpc).invokeRpc(any(QName.class), any(ContainerNode.class));
keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
*/
package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_FILTER_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
}
@Test
- public void testDiscardChanges() throws InterruptedException {
+ public void testDiscardChanges() {
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((ContainerNode) null)))
.when(rpc).invokeRpc(any(QName.class), isNull());
- final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)),
- false);
- try {
- tx.commit().get();
- } catch (final ExecutionException e) {
- // verify discard changes was sent
- final InOrder inOrder = inOrder(rpc);
- inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME,
- NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME));
- inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME,
- NetconfMessageTransformUtil.COMMIT_RPC_CONTENT);
- inOrder.verify(rpc).invokeRpc(eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME),
- isNull());
- inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME,
- NetconfBaseOps.getUnLockContent(NETCONF_CANDIDATE_QNAME));
- return;
- }
-
- fail("Submit should fail");
+ final var future = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)), false)
+ .commit();
+ assertThrows(ExecutionException.class, () -> Futures.getDone(future));
+
+ // verify discard changes was sent
+ final InOrder inOrder = inOrder(rpc);
+ inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME,
+ NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_NODEID));
+ inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME,
+ NetconfMessageTransformUtil.COMMIT_RPC_CONTENT);
+ inOrder.verify(rpc).invokeRpc(eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME),
+ isNull());
+ inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME,
+ NetconfBaseOps.getUnLockContent(NETCONF_CANDIDATE_NODEID));
}
@Test
- public void testFailedCommit() throws Exception {
+ public void testFailedCommit() {
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult((ContainerNode) null)))
.doReturn(Futures.immediateFuture(new DefaultDOMRpcResult(RpcResultBuilder.newError(ErrorType.APPLICATION,
new ErrorTag("a"), "m")))).when(rpc).invokeRpc(any(QName.class), any(ContainerNode.class));
- final WriteCandidateTx tx = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)),
- false);
+ final var future = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)), false)
+ .commit();
- try {
- tx.commit().get();
- fail("Submit should fail");
- } catch (final ExecutionException e) {
- // Intended
- }
+ assertThrows(ExecutionException.class, () -> Futures.getDone(future));
}
@Test
// verify discard changes was sent
final InOrder inOrder = inOrder(rpc);
inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME,
- NetconfBaseOps.getLockContent(NETCONF_RUNNING_QNAME));
+ NetconfBaseOps.getLockContent(NETCONF_RUNNING_NODEID));
inOrder.verify(rpc).invokeRpc(eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME),
any(ContainerNode.class));
inOrder.verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME,
- NetconfBaseOps.getUnLockContent(NETCONF_RUNNING_QNAME));
+ NetconfBaseOps.getUnLockContent(NETCONF_RUNNING_NODEID));
}
@Test
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_TARGET_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_TARGET_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class WriteCandidateRunningTxTest extends AbstractTestModelTest {
final WriteCandidateRunningTx tx = new WriteCandidateRunningTx(id, netconfOps, true);
//check, if lock is called
final ContainerNode candidateLock =
- getLockContent(NETCONF_LOCK_QNAME, NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME);
+ getLockContent(NETCONF_LOCK_QNAME, NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID);
final ContainerNode runningLock =
- getLockContent(NETCONF_LOCK_QNAME, NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME);
+ getLockContent(NETCONF_LOCK_QNAME, NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID);
verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME, runningLock);
verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME, candidateLock);
tx.put(LogicalDatastoreType.CONFIGURATION, TxTestUtils.getContainerId(), TxTestUtils.getContainerNode());
verify(rpc).invokeRpc(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME,
NetconfMessageTransformUtil.COMMIT_RPC_CONTENT);
final ContainerNode candidateUnlock = getLockContent(NETCONF_UNLOCK_QNAME,
- NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME);
+ NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID);
final ContainerNode runningUnlock = getLockContent(NETCONF_UNLOCK_QNAME,
- NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME);
+ NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID);
verify(rpc).invokeRpc(NETCONF_UNLOCK_QNAME, candidateUnlock);
verify(rpc).invokeRpc(NETCONF_UNLOCK_QNAME, runningUnlock);
}
- private static ContainerNode getLockContent(final QName op, final QName datastore) {
- final LeafNode<Object> datastoreLeaf = Builders.leafBuilder().withNodeIdentifier(toId(datastore))
- .withValue(Empty.value()).build();
- final ChoiceNode choice = Builders.choiceBuilder()
- .withNodeIdentifier(toId(ConfigTarget.QNAME))
- .withChild(datastoreLeaf)
- .build();
- final ContainerNode target = Builders.containerBuilder()
- .withNodeIdentifier(toId(NETCONF_TARGET_QNAME))
- .withChild(choice).build();
+ private static ContainerNode getLockContent(final QName op, final NodeIdentifier datastore) {
return Builders.containerBuilder()
- .withNodeIdentifier(toId(op))
- .withChild(target)
- .build();
+ .withNodeIdentifier(toId(op))
+ .withChild(Builders.containerBuilder()
+ .withNodeIdentifier(NETCONF_TARGET_NODEID)
+ .withChild(Builders.choiceBuilder()
+ .withNodeIdentifier(toId(ConfigTarget.QNAME))
+ .withChild(ImmutableNodes.leafNode(datastore, Empty.value()))
+ .build())
+ .build())
+ .build();
}
}
\ No newline at end of file
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_CONTENT;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.GET_SCHEMA_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.createEditConfigStructure;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
public void testLockRequestBaseSchemaNotPresent() throws Exception {
final NetconfMessageTransformer transformer = getTransformer(PARTIAL_SCHEMA);
final NetconfMessage netconfMessage = transformer.toRpcRequest(NETCONF_LOCK_QNAME,
- NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME));
+ NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_NODEID));
assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<lock"));
assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<rpc"));
NodeIdentifierWithPredicates.of(Schema.QNAME),
toId(QName.create(Schemas.QNAME, "version"))), SCHEMA);
- final ContainerNode source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME);
+ final ContainerNode source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_NODEID);
final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_CONFIG_QNAME,
NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter));
final AnyxmlNode<?> filter = toFilterStructure(
YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME)), SCHEMA);
- final ContainerNode source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME);
+ final ContainerNode source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_NODEID);
final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_CONFIG_QNAME,
NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter));
createEditConfigStructure(BASE_SCHEMAS.getBaseSchemaWithNotifications().getEffectiveModelContext(), id,
Optional.empty(), Optional.ofNullable(schemaNode));
- final DataContainerChild target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_QNAME);
+ final DataContainerChild target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_NODEID);
final ContainerNode wrap =
NetconfMessageTransformUtil.wrap(NETCONF_EDIT_CONFIG_QNAME, editConfigStructure, target);
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
final MessageTransformer transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT),
true, BASE_SCHEMAS.getBaseSchema());
final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
- final RemoteDeviceId id =
- new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
- callback = new NetconfRpcFutureCallback("prefix", id);
+ callback = new NetconfRpcFutureCallback("prefix",
+ new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)));
baseOps = new NetconfBaseOps(rpc, new EmptyMountPointContext(SCHEMA_CONTEXT));
}
@Test
public void testLock() throws Exception {
- baseOps.lock(callback, NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME);
+ baseOps.lock(callback, NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID);
verifyMessageSent("lock", NetconfMessageTransformUtil.NETCONF_LOCK_QNAME);
}
@Test
public void testUnlock() throws Exception {
- baseOps.unlock(callback, NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME);
+ baseOps.unlock(callback, NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID);
verifyMessageSent("unlock", NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME);
}
@Test
public void testCopyConfig() throws Exception {
- baseOps.copyConfig(callback, NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME,
- NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME);
+ baseOps.copyConfig(callback, NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID,
+ NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID);
verifyMessageSent("copy-config", NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME);
}
@Test
public void testGetConfigRunningData() throws Exception {
- final Optional<NormalizedNode> dataOpt =
- baseOps.getConfigRunningData(callback, Optional.of(YangInstanceIdentifier.empty())).get();
+ final var dataOpt = baseOps.getConfigRunningData(callback, Optional.of(YangInstanceIdentifier.empty())).get();
assertTrue(dataOpt.isPresent());
- assertEquals(NetconfUtil.NETCONF_DATA_QNAME, dataOpt.get().getIdentifier().getNodeType());
+ assertEquals(NetconfUtil.NETCONF_DATA_QNAME, dataOpt.orElseThrow().getIdentifier().getNodeType());
}
@Test
public void testGetData() throws Exception {
- final Optional<NormalizedNode> dataOpt =
- baseOps.getData(callback, Optional.of(YangInstanceIdentifier.empty())).get();
+ final var dataOpt = baseOps.getData(callback, Optional.of(YangInstanceIdentifier.empty())).get();
assertTrue(dataOpt.isPresent());
- assertEquals(NetconfUtil.NETCONF_DATA_QNAME, dataOpt.get().getIdentifier().getNodeType());
+ assertEquals(NetconfUtil.NETCONF_DATA_QNAME, dataOpt.orElseThrow().getIdentifier().getNodeType());
}
@Test
@Test
public void testGetConfigCandidateWithFilter() throws Exception {
- final YangInstanceIdentifier id = YangInstanceIdentifier.builder()
- .node(CONTAINER_C_QNAME)
- .build();
- baseOps.getConfigCandidate(callback, Optional.of(id));
+ baseOps.getConfigCandidate(callback, Optional.of(YangInstanceIdentifier.of(CONTAINER_C_QNAME)));
verifyMessageSent("getConfig_candidate-filter", NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME);
}
@Test
public void testEditConfigCandidate() throws Exception {
- final LeafNode<Object> leaf = Builders.leafBuilder()
- .withNodeIdentifier(LEAF_A_NID)
- .withValue("leaf-value")
- .build();
- final YangInstanceIdentifier leafId = YangInstanceIdentifier.builder()
- .node(CONTAINER_C_QNAME)
- .node(LEAF_A_NID)
- .build();
- final DataContainerChild structure = baseOps.createEditConfigStructure(Optional.of(leaf),
- Optional.of(ModifyAction.REPLACE), leafId);
- baseOps.editConfigCandidate(callback, structure, true);
+ baseOps.editConfigCandidate(callback, baseOps.createEditConfigStructure(
+ Optional.of(ImmutableNodes.leafNode(LEAF_A_NID, "leaf-value")),
+ Optional.of(ModifyAction.REPLACE), YangInstanceIdentifier.builder()
+ .node(CONTAINER_C_QNAME)
+ .node(LEAF_A_NID)
+ .build()), true);
verifyMessageSent("edit-config-test-module", NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME);
}
@Test
public void testDeleteContainerNodeCandidate() throws Exception {
- final YangInstanceIdentifier containerId = YangInstanceIdentifier.builder()
- .node(CONTAINER_C_QNAME)
- .build();
- final DataContainerChild structure = baseOps.createEditConfigStructure(Optional.empty(),
- Optional.of(ModifyAction.DELETE), containerId);
- baseOps.editConfigCandidate(callback, structure, true);
+ baseOps.editConfigCandidate(callback, baseOps.createEditConfigStructure(Optional.empty(),
+ Optional.of(ModifyAction.DELETE), YangInstanceIdentifier.of(CONTAINER_C_QNAME)), true);
verifyMessageSent("edit-config-delete-container-node-candidate",
NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME);
}
@Test
public void testDeleteLeafNodeCandidate() throws Exception {
- final YangInstanceIdentifier leafId = YangInstanceIdentifier.builder()
- .node(CONTAINER_C_QNAME)
- .node(LEAF_A_NID)
- .build();
- final DataContainerChild structure = baseOps.createEditConfigStructure(Optional.empty(),
- Optional.of(ModifyAction.DELETE), leafId);
- baseOps.editConfigCandidate(callback, structure, true);
+ baseOps.editConfigCandidate(callback, baseOps.createEditConfigStructure(Optional.empty(),
+ Optional.of(ModifyAction.DELETE),
+ YangInstanceIdentifier.builder().node(CONTAINER_C_QNAME).node(LEAF_A_NID).build()), true);
verifyMessageSent("edit-config-delete-leaf-node-candidate",
NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME);
}
@Test
public void testEditConfigRunning() throws Exception {
- final LeafNode<Object> leaf = Builders.leafBuilder()
- .withNodeIdentifier(LEAF_A_NID)
- .withValue("leaf-value")
- .build();
- final YangInstanceIdentifier leafId = YangInstanceIdentifier.builder()
- .node(CONTAINER_C_NID)
- .node(LEAF_A_NID)
- .build();
- final DataContainerChild structure = baseOps.createEditConfigStructure(Optional.of(leaf),
- Optional.of(ModifyAction.REPLACE), leafId);
- baseOps.editConfigRunning(callback, structure, ModifyAction.MERGE, true);
+ baseOps.editConfigRunning(callback, baseOps.createEditConfigStructure(
+ Optional.of(ImmutableNodes.leafNode(LEAF_A_NID, "leaf-value")),
+ Optional.of(ModifyAction.REPLACE),
+ YangInstanceIdentifier.builder().node(CONTAINER_C_NID).node(LEAF_A_NID).build()), ModifyAction.MERGE, true);
verifyMessageSent("edit-config-test-module-running", NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME);
}
@Test
public void testGetDataWithoutFields() {
assertThrows(ExecutionException.class, () -> baseOps.getData(callback,
- Optional.of(YangInstanceIdentifier.empty()), Collections.emptyList()).get());
+ Optional.of(YangInstanceIdentifier.empty()), List.of()).get());
}
@Test
public void getConfigRunningDataWithoutFields() {
assertThrows(ExecutionException.class, () -> baseOps.getConfigRunningData(callback,
- Optional.of(YangInstanceIdentifier.empty()), Collections.emptyList()).get());
+ Optional.of(YangInstanceIdentifier.empty()), List.of()).get());
}
@Test