InstanceIdentifierContext does not take generics
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / restconf / impl / BrokerFacade.java
index b30b00d107cf57d06b16c3f5726147ca6fb99cd4..4ce925f7f5a9160edda3529900a6384b7eb22443 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.netconf.sal.restconf.impl;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
 
-import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.FluentFuture;
@@ -23,7 +24,6 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map.Entry;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
@@ -31,7 +31,7 @@ import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import javax.ws.rs.core.Response.Status;
-import org.apache.aries.blueprint.annotation.service.Reference;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.ReadFailedException;
@@ -47,20 +47,21 @@ import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
 import org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapter;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.common.util.DataChangeScope;
+import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -74,43 +75,46 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.SchemaAwareBuilders;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Singleton
-@SuppressWarnings("checkstyle:FinalClass")
 public class BrokerFacade implements Closeable {
     private static final Logger LOG = LoggerFactory.getLogger(BrokerFacade.class);
 
-    private volatile DOMRpcService rpcService;
-
-    private final DOMDataBroker domDataBroker;
+    private final ThreadLocal<Boolean> isMounted = new ThreadLocal<>();
     private final DOMNotificationService domNotification;
     private final ControllerContext controllerContext;
+    private final DOMDataBroker domDataBroker;
+
+    private volatile DOMRpcService rpcService;
 
     @Inject
-    public BrokerFacade(final @Reference DOMRpcService rpcService, final DOMDataBroker domDataBroker,
-            final @Reference DOMNotificationService domNotification, final ControllerContext controllerContext) {
-        this.rpcService = Objects.requireNonNull(rpcService);
-        this.domDataBroker = Objects.requireNonNull(domDataBroker);
-        this.domNotification = Objects.requireNonNull(domNotification);
-        this.controllerContext = Objects.requireNonNull(controllerContext);
+    public BrokerFacade(final DOMRpcService rpcService, final DOMDataBroker domDataBroker,
+            final DOMNotificationService domNotification, final ControllerContext controllerContext) {
+        this.rpcService = requireNonNull(rpcService);
+        this.domDataBroker = requireNonNull(domDataBroker);
+        this.domNotification = requireNonNull(domNotification);
+        this.controllerContext = requireNonNull(controllerContext);
     }
 
     /**
@@ -138,7 +142,7 @@ public class BrokerFacade implements Closeable {
      *            path of data
      * @return read date
      */
-    public NormalizedNode<?, ?> readConfigurationData(final YangInstanceIdentifier path) {
+    public NormalizedNode readConfigurationData(final YangInstanceIdentifier path) {
         return readConfigurationData(path, null);
     }
 
@@ -151,8 +155,8 @@ public class BrokerFacade implements Closeable {
      *            value of with-defaults parameter
      * @return read date
      */
-    public NormalizedNode<?, ?> readConfigurationData(final YangInstanceIdentifier path, final String withDefa) {
-        try (DOMDataTreeReadTransaction tx = this.domDataBroker.newReadOnlyTransaction()) {
+    public NormalizedNode readConfigurationData(final YangInstanceIdentifier path, final String withDefa) {
+        try (DOMDataTreeReadTransaction tx = domDataBroker.newReadOnlyTransaction()) {
             return readDataViaTransaction(tx, CONFIGURATION, path, withDefa);
         }
     }
@@ -166,8 +170,7 @@ public class BrokerFacade implements Closeable {
      *            path of data
      * @return read data
      */
-    public NormalizedNode<?, ?> readConfigurationData(final DOMMountPoint mountPoint,
-            final YangInstanceIdentifier path) {
+    public NormalizedNode readConfigurationData(final DOMMountPoint mountPoint, final YangInstanceIdentifier path) {
         return readConfigurationData(mountPoint, path, null);
     }
 
@@ -182,7 +185,7 @@ public class BrokerFacade implements Closeable {
      *            value of with-defaults parameter
      * @return read data
      */
-    public NormalizedNode<?, ?> readConfigurationData(final DOMMountPoint mountPoint, final YangInstanceIdentifier path,
+    public NormalizedNode readConfigurationData(final DOMMountPoint mountPoint, final YangInstanceIdentifier path,
             final String withDefa) {
         final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
         if (domDataBrokerService.isPresent()) {
@@ -200,8 +203,8 @@ public class BrokerFacade implements Closeable {
      *            path of data
      * @return read data
      */
-    public NormalizedNode<?, ?> readOperationalData(final YangInstanceIdentifier path) {
-        try (DOMDataTreeReadTransaction tx = this.domDataBroker.newReadOnlyTransaction()) {
+    public NormalizedNode readOperationalData(final YangInstanceIdentifier path) {
+        try (DOMDataTreeReadTransaction tx = domDataBroker.newReadOnlyTransaction()) {
             return readDataViaTransaction(tx, OPERATIONAL, path);
         }
     }
@@ -215,7 +218,7 @@ public class BrokerFacade implements Closeable {
      *            path of data
      * @return read data
      */
-    public NormalizedNode<?, ?> readOperationalData(final DOMMountPoint mountPoint, final YangInstanceIdentifier path) {
+    public NormalizedNode readOperationalData(final DOMMountPoint mountPoint, final YangInstanceIdentifier path) {
         final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
         if (domDataBrokerService.isPresent()) {
             try (DOMDataTreeReadTransaction tx = domDataBrokerService.get().newReadOnlyTransaction()) {
@@ -244,18 +247,19 @@ public class BrokerFacade implements Closeable {
      *            insert
      * @return wrapper of status and future of PUT
      */
-    public PutResult commitConfigurationDataPut(
-            final SchemaContext globalSchema, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
-            final String insert, final String point) {
-        Preconditions.checkNotNull(globalSchema);
-        Preconditions.checkNotNull(path);
-        Preconditions.checkNotNull(payload);
-
-        final DOMDataTreeReadWriteTransaction newReadWriteTransaction = this.domDataBroker.newReadWriteTransaction();
+    public PutResult commitConfigurationDataPut(final EffectiveModelContext globalSchema,
+            final YangInstanceIdentifier path, final NormalizedNode payload, final String insert, final String point) {
+        requireNonNull(globalSchema);
+        requireNonNull(path);
+        requireNonNull(payload);
+
+        isMounted.set(false);
+        final DOMDataTreeReadWriteTransaction newReadWriteTransaction = domDataBroker.newReadWriteTransaction();
         final Status status = readDataViaTransaction(newReadWriteTransaction, CONFIGURATION, path) != null ? Status.OK
                 : Status.CREATED;
         final FluentFuture<? extends CommitInfo> future = putDataViaTransaction(
                 newReadWriteTransaction, CONFIGURATION, path, payload, globalSchema, insert, point);
+        isMounted.remove();
         return new PutResult(status, future);
     }
 
@@ -279,13 +283,13 @@ public class BrokerFacade implements Closeable {
      *            insert
      * @return wrapper of status and future of PUT
      */
-    public PutResult commitMountPointDataPut(
-            final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
-            final String insert, final String point) {
-        Preconditions.checkNotNull(mountPoint);
-        Preconditions.checkNotNull(path);
-        Preconditions.checkNotNull(payload);
+    public PutResult commitMountPointDataPut(final DOMMountPoint mountPoint, final YangInstanceIdentifier path,
+            final NormalizedNode payload, final String insert, final String point) {
+        requireNonNull(mountPoint);
+        requireNonNull(path);
+        requireNonNull(payload);
 
+        isMounted.set(true);
         final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
         if (domDataBrokerService.isPresent()) {
             final DOMDataTreeReadWriteTransaction newReadWriteTransaction =
@@ -293,10 +297,11 @@ public class BrokerFacade implements Closeable {
             final Status status = readDataViaTransaction(newReadWriteTransaction, CONFIGURATION, path) != null
                     ? Status.OK : Status.CREATED;
             final FluentFuture<? extends CommitInfo> future = putDataViaTransaction(
-                    newReadWriteTransaction, CONFIGURATION, path, payload, mountPoint.getSchemaContext(), insert,
-                    point);
+                    newReadWriteTransaction, CONFIGURATION, path, payload, modelContext(mountPoint), insert, point);
+            isMounted.remove();
             return new PutResult(status, future);
         }
+        isMounted.remove();
         throw dataBrokerUnavailable(path);
     }
 
@@ -305,13 +310,13 @@ public class BrokerFacade implements Closeable {
         final DOMMountPoint mountPoint = patchContext.getInstanceIdentifierContext().getMountPoint();
 
         // get new transaction and schema context on server or on mounted device
-        final SchemaContext schemaContext;
+        final EffectiveModelContext schemaContext;
         final DOMDataTreeReadWriteTransaction patchTransaction;
         if (mountPoint == null) {
             schemaContext = patchContext.getInstanceIdentifierContext().getSchemaContext();
-            patchTransaction = this.domDataBroker.newReadWriteTransaction();
+            patchTransaction = domDataBroker.newReadWriteTransaction();
         } else {
-            schemaContext = mountPoint.getSchemaContext();
+            schemaContext = modelContext(mountPoint);
 
             final Optional<DOMDataBroker> optional = mountPoint.getService(DOMDataBroker.class);
 
@@ -325,11 +330,8 @@ public class BrokerFacade implements Closeable {
                         patchContext.getPatchId(),
                         null,
                         false,
-                        ImmutableList.of(new RestconfError(
-                                ErrorType.APPLICATION,
-                                ErrorTag.OPERATION_FAILED,
-                                "DOM data broker service isn't available for mount point "
-                                        + mountPoint.getIdentifier()))
+                        ImmutableList.of(new RestconfError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED,
+                            "DOM data broker service isn't available for mount point " + mountPoint.getIdentifier()))
                 );
             }
         }
@@ -446,7 +448,7 @@ public class BrokerFacade implements Closeable {
                 // if commit failed it is global error
                 LOG.error("Http Patch {} transaction commit has failed", patchContext.getPatchId());
                 status.setStatus(new PatchStatusContext(patchContext.getPatchId(), ImmutableList.copyOf(editCollection),
-                        false, ImmutableList.of(
+                    false, ImmutableList.of(
                         new RestconfError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, throwable.getMessage()))));
                 waiter.countDown();
             }
@@ -458,26 +460,35 @@ public class BrokerFacade implements Closeable {
 
     // POST configuration
     public FluentFuture<? extends CommitInfo> commitConfigurationDataPost(
-            final SchemaContext globalSchema, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
-            final String insert, final String point) {
-        return postDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload,
-                globalSchema, insert, point);
+            final EffectiveModelContext globalSchema, final YangInstanceIdentifier path,
+            final NormalizedNode payload, final String insert, final String point) {
+        isMounted.set(false);
+        FluentFuture<? extends CommitInfo> future =
+                postDataViaTransaction(domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload,
+                                       globalSchema, insert, point);
+        isMounted.remove();
+        return future;
     }
 
     public FluentFuture<? extends CommitInfo> commitConfigurationDataPost(
-            final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+            final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode payload,
             final String insert, final String point) {
+        isMounted.set(true);
         final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
         if (domDataBrokerService.isPresent()) {
-            return postDataViaTransaction(domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path,
-                    payload, mountPoint.getSchemaContext(), insert, point);
+            FluentFuture<? extends CommitInfo> future =
+                    postDataViaTransaction(domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path,
+                                           payload, modelContext(mountPoint), insert, point);
+            isMounted.remove();
+            return future;
         }
+        isMounted.remove();
         throw dataBrokerUnavailable(path);
     }
 
     // DELETE configuration
     public FluentFuture<? extends CommitInfo> commitConfigurationDataDelete(final YangInstanceIdentifier path) {
-        return deleteDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path);
+        return deleteDataViaTransaction(domDataBroker.newReadWriteTransaction(), CONFIGURATION, path);
     }
 
     public FluentFuture<? extends CommitInfo> commitConfigurationDataDelete(
@@ -490,26 +501,27 @@ public class BrokerFacade implements Closeable {
     }
 
     // RPC
-    public ListenableFuture<DOMRpcResult> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
-        if (this.rpcService == null) {
+    public ListenableFuture<? extends DOMRpcResult> invokeRpc(final @NonNull QName type,
+            final @NonNull NormalizedNode input) {
+        if (rpcService == null) {
             throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
         }
         LOG.trace("Invoke RPC {} with input: {}", type, input);
-        return this.rpcService.invokeRpc(type, input);
+        return rpcService.invokeRpc(type, input);
     }
 
-    public void registerToListenDataChanges(final LogicalDatastoreType datastore, final DataChangeScope scope,
+    public void registerToListenDataChanges(final LogicalDatastoreType datastore, final Scope scope,
             final ListenerAdapter listener) {
         if (listener.isListening()) {
             return;
         }
 
         final YangInstanceIdentifier path = listener.getPath();
-        DOMDataTreeChangeService changeService = this.domDataBroker.getExtensions()
+        DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
                 .getInstance(DOMDataTreeChangeService.class);
         if (changeService == null) {
             throw new UnsupportedOperationException("DOMDataBroker does not support the DOMDataTreeChangeService"
-                                                        + this.domDataBroker);
+                                                        + domDataBroker);
         }
         DOMDataTreeIdentifier root = new DOMDataTreeIdentifier(datastore, path);
         ListenerRegistration<ListenerAdapter> registration =
@@ -517,19 +529,19 @@ public class BrokerFacade implements Closeable {
         listener.setRegistration(registration);
     }
 
-    private NormalizedNode<?, ?> readDataViaTransaction(final DOMDataTreeReadOperations transaction,
+    private NormalizedNode readDataViaTransaction(final DOMDataTreeReadOperations transaction,
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path) {
         return readDataViaTransaction(transaction, datastore, path, null);
     }
 
-    private NormalizedNode<?, ?> readDataViaTransaction(final DOMDataTreeReadOperations transaction,
+    private NormalizedNode readDataViaTransaction(final DOMDataTreeReadOperations transaction,
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final String withDefa) {
         LOG.trace("Read {} via Restconf: {}", datastore.name(), path);
 
         try {
-            final Optional<NormalizedNode<?, ?>> optional = transaction.read(datastore, path).get();
-            return !optional.isPresent() ? null : withDefa == null ? optional.get() :
-                prepareDataByParamWithDef(optional.get(), path, withDefa);
+            final Optional<NormalizedNode> optional = transaction.read(datastore, path).get();
+            return optional.map(normalizedNode -> withDefa == null ? normalizedNode :
+                prepareDataByParamWithDef(normalizedNode, path, withDefa)).orElse(null);
         } catch (InterruptedException e) {
             LOG.warn("Error reading {} from datastore {}", path, datastore.name(), e);
             throw new RestconfDocumentedException("Error reading data.", e);
@@ -540,7 +552,7 @@ public class BrokerFacade implements Closeable {
         }
     }
 
-    private NormalizedNode<?, ?> prepareDataByParamWithDef(final NormalizedNode<?, ?> result,
+    private NormalizedNode prepareDataByParamWithDef(final NormalizedNode result,
             final YangInstanceIdentifier path, final String withDefa) {
         boolean trim;
         switch (withDefa) {
@@ -554,18 +566,18 @@ public class BrokerFacade implements Closeable {
                 throw new RestconfDocumentedException("Bad value used with with-defaults parameter : " + withDefa);
         }
 
-        final SchemaContext ctx = controllerContext.getGlobalSchema();
+        final EffectiveModelContext ctx = controllerContext.getGlobalSchema();
         final DataSchemaContextTree baseSchemaCtxTree = DataSchemaContextTree.from(ctx);
-        final DataSchemaNode baseSchemaNode = baseSchemaCtxTree.getChild(path).getDataSchemaNode();
+        final DataSchemaNode baseSchemaNode = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
         if (result instanceof ContainerNode) {
             final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder =
-                    Builders.containerBuilder((ContainerSchemaNode) baseSchemaNode);
+                SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) baseSchemaNode);
             buildCont(builder, (ContainerNode) result, baseSchemaCtxTree, path, trim);
             return builder.build();
         }
 
         final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder =
-                Builders.mapEntryBuilder((ListSchemaNode) baseSchemaNode);
+            SchemaAwareBuilders.mapEntryBuilder((ListSchemaNode) baseSchemaNode);
         buildMapEntryBuilder(builder, (MapEntryNode) result, baseSchemaCtxTree, path, trim,
             ((ListSchemaNode) baseSchemaNode).getKeyDefinition());
         return builder.build();
@@ -575,37 +587,37 @@ public class BrokerFacade implements Closeable {
             final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder,
             final MapEntryNode result, final DataSchemaContextTree baseSchemaCtxTree,
             final YangInstanceIdentifier actualPath, final boolean trim, final List<QName> keys) {
-        for (final DataContainerChild<? extends PathArgument, ?> child : result.getValue()) {
+        for (final DataContainerChild child : result.body()) {
             final YangInstanceIdentifier path = actualPath.node(child.getIdentifier());
-            final DataSchemaNode childSchema = baseSchemaCtxTree.getChild(path).getDataSchemaNode();
+            final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
             if (child instanceof ContainerNode) {
                 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> childBuilder =
-                        Builders.containerBuilder((ContainerSchemaNode) childSchema);
+                        SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) childSchema);
                 buildCont(childBuilder, (ContainerNode) child, baseSchemaCtxTree, path, trim);
                 builder.withChild(childBuilder.build());
             } else if (child instanceof MapNode) {
-                final CollectionNodeBuilder<MapEntryNode, MapNode> childBuilder =
-                        Builders.mapBuilder((ListSchemaNode) childSchema);
+                final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childBuilder =
+                        SchemaAwareBuilders.mapBuilder((ListSchemaNode) childSchema);
                 buildList(childBuilder, (MapNode) child, baseSchemaCtxTree, path, trim,
                         ((ListSchemaNode) childSchema).getKeyDefinition());
                 builder.withChild(childBuilder.build());
             } else if (child instanceof LeafNode) {
                 final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
-                final Object nodeVal = child.getValue();
+                final Object nodeVal = child.body();
                 final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder =
-                        Builders.leafBuilder((LeafSchemaNode) childSchema);
-                if (keys.contains(child.getNodeType())) {
-                    leafBuilder.withValue(child.getValue());
+                        SchemaAwareBuilders.leafBuilder((LeafSchemaNode) childSchema);
+                if (keys.contains(child.getIdentifier().getNodeType())) {
+                    leafBuilder.withValue(child.body());
                     builder.withChild(leafBuilder.build());
                 } else {
                     if (trim) {
                         if (defaultVal == null || !defaultVal.equals(nodeVal)) {
-                            leafBuilder.withValue(child.getValue());
+                            leafBuilder.withValue(child.body());
                             builder.withChild(leafBuilder.build());
                         }
                     } else {
                         if (defaultVal != null && defaultVal.equals(nodeVal)) {
-                            leafBuilder.withValue(child.getValue());
+                            leafBuilder.withValue(child.body());
                             builder.withChild(leafBuilder.build());
                         }
                     }
@@ -614,14 +626,15 @@ public class BrokerFacade implements Closeable {
         }
     }
 
-    private void buildList(final CollectionNodeBuilder<MapEntryNode, MapNode> builder, final MapNode result,
+    private void buildList(final CollectionNodeBuilder<MapEntryNode, SystemMapNode> builder, final MapNode result,
             final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier path, final boolean trim,
             final List<QName> keys) {
-        for (final MapEntryNode mapEntryNode : result.getValue()) {
+        for (final MapEntryNode mapEntryNode : result.body()) {
             final YangInstanceIdentifier actualNode = path.node(mapEntryNode.getIdentifier());
-            final DataSchemaNode childSchema = baseSchemaCtxTree.getChild(actualNode).getDataSchemaNode();
+            final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(actualNode).orElseThrow()
+                    .getDataSchemaNode();
             final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder =
-                    Builders.mapEntryBuilder((ListSchemaNode) childSchema);
+                    SchemaAwareBuilders.mapEntryBuilder((ListSchemaNode) childSchema);
             buildMapEntryBuilder(mapEntryBuilder, mapEntryNode, baseSchemaCtxTree, actualNode, trim, keys);
             builder.withChild(mapEntryBuilder.build());
         }
@@ -630,33 +643,33 @@ public class BrokerFacade implements Closeable {
     private void buildCont(final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder,
             final ContainerNode result, final DataSchemaContextTree baseSchemaCtxTree,
             final YangInstanceIdentifier actualPath, final boolean trim) {
-        for (final DataContainerChild<? extends PathArgument, ?> child : result.getValue()) {
+        for (final DataContainerChild child : result.body()) {
             final YangInstanceIdentifier path = actualPath.node(child.getIdentifier());
-            final DataSchemaNode childSchema = baseSchemaCtxTree.getChild(path).getDataSchemaNode();
+            final DataSchemaNode childSchema = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
             if (child instanceof ContainerNode) {
                 final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builderChild =
-                        Builders.containerBuilder((ContainerSchemaNode) childSchema);
+                        SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) childSchema);
                 buildCont(builderChild, result, baseSchemaCtxTree, actualPath, trim);
                 builder.withChild(builderChild.build());
             } else if (child instanceof MapNode) {
-                final CollectionNodeBuilder<MapEntryNode, MapNode> childBuilder =
-                        Builders.mapBuilder((ListSchemaNode) childSchema);
+                final CollectionNodeBuilder<MapEntryNode, SystemMapNode> childBuilder =
+                        SchemaAwareBuilders.mapBuilder((ListSchemaNode) childSchema);
                 buildList(childBuilder, (MapNode) child, baseSchemaCtxTree, path, trim,
                         ((ListSchemaNode) childSchema).getKeyDefinition());
                 builder.withChild(childBuilder.build());
             } else if (child instanceof LeafNode) {
                 final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
-                final Object nodeVal = child.getValue();
+                final Object nodeVal = child.body();
                 final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder =
-                        Builders.leafBuilder((LeafSchemaNode) childSchema);
+                        SchemaAwareBuilders.leafBuilder((LeafSchemaNode) childSchema);
                 if (trim) {
                     if (defaultVal == null || !defaultVal.equals(nodeVal)) {
-                        leafBuilder.withValue(child.getValue());
+                        leafBuilder.withValue(child.body());
                         builder.withChild(leafBuilder.build());
                     }
                 } else {
                     if (defaultVal != null && defaultVal.equals(nodeVal)) {
-                        leafBuilder.withValue(child.getValue());
+                        leafBuilder.withValue(child.body());
                         builder.withChild(leafBuilder.build());
                     }
                 }
@@ -669,8 +682,8 @@ public class BrokerFacade implements Closeable {
      */
     private FluentFuture<? extends CommitInfo> postDataViaTransaction(
             final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
-            final String insert, final String point) {
+            final YangInstanceIdentifier path, final NormalizedNode payload,
+            final EffectiveModelContext schemaContext, final String insert, final String point) {
         LOG.trace("POST {} via Restconf: {} with payload {}", datastore.name(), path, payload);
         postData(rwTransaction, datastore, path, payload, schemaContext, insert, point);
         return rwTransaction.commit();
@@ -681,14 +694,15 @@ public class BrokerFacade implements Closeable {
      */
     private void postDataWithinTransaction(
             final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
+            final YangInstanceIdentifier path, final NormalizedNode payload,
+            final EffectiveModelContext schemaContext) {
         LOG.trace("POST {} within Restconf Patch: {} with payload {}", datastore.name(), path, payload);
         postData(rwTransaction, datastore, path, payload, schemaContext, null, null);
     }
 
     private void postData(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore,
-                          final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
-            final SchemaContext schemaContext, final String insert, final String point) {
+                          final YangInstanceIdentifier path, final NormalizedNode payload,
+                          final EffectiveModelContext schemaContext, final String insert, final String point) {
         if (insert == null) {
             makeNormalPost(rwTransaction, datastore, path, payload, schemaContext);
             return;
@@ -699,9 +713,9 @@ public class BrokerFacade implements Closeable {
         switch (insert) {
             case "first":
                 if (schemaNode instanceof ListSchemaNode) {
-                    final OrderedMapNode readList =
-                            (OrderedMapNode) this.readConfigurationData(path.getParent().getParent());
-                    if (readList == null || readList.getValue().isEmpty()) {
+                    final UserMapNode readList =
+                            (UserMapNode) this.readConfigurationData(path.getParent().getParent());
+                    if (readList == null || readList.isEmpty()) {
                         simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                     } else {
                         rwTransaction.delete(datastore, path.getParent().getParent());
@@ -710,9 +724,9 @@ public class BrokerFacade implements Closeable {
                             schemaContext);
                     }
                 } else {
-                    final OrderedLeafSetNode<?> readLeafList =
-                            (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
-                    if (readLeafList == null || readLeafList.getValue().isEmpty()) {
+                    final UserLeafSetNode<?> readLeafList =
+                            (UserLeafSetNode<?>) readConfigurationData(path.getParent());
+                    if (readLeafList == null || readLeafList.isEmpty()) {
                         simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                     } else {
                         rwTransaction.delete(datastore, path.getParent());
@@ -727,9 +741,9 @@ public class BrokerFacade implements Closeable {
                 break;
             case "before":
                 if (schemaNode instanceof ListSchemaNode) {
-                    final OrderedMapNode readList =
-                            (OrderedMapNode) this.readConfigurationData(path.getParent().getParent());
-                    if (readList == null || readList.getValue().isEmpty()) {
+                    final UserMapNode readList =
+                            (UserMapNode) this.readConfigurationData(path.getParent().getParent());
+                    if (readList == null || readList.isEmpty()) {
                         simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                     } else {
                         insertWithPointListPost(rwTransaction, datastore, path, payload, schemaContext, point,
@@ -737,9 +751,9 @@ public class BrokerFacade implements Closeable {
                             true);
                     }
                 } else {
-                    final OrderedLeafSetNode<?> readLeafList =
-                            (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
-                    if (readLeafList == null || readLeafList.getValue().isEmpty()) {
+                    final UserLeafSetNode<?> readLeafList =
+                            (UserLeafSetNode<?>) readConfigurationData(path.getParent());
+                    if (readLeafList == null || readLeafList.isEmpty()) {
                         simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                     } else {
                         insertWithPointLeafListPost(rwTransaction, datastore, path, payload, schemaContext, point,
@@ -749,9 +763,9 @@ public class BrokerFacade implements Closeable {
                 break;
             case "after":
                 if (schemaNode instanceof ListSchemaNode) {
-                    final OrderedMapNode readList =
-                            (OrderedMapNode) this.readConfigurationData(path.getParent().getParent());
-                    if (readList == null || readList.getValue().isEmpty()) {
+                    final UserMapNode readList =
+                            (UserMapNode) this.readConfigurationData(path.getParent().getParent());
+                    if (readList == null || readList.isEmpty()) {
                         simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                     } else {
                         insertWithPointListPost(rwTransaction, datastore, path, payload, schemaContext, point,
@@ -759,9 +773,9 @@ public class BrokerFacade implements Closeable {
                             false);
                     }
                 } else {
-                    final OrderedLeafSetNode<?> readLeafList =
-                            (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
-                    if (readLeafList == null || readLeafList.getValue().isEmpty()) {
+                    final UserLeafSetNode<?> readLeafList =
+                            (UserLeafSetNode<?>) readConfigurationData(path.getParent());
+                    if (readLeafList == null || readLeafList.isEmpty()) {
                         simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
                     } else {
                         insertWithPointLeafListPost(rwTransaction, datastore, path, payload, schemaContext, point,
@@ -777,13 +791,13 @@ public class BrokerFacade implements Closeable {
     }
 
     private void insertWithPointLeafListPost(final DOMDataTreeReadWriteTransaction rwTransaction,
-            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
-            final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
+            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload,
+            final SchemaContext schemaContext, final String point, final UserLeafSetNode<?> readLeafList,
             final boolean before) {
         rwTransaction.delete(datastore, path.getParent().getParent());
-        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier(point);
+        final InstanceIdentifierContext instanceIdentifier = controllerContext.toInstanceIdentifier(point);
         int lastItemPosition = 0;
-        for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+        for (final LeafSetEntryNode<?> nodeChild : readLeafList.body()) {
             if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
                 break;
             }
@@ -793,10 +807,9 @@ public class BrokerFacade implements Closeable {
             lastItemPosition++;
         }
         int lastInsertedPosition = 0;
-        final NormalizedNode<?, ?> emptySubtree =
-                ImmutableNodes.fromInstanceId(schemaContext, path.getParent().getParent());
+        final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent().getParent());
         rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
-        for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+        for (final LeafSetEntryNode<?> nodeChild : readLeafList.body()) {
             if (lastInsertedPosition == lastItemPosition) {
                 checkItemDoesNotExists(rwTransaction, datastore, path);
                 simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
@@ -810,12 +823,12 @@ public class BrokerFacade implements Closeable {
 
     private void insertWithPointListPost(final DOMDataTreeReadWriteTransaction rwTransaction,
             final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
+            final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext,
             final String point, final MapNode readList, final boolean before) {
         rwTransaction.delete(datastore, path.getParent().getParent());
-        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier(point);
+        final InstanceIdentifierContext instanceIdentifier = controllerContext.toInstanceIdentifier(point);
         int lastItemPosition = 0;
-        for (final MapEntryNode mapEntryNode : readList.getValue()) {
+        for (final MapEntryNode mapEntryNode : readList.body()) {
             if (mapEntryNode.getIdentifier()
                     .equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
                 break;
@@ -826,10 +839,9 @@ public class BrokerFacade implements Closeable {
             lastItemPosition++;
         }
         int lastInsertedPosition = 0;
-        final NormalizedNode<?, ?> emptySubtree =
-                ImmutableNodes.fromInstanceId(schemaContext, path.getParent().getParent());
+        final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent().getParent());
         rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
-        for (final MapEntryNode mapEntryNode : readList.getValue()) {
+        for (final MapEntryNode mapEntryNode : readList.body()) {
             if (lastInsertedPosition == lastItemPosition) {
                 checkItemDoesNotExists(rwTransaction, datastore, path);
                 simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
@@ -841,9 +853,10 @@ public class BrokerFacade implements Closeable {
         }
     }
 
-    private static DataSchemaNode checkListAndOrderedType(final SchemaContext ctx, final YangInstanceIdentifier path) {
+    private static DataSchemaNode checkListAndOrderedType(final EffectiveModelContext ctx,
+            final YangInstanceIdentifier path) {
         final YangInstanceIdentifier parent = path.getParent();
-        final DataSchemaContextNode<?> node = DataSchemaContextTree.from(ctx).getChild(parent);
+        final DataSchemaContextNode<?> node = DataSchemaContextTree.from(ctx).findChild(parent).orElseThrow();
         final DataSchemaNode dataSchemaNode = node.getDataSchemaNode();
 
         if (dataSchemaNode instanceof ListSchemaNode) {
@@ -862,23 +875,27 @@ public class BrokerFacade implements Closeable {
         throw new RestconfDocumentedException("Insert parameter can be used only with list or leaf-list");
     }
 
-    private static void makeNormalPost(final DOMDataTreeReadWriteTransaction rwTransaction,
-            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+    private void makeNormalPost(final DOMDataTreeReadWriteTransaction rwTransaction,
+            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload,
             final SchemaContext schemaContext) {
-        final Collection<? extends NormalizedNode<?, ?>> children;
+        final Collection<? extends NormalizedNode> children;
         if (payload instanceof MapNode) {
-            children = ((MapNode) payload).getValue();
+            children = ((MapNode) payload).body();
         } else if (payload instanceof LeafSetNode) {
-            children = ((LeafSetNode<?>) payload).getValue();
+            children = ((LeafSetNode<?>) payload).body();
         } else {
             simplePostPut(rwTransaction, datastore, path, payload, schemaContext);
             return;
         }
 
-        final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
+        final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
         if (children.isEmpty()) {
-            rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
-            ensureParentsByMerge(datastore, path, rwTransaction, schemaContext);
+            if (isMounted != null && !isMounted.get()) {
+
+                rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()),
+                                    emptySubtree);
+                ensureParentsByMerge(datastore, path, rwTransaction, schemaContext);
+            }
             return;
         }
 
@@ -887,9 +904,12 @@ public class BrokerFacade implements Closeable {
 
         // ... now enqueue modifications. This relies on proper ordering of requests, i.e. these will not affect the
         // result of the existence checks...
-        rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
-        ensureParentsByMerge(datastore, path, rwTransaction, schemaContext);
-        for (final NormalizedNode<?, ?> child : children) {
+        if (isMounted != null && !isMounted.get()) {
+
+            rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+            ensureParentsByMerge(datastore, path, rwTransaction, schemaContext);
+        }
+        for (final NormalizedNode child : children) {
             // FIXME: we really want a create(YangInstanceIdentifier, NormalizedNode) method in the transaction,
             //        as that would allow us to skip the existence checks
             rwTransaction.put(datastore, path.node(child.getIdentifier()), child);
@@ -917,11 +937,13 @@ public class BrokerFacade implements Closeable {
         }
     }
 
-    private static void simplePostPut(final DOMDataTreeReadWriteTransaction rwTransaction,
-            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+    private void simplePostPut(final DOMDataTreeReadWriteTransaction rwTransaction,
+            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload,
             final SchemaContext schemaContext) {
         checkItemDoesNotExists(rwTransaction, datastore, path);
-        ensureParentsByMerge(datastore, path, rwTransaction, schemaContext);
+        if (isMounted != null && !isMounted.get()) {
+            ensureParentsByMerge(datastore, path, rwTransaction, schemaContext);
+        }
         rwTransaction.put(datastore, path, payload);
     }
 
@@ -981,8 +1003,8 @@ public class BrokerFacade implements Closeable {
      */
     private FluentFuture<? extends CommitInfo> putDataViaTransaction(
             final DOMDataTreeReadWriteTransaction readWriteTransaction, final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
-            final String insert, final String point) {
+            final YangInstanceIdentifier path, final NormalizedNode payload,
+            final EffectiveModelContext schemaContext, final String insert, final String point) {
         LOG.trace("Put {} via Restconf: {} with payload {}", datastore.name(), path, payload);
         putData(readWriteTransaction, datastore, path, payload, schemaContext, insert, point);
         return readWriteTransaction.commit();
@@ -993,15 +1015,16 @@ public class BrokerFacade implements Closeable {
      */
     private void putDataWithinTransaction(
             final DOMDataTreeReadWriteTransaction writeTransaction, final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
+            final YangInstanceIdentifier path, final NormalizedNode payload,
+            final EffectiveModelContext schemaContext) {
         LOG.trace("Put {} within Restconf Patch: {} with payload {}", datastore.name(), path, payload);
         putData(writeTransaction, datastore, path, payload, schemaContext, null, null);
     }
 
     // FIXME: This is doing correct put for container and list children, not sure if this will work for choice case
     private void putData(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
-            final String insert, final String point) {
+            final YangInstanceIdentifier path, final NormalizedNode payload,
+            final EffectiveModelContext schemaContext, final String insert, final String point) {
         if (insert == null) {
             makePut(rwTransaction, datastore, path, payload, schemaContext);
             return;
@@ -1012,9 +1035,8 @@ public class BrokerFacade implements Closeable {
         switch (insert) {
             case "first":
                 if (schemaNode instanceof ListSchemaNode) {
-                    final OrderedMapNode readList =
-                            (OrderedMapNode) this.readConfigurationData(path.getParent());
-                    if (readList == null || readList.getValue().isEmpty()) {
+                    final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent());
+                    if (readList == null || readList.isEmpty()) {
                         simplePut(datastore, path, rwTransaction, schemaContext, payload);
                     } else {
                         rwTransaction.delete(datastore, path.getParent());
@@ -1022,9 +1044,9 @@ public class BrokerFacade implements Closeable {
                         makePut(rwTransaction, datastore, path.getParent(), readList, schemaContext);
                     }
                 } else {
-                    final OrderedLeafSetNode<?> readLeafList =
-                            (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
-                    if (readLeafList == null || readLeafList.getValue().isEmpty()) {
+                    final UserLeafSetNode<?> readLeafList =
+                            (UserLeafSetNode<?>) readConfigurationData(path.getParent());
+                    if (readLeafList == null || readLeafList.isEmpty()) {
                         simplePut(datastore, path, rwTransaction, schemaContext, payload);
                     } else {
                         rwTransaction.delete(datastore, path.getParent());
@@ -1039,18 +1061,17 @@ public class BrokerFacade implements Closeable {
                 break;
             case "before":
                 if (schemaNode instanceof ListSchemaNode) {
-                    final OrderedMapNode readList =
-                            (OrderedMapNode) this.readConfigurationData(path.getParent());
-                    if (readList == null || readList.getValue().isEmpty()) {
+                    final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent());
+                    if (readList == null || readList.isEmpty()) {
                         simplePut(datastore, path, rwTransaction, schemaContext, payload);
                     } else {
                         insertWithPointListPut(rwTransaction, datastore, path, payload, schemaContext, point,
                             readList, true);
                     }
                 } else {
-                    final OrderedLeafSetNode<?> readLeafList =
-                            (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
-                    if (readLeafList == null || readLeafList.getValue().isEmpty()) {
+                    final UserLeafSetNode<?> readLeafList =
+                            (UserLeafSetNode<?>) readConfigurationData(path.getParent());
+                    if (readLeafList == null || readLeafList.isEmpty()) {
                         simplePut(datastore, path, rwTransaction, schemaContext, payload);
                     } else {
                         insertWithPointLeafListPut(rwTransaction, datastore, path, payload, schemaContext, point,
@@ -1060,18 +1081,17 @@ public class BrokerFacade implements Closeable {
                 break;
             case "after":
                 if (schemaNode instanceof ListSchemaNode) {
-                    final OrderedMapNode readList =
-                            (OrderedMapNode) this.readConfigurationData(path.getParent());
-                    if (readList == null || readList.getValue().isEmpty()) {
+                    final UserMapNode readList = (UserMapNode) this.readConfigurationData(path.getParent());
+                    if (readList == null || readList.isEmpty()) {
                         simplePut(datastore, path, rwTransaction, schemaContext, payload);
                     } else {
                         insertWithPointListPut(rwTransaction, datastore, path, payload, schemaContext, point,
                             readList, false);
                     }
                 } else {
-                    final OrderedLeafSetNode<?> readLeafList =
-                            (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
-                    if (readLeafList == null || readLeafList.getValue().isEmpty()) {
+                    final UserLeafSetNode<?> readLeafList =
+                            (UserLeafSetNode<?>) readConfigurationData(path.getParent());
+                    if (readLeafList == null || readLeafList.isEmpty()) {
                         simplePut(datastore, path, rwTransaction, schemaContext, payload);
                     } else {
                         insertWithPointLeafListPut(rwTransaction, datastore, path, payload, schemaContext, point,
@@ -1087,13 +1107,13 @@ public class BrokerFacade implements Closeable {
     }
 
     private void insertWithPointLeafListPut(final DOMDataTreeWriteTransaction tx,
-            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
-            final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
+            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload,
+            final SchemaContext schemaContext, final String point, final UserLeafSetNode<?> readLeafList,
             final boolean before) {
         tx.delete(datastore, path.getParent());
-        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier(point);
+        final InstanceIdentifierContext instanceIdentifier = controllerContext.toInstanceIdentifier(point);
         int index1 = 0;
-        for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+        for (final LeafSetEntryNode<?> nodeChild : readLeafList.body()) {
             if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
                 break;
             }
@@ -1103,10 +1123,9 @@ public class BrokerFacade implements Closeable {
             index1++;
         }
         int index2 = 0;
-        final NormalizedNode<?, ?> emptySubtree =
-                ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
+        final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
         tx.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
-        for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+        for (final LeafSetEntryNode<?> nodeChild : readLeafList.body()) {
             if (index2 == index1) {
                 simplePut(datastore, path, tx, schemaContext, payload);
             }
@@ -1117,12 +1136,12 @@ public class BrokerFacade implements Closeable {
     }
 
     private void insertWithPointListPut(final DOMDataTreeWriteTransaction tx, final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
-            final String point, final OrderedMapNode readList, final boolean before) {
+            final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext,
+            final String point, final UserMapNode readList, final boolean before) {
         tx.delete(datastore, path.getParent());
-        final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier(point);
+        final InstanceIdentifierContext instanceIdentifier = controllerContext.toInstanceIdentifier(point);
         int index1 = 0;
-        for (final MapEntryNode mapEntryNode : readList.getValue()) {
+        for (final MapEntryNode mapEntryNode : readList.body()) {
             if (mapEntryNode.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
                 break;
             }
@@ -1132,10 +1151,9 @@ public class BrokerFacade implements Closeable {
             index1++;
         }
         int index2 = 0;
-        final NormalizedNode<?, ?> emptySubtree =
-                ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
+        final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
         tx.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
-        for (final MapEntryNode mapEntryNode : readList.getValue()) {
+        for (final MapEntryNode mapEntryNode : readList.body()) {
             if (index2 == index1) {
                 simplePut(datastore, path, tx, schemaContext, payload);
             }
@@ -1145,13 +1163,15 @@ public class BrokerFacade implements Closeable {
         }
     }
 
-    private static void makePut(final DOMDataTreeWriteTransaction tx, final LogicalDatastoreType datastore,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
+    private void makePut(final DOMDataTreeWriteTransaction tx, final LogicalDatastoreType datastore,
+            final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext) {
         if (payload instanceof MapNode) {
-            final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
-            tx.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
-            ensureParentsByMerge(datastore, path, tx, schemaContext);
-            for (final MapEntryNode child : ((MapNode) payload).getValue()) {
+            final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
+            if (isMounted != null && !isMounted.get()) {
+                tx.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+                ensureParentsByMerge(datastore, path, tx, schemaContext);
+            }
+            for (final MapEntryNode child : ((MapNode) payload).body()) {
                 final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
                 tx.put(datastore, childPath, child);
             }
@@ -1160,10 +1180,11 @@ public class BrokerFacade implements Closeable {
         }
     }
 
-    private static void simplePut(final LogicalDatastoreType datastore, final YangInstanceIdentifier path,
-            final DOMDataTreeWriteTransaction tx, final SchemaContext schemaContext,
-            final NormalizedNode<?, ?> payload) {
-        ensureParentsByMerge(datastore, path, tx, schemaContext);
+    private void simplePut(final LogicalDatastoreType datastore, final YangInstanceIdentifier path,
+            final DOMDataTreeWriteTransaction tx, final SchemaContext schemaContext, final NormalizedNode payload) {
+        if (isMounted != null && !isMounted.get()) {
+            ensureParentsByMerge(datastore, path, tx, schemaContext);
+        }
         tx.put(datastore, path, payload);
     }
 
@@ -1183,7 +1204,7 @@ public class BrokerFacade implements Closeable {
     }
 
     private static void mergeDataWithinTransaction(final DOMDataTreeWriteTransaction tx,
-            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+            final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload,
             final SchemaContext schemaContext) {
         LOG.trace("Merge {} within Restconf Patch: {} with payload {}", datastore.name(), path, payload);
         ensureParentsByMerge(datastore, path, tx, schemaContext);
@@ -1199,8 +1220,8 @@ public class BrokerFacade implements Closeable {
         }
 
         final SchemaPath path = listener.getSchemaPath();
-        final ListenerRegistration<DOMNotificationListener> registration = this.domNotification
-                .registerNotificationListener(listener, path);
+        final ListenerRegistration<DOMNotificationListener> registration = domNotification
+                .registerNotificationListener(listener, Absolute.of(ImmutableList.copyOf(path.getPathFromRoot())));
 
         listener.setRegistration(registration);
     }
@@ -1228,11 +1249,9 @@ public class BrokerFacade implements Closeable {
             return;
         }
 
-        Preconditions.checkArgument(rootNormalizedPath != null, "Empty path received");
-
-        final NormalizedNode<?, ?> parentStructure = ImmutableNodes.fromInstanceId(schemaContext,
-                YangInstanceIdentifier.create(normalizedPathWithoutChildArgs));
-        tx.merge(store, rootNormalizedPath, parentStructure);
+        checkArgument(rootNormalizedPath != null, "Empty path received");
+        tx.merge(store, rootNormalizedPath, ImmutableNodes.fromInstanceId(schemaContext,
+            YangInstanceIdentifier.create(normalizedPathWithoutChildArgs)));
     }
 
     private static RestconfDocumentedException dataBrokerUnavailable(final YangInstanceIdentifier path) {
@@ -1240,11 +1259,17 @@ public class BrokerFacade implements Closeable {
         return new RestconfDocumentedException("DOM data broker service is not available for mount point " + path);
     }
 
+    private static EffectiveModelContext modelContext(final DOMMountPoint mountPoint) {
+        return mountPoint.getService(DOMSchemaService.class)
+            .flatMap(svc -> Optional.ofNullable(svc.getGlobalContext()))
+            .orElse(null);
+    }
+
     private static final class PatchStatusContextHelper {
         PatchStatusContext status;
 
         public PatchStatusContext getStatus() {
-            return this.status;
+            return status;
         }
 
         public void setStatus(final PatchStatusContext status) {