package org.opendaylight.netconf.mdsal.connector.ops;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.stream.Collectors;
import org.opendaylight.controller.config.util.xml.DocumentedException;
import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity;
import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorTag;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
}
}
- private static void executeChange(final DOMDataReadWriteTransaction rwtx, final DataTreeChange change)
+ private void executeChange(final DOMDataReadWriteTransaction rwtx, final DataTreeChange change)
throws DocumentedException {
final YangInstanceIdentifier path = YangInstanceIdentifier.create(change.getPath());
final NormalizedNode<?, ?> changeData = change.getChangeRoot();
}
}
- private static void mergeParentMap(final DOMDataReadWriteTransaction rwtx, final YangInstanceIdentifier path,
+ private void mergeParentMap(final DOMDataReadWriteTransaction rwtx, final YangInstanceIdentifier path,
final NormalizedNode<?, ?> change) {
if (change instanceof MapEntryNode) {
final YangInstanceIdentifier mapNodeYid = path.getParent();
- //merge empty map
+
+ final SchemaNode schemaNode = SchemaContextUtil.findNodeInSchemaContext(
+ schemaContext.getCurrentContext(),
+ mapNodeYid.getPathArguments().stream()
+ // filter out identifiers not present in the schema tree
+ .filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates))
+ .filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier))
+ .map(YangInstanceIdentifier.PathArgument::getNodeType).collect(Collectors.toList()));
+
+ // we should have the schema node that points to the parent list now, enforce it
+ Preconditions.checkState(schemaNode instanceof ListSchemaNode, "Schema node is not pointing to a list.");
+
+ //merge empty ordered or unordered map
+ if (((ListSchemaNode) schemaNode).isUserOrdered()) {
+ final MapNode mixinNode = Builders.orderedMapBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(mapNodeYid.getLastPathArgument().getNodeType()))
+ .build();
+ rwtx.merge(LogicalDatastoreType.CONFIGURATION, mapNodeYid, mixinNode);
+ return;
+ }
+
final MapNode mixinNode = Builders.mapBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(mapNodeYid.getLastPathArgument().getNodeType()))
.build();
}
+ @Test
+ public void testOrderedListEdits() throws Exception {
+
+ verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_create.xml"), RPC_REPLY_OK);
+ verifyResponse(commit(), RPC_REPLY_OK);
+
+ verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_replace.xml"), RPC_REPLY_OK);
+ verifyResponse(commit(), RPC_REPLY_OK);
+
+ deleteDatastore();
+
+ }
+
+ @Test
+ public void testAugmentedOrderedListEdits() throws Exception {
+
+ verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_create.xml"),
+ RPC_REPLY_OK);
+ verifyResponse(commit(), RPC_REPLY_OK);
+
+ verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_replace.xml"),
+ RPC_REPLY_OK);
+ verifyResponse(commit(), RPC_REPLY_OK);
+
+ deleteDatastore();
+
+ }
+
@Test
public void testLock() throws Exception {
--- /dev/null
+<!--
+ ~ Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ ~
+ ~ This program and the accompanying materials are made available under the
+ ~ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ ~ and is available at http://www.eclipse.org/legal/epl-v10.html
+ -->
+
+<rpc message-id="a" a="64" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+ <edit-config>
+ <target>
+ <candidate/>
+ </target>
+ <test-option>
+ set
+ </test-option>
+ <default-operation>none</default-operation>
+ <config>
+ <mapping-nodes xmlns="urn:opendaylight:mdsal:mapping:test" xmlns:a="urn:ietf:params:xml:ns:netconf:base:1.0" a:operation="create">
+ <mapping-node>
+ <id>id</id>
+ <augmented-ordered-items>
+ <augmented-ordered-item>
+ <id>node1</id>
+ <content>node1 original content</content>
+ </augmented-ordered-item>
+ </augmented-ordered-items>
+ </mapping-node>
+ </mapping-nodes>
+ </config>
+ </edit-config>
+</rpc>
\ No newline at end of file
--- /dev/null
+<!--
+ ~ Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ ~
+ ~ This program and the accompanying materials are made available under the
+ ~ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ ~ and is available at http://www.eclipse.org/legal/epl-v10.html
+ -->
+
+<rpc message-id="a" a="64" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+ <edit-config>
+ <target>
+ <candidate/>
+ </target>
+ <test-option>
+ set
+ </test-option>
+ <default-operation>none</default-operation>
+ <config>
+ <mapping-nodes xmlns="urn:opendaylight:mdsal:mapping:test" xmlns:a="urn:ietf:params:xml:ns:netconf:base:1.0" a:operation="none">
+ <mapping-node>
+ <id>id</id>
+ <augmented-ordered-items>
+ <augmented-ordered-item xmlns:a="urn:ietf:params:xml:ns:netconf:base:1.0" a:operation="replace">
+ <id>node1</id>
+ <content>node1 content</content>
+ </augmented-ordered-item>
+ </augmented-ordered-items>
+ </mapping-node>
+ </mapping-nodes>
+ </config>
+ </edit-config>
+</rpc>
\ No newline at end of file
--- /dev/null
+<!--
+ ~ Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ ~
+ ~ This program and the accompanying materials are made available under the
+ ~ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ ~ and is available at http://www.eclipse.org/legal/epl-v10.html
+ -->
+
+<rpc message-id="a" a="64" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+ <edit-config>
+ <target>
+ <candidate/>
+ </target>
+ <test-option>
+ set
+ </test-option>
+ <default-operation>none</default-operation>
+ <config>
+ <mapping-nodes xmlns="urn:opendaylight:mdsal:mapping:test" xmlns:a="urn:ietf:params:xml:ns:netconf:base:1.0" a:operation="create">
+ <mapping-node>
+ <id>id</id>
+ <ordered-items>
+ <ordered-item>
+ <id>node1</id>
+ <content>node1 original content</content>
+ </ordered-item>
+ </ordered-items>
+ </mapping-node>
+ </mapping-nodes>
+ </config>
+ </edit-config>
+</rpc>
\ No newline at end of file
--- /dev/null
+<!--
+ ~ Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ ~
+ ~ This program and the accompanying materials are made available under the
+ ~ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ ~ and is available at http://www.eclipse.org/legal/epl-v10.html
+ -->
+
+<rpc message-id="a" a="64" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+ <edit-config>
+ <target>
+ <candidate/>
+ </target>
+ <test-option>
+ set
+ </test-option>
+ <default-operation>none</default-operation>
+ <config>
+ <mapping-nodes xmlns="urn:opendaylight:mdsal:mapping:test" xmlns:a="urn:ietf:params:xml:ns:netconf:base:1.0" a:operation="none">
+ <mapping-node>
+ <id>id</id>
+ <ordered-items>
+ <ordered-item xmlns:a="urn:ietf:params:xml:ns:netconf:base:1.0" a:operation="replace">
+ <id>node1</id>
+ <content>node1 content</content>
+ </ordered-item>
+ </ordered-items>
+ </mapping-node>
+ </mapping-nodes>
+ </config>
+ </edit-config>
+</rpc>
\ No newline at end of file
}
}
- list mapping-node{
+ list mapping-node {
key "id";
leaf id {
type string;
leaf content {
type string;
}
+
+ choice ordered-choice {
+ case a {
+ container ordered-items {
+ list ordered-item {
+ key "id";
+ ordered-by user;
+ leaf id {
+ type string;
+ }
+
+ leaf content {
+ type string;
+ }
+ }
+ }
+ }
+ case b {
+ container augmented-ordered-items {
+
+ }
+ }
+ }
+ }
+ }
+
+ augment "/map:mapping-nodes/map:mapping-node/map:ordered-choice/map:b/map:augmented-ordered-items" {
+ list augmented-ordered-item {
+ key "id";
+ ordered-by user;
+ leaf id {
+ type string;
+ }
+
+ leaf content {
+ type string;
+ }
}
}