X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-bierman02%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Frestconf%2Fimpl%2FBrokerFacade.java;h=689f201536a58f26c93898ca8044bf3373e9f2a7;hb=982e75ece2483e413befe3edd8fd90022a644f72;hp=a5ea3e00eea510014a5943ba2bd8ab8a1131cd45;hpb=4ad8c8f798f194cc2c21212d8e5f0934d1a25306;p=netconf.git diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java index a5ea3e00ee..689f201536 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java @@ -7,15 +7,14 @@ */ package org.opendaylight.netconf.sal.restconf.impl; -import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; -import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; +import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; +import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import java.io.Closeable; import java.util.ArrayList; @@ -24,26 +23,24 @@ 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 javax.annotation.Nullable; +import java.util.concurrent.ExecutionException; import javax.ws.rs.core.Response.Status; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; -import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; -import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; -import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcException; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.ReadFailedException; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService; +import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; +import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction; +import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction; +import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; +import org.opendaylight.mdsal.dom.api.DOMMountPoint; +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.netconf.sal.streams.listeners.ListenerAdapter; import org.opendaylight.netconf.sal.streams.listeners.NotificationListenerAdapter; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; @@ -56,9 +53,9 @@ 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.yangtools.concepts.ListenerRegistration; 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.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; @@ -76,8 +73,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; 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.DataContainerNodeAttrBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder; +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.util.DataSchemaContextNode; import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; @@ -100,16 +97,16 @@ public class BrokerFacade implements Closeable { private final DOMNotificationService domNotification; private final ControllerContext controllerContext; - private BrokerFacade(DOMRpcService rpcService, DOMDataBroker domDataBroker, DOMNotificationService domNotification, - ControllerContext controllerContext) { + private BrokerFacade(final DOMRpcService rpcService, final DOMDataBroker domDataBroker, + final 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 static BrokerFacade newInstance(DOMRpcService rpcService, DOMDataBroker domDataBroker, - DOMNotificationService domNotification, ControllerContext controllerContext) { + public static BrokerFacade newInstance(final DOMRpcService rpcService, final DOMDataBroker domDataBroker, + final DOMNotificationService domNotification, final ControllerContext controllerContext) { return new BrokerFacade(rpcService, domDataBroker, domNotification, controllerContext); } @@ -138,7 +135,7 @@ public class BrokerFacade implements Closeable { * @return read date */ public NormalizedNode readConfigurationData(final YangInstanceIdentifier path, final String withDefa) { - try (DOMDataReadOnlyTransaction tx = this.domDataBroker.newReadOnlyTransaction()) { + try (DOMDataTreeReadTransaction tx = this.domDataBroker.newReadOnlyTransaction()) { return readDataViaTransaction(tx, CONFIGURATION, path, withDefa); } } @@ -172,13 +169,11 @@ public class BrokerFacade implements Closeable { final String withDefa) { final Optional domDataBrokerService = mountPoint.getService(DOMDataBroker.class); if (domDataBrokerService.isPresent()) { - try (DOMDataReadOnlyTransaction tx = domDataBrokerService.get().newReadOnlyTransaction()) { + try (DOMDataTreeReadTransaction tx = domDataBrokerService.get().newReadOnlyTransaction()) { return readDataViaTransaction(tx, CONFIGURATION, path, withDefa); } } - final String errMsg = "DOM data broker service isn't available for mount point " + path; - LOG.warn(errMsg); - throw new RestconfDocumentedException(errMsg); + throw dataBrokerUnavailable(path); } /** @@ -189,7 +184,7 @@ public class BrokerFacade implements Closeable { * @return read data */ public NormalizedNode readOperationalData(final YangInstanceIdentifier path) { - try (DOMDataReadOnlyTransaction tx = this.domDataBroker.newReadOnlyTransaction()) { + try (DOMDataTreeReadTransaction tx = this.domDataBroker.newReadOnlyTransaction()) { return readDataViaTransaction(tx, OPERATIONAL, path); } } @@ -206,13 +201,11 @@ public class BrokerFacade implements Closeable { public NormalizedNode readOperationalData(final DOMMountPoint mountPoint, final YangInstanceIdentifier path) { final Optional domDataBrokerService = mountPoint.getService(DOMDataBroker.class); if (domDataBrokerService.isPresent()) { - try (DOMDataReadOnlyTransaction tx = domDataBrokerService.get().newReadOnlyTransaction()) { + try (DOMDataTreeReadTransaction tx = domDataBrokerService.get().newReadOnlyTransaction()) { return readDataViaTransaction(tx, OPERATIONAL, path); } } - final String errMsg = "DOM data broker service isn't available for mount point " + path; - LOG.warn(errMsg); - throw new RestconfDocumentedException(errMsg); + throw dataBrokerUnavailable(path); } /** @@ -241,10 +234,10 @@ public class BrokerFacade implements Closeable { Preconditions.checkNotNull(path); Preconditions.checkNotNull(payload); - final DOMDataReadWriteTransaction newReadWriteTransaction = this.domDataBroker.newReadWriteTransaction(); + final DOMDataTreeReadWriteTransaction newReadWriteTransaction = this.domDataBroker.newReadWriteTransaction(); final Status status = readDataViaTransaction(newReadWriteTransaction, CONFIGURATION, path) != null ? Status.OK : Status.CREATED; - final CheckedFuture future = putDataViaTransaction( + final FluentFuture future = putDataViaTransaction( newReadWriteTransaction, CONFIGURATION, path, payload, globalSchema, insert, point); return new PutResult(status, future); } @@ -278,18 +271,16 @@ public class BrokerFacade implements Closeable { final Optional domDataBrokerService = mountPoint.getService(DOMDataBroker.class); if (domDataBrokerService.isPresent()) { - final DOMDataReadWriteTransaction newReadWriteTransaction = + final DOMDataTreeReadWriteTransaction newReadWriteTransaction = domDataBrokerService.get().newReadWriteTransaction(); final Status status = readDataViaTransaction(newReadWriteTransaction, CONFIGURATION, path) != null ? Status.OK : Status.CREATED; - final CheckedFuture future = putDataViaTransaction( + final FluentFuture future = putDataViaTransaction( newReadWriteTransaction, CONFIGURATION, path, payload, mountPoint.getSchemaContext(), insert, point); return new PutResult(status, future); } - final String errMsg = "DOM data broker service isn't available for mount point " + path; - LOG.warn(errMsg); - throw new RestconfDocumentedException(errMsg); + throw dataBrokerUnavailable(path); } public PatchStatusContext patchConfigurationDataWithinTransaction(final PatchContext patchContext) @@ -298,7 +289,7 @@ public class BrokerFacade implements Closeable { // get new transaction and schema context on server or on mounted device final SchemaContext schemaContext; - final DOMDataReadWriteTransaction patchTransaction; + final DOMDataTreeReadWriteTransaction patchTransaction; if (mountPoint == null) { schemaContext = patchContext.getInstanceIdentifierContext().getSchemaContext(); patchTransaction = this.domDataBroker.newReadWriteTransaction(); @@ -422,12 +413,12 @@ public class BrokerFacade implements Closeable { // if no errors commit transaction final CountDownLatch waiter = new CountDownLatch(1); - final CheckedFuture future = patchTransaction.submit(); + final FluentFuture future = patchTransaction.commit(); final PatchStatusContextHelper status = new PatchStatusContextHelper(); - Futures.addCallback(future, new FutureCallback() { + future.addCallback(new FutureCallback() { @Override - public void onSuccess(@Nullable final Void result) { + public void onSuccess(final CommitInfo result) { status.setStatus(new PatchStatusContext(patchContext.getPatchId(), ImmutableList.copyOf(editCollection), true, null)); waiter.countDown(); @@ -449,14 +440,14 @@ public class BrokerFacade implements Closeable { } // POST configuration - public CheckedFuture commitConfigurationDataPost( + public FluentFuture 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); } - public CheckedFuture commitConfigurationDataPost( + public FluentFuture commitConfigurationDataPost( final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode payload, final String insert, final String point) { final Optional domDataBrokerService = mountPoint.getService(DOMDataBroker.class); @@ -464,31 +455,25 @@ public class BrokerFacade implements Closeable { return postDataViaTransaction(domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path, payload, mountPoint.getSchemaContext(), insert, point); } - final String errMsg = "DOM data broker service isn't available for mount point " + path; - LOG.warn(errMsg); - throw new RestconfDocumentedException(errMsg); + throw dataBrokerUnavailable(path); } // DELETE configuration - public CheckedFuture commitConfigurationDataDelete( - final YangInstanceIdentifier path) { + public FluentFuture commitConfigurationDataDelete(final YangInstanceIdentifier path) { return deleteDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path); } - public CheckedFuture commitConfigurationDataDelete( + public FluentFuture commitConfigurationDataDelete( final DOMMountPoint mountPoint, final YangInstanceIdentifier path) { final Optional domDataBrokerService = mountPoint.getService(DOMDataBroker.class); if (domDataBrokerService.isPresent()) { return deleteDataViaTransaction(domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path); } - final String errMsg = "DOM data broker service isn't available for mount point " + path; - LOG.warn(errMsg); - throw new RestconfDocumentedException(errMsg); + throw dataBrokerUnavailable(path); } // RPC - public CheckedFuture invokeRpc(final SchemaPath type, - final NormalizedNode input) { + public FluentFuture invokeRpc(final SchemaPath type, final NormalizedNode input) { if (this.rpcService == null) { throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE); } @@ -503,8 +488,8 @@ public class BrokerFacade implements Closeable { } final YangInstanceIdentifier path = listener.getPath(); - DOMDataTreeChangeService changeService = (DOMDataTreeChangeService) - this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class); + DOMDataTreeChangeService changeService = this.domDataBroker.getExtensions() + .getInstance(DOMDataTreeChangeService.class); if (changeService == null) { throw new UnsupportedOperationException("DOMDataBroker does not support the DOMDataTreeChangeService" + this.domDataBroker); @@ -515,31 +500,26 @@ public class BrokerFacade implements Closeable { listener.setRegistration(registration); } - private NormalizedNode readDataViaTransaction(final DOMDataReadTransaction transaction, + private NormalizedNode readDataViaTransaction(final DOMDataTreeReadTransaction transaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path) { return readDataViaTransaction(transaction, datastore, path, null); } - private NormalizedNode readDataViaTransaction(final DOMDataReadTransaction transaction, + private NormalizedNode readDataViaTransaction(final DOMDataTreeReadTransaction transaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final String withDefa) { LOG.trace("Read {} via Restconf: {}", datastore.name(), path); try { - final Optional> optional = transaction.read(datastore, path).checkedGet(); + final Optional> optional = transaction.read(datastore, path).get(); return !optional.isPresent() ? null : withDefa == null ? optional.get() : prepareDataByParamWithDef(optional.get(), path, withDefa); - } catch (ReadFailedException e) { + } catch (InterruptedException e) { LOG.warn("Error reading {} from datastore {}", path, datastore.name(), e); - for (final RpcError error : e.getErrorList()) { - if (error.getErrorType() == RpcError.ErrorType.TRANSPORT - && error.getTag().equals(ErrorTag.RESOURCE_DENIED.getTagValue())) { - throw new RestconfDocumentedException( - error.getMessage(), - ErrorType.TRANSPORT, - ErrorTag.RESOURCE_DENIED_TRANSPORT, e); - } - } - throw new RestconfDocumentedException("Error reading data.", e, e.getErrorList()); + throw new RestconfDocumentedException("Error reading data.", e); + } catch (ExecutionException e) { + LOG.warn("Error reading {} from datastore {}", path, datastore.name(), e); + throw RestconfDocumentedException.decodeAndThrow("Error reading data.", Throwables.getCauseAs(e, + ReadFailedException.class)); } } @@ -561,13 +541,13 @@ public class BrokerFacade implements Closeable { final DataSchemaContextTree baseSchemaCtxTree = DataSchemaContextTree.from(ctx); final DataSchemaNode baseSchemaNode = baseSchemaCtxTree.getChild(path).getDataSchemaNode(); if (result instanceof ContainerNode) { - final DataContainerNodeAttrBuilder builder = + final DataContainerNodeBuilder builder = Builders.containerBuilder((ContainerSchemaNode) baseSchemaNode); buildCont(builder, (ContainerNode) result, baseSchemaCtxTree, path, trim); return builder.build(); } - final DataContainerNodeAttrBuilder builder = + final DataContainerNodeBuilder builder = Builders.mapEntryBuilder((ListSchemaNode) baseSchemaNode); buildMapEntryBuilder(builder, (MapEntryNode) result, baseSchemaCtxTree, path, trim, ((ListSchemaNode) baseSchemaNode).getKeyDefinition()); @@ -575,14 +555,14 @@ public class BrokerFacade implements Closeable { } private void buildMapEntryBuilder( - final DataContainerNodeAttrBuilder builder, + final DataContainerNodeBuilder builder, final MapEntryNode result, final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier actualPath, final boolean trim, final List keys) { for (final DataContainerChild child : result.getValue()) { final YangInstanceIdentifier path = actualPath.node(child.getIdentifier()); final DataSchemaNode childSchema = baseSchemaCtxTree.getChild(path).getDataSchemaNode(); if (child instanceof ContainerNode) { - final DataContainerNodeAttrBuilder childBuilder = + final DataContainerNodeBuilder childBuilder = Builders.containerBuilder((ContainerSchemaNode) childSchema); buildCont(childBuilder, (ContainerNode) child, baseSchemaCtxTree, path, trim); builder.withChild(childBuilder.build()); @@ -594,21 +574,21 @@ public class BrokerFacade implements Closeable { builder.withChild(childBuilder.build()); } else if (child instanceof LeafNode) { final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null); - final Object nodeVal = ((LeafNode) child).getValue(); - final NormalizedNodeAttrBuilder> leafBuilder = + final Object nodeVal = child.getValue(); + final NormalizedNodeBuilder> leafBuilder = Builders.leafBuilder((LeafSchemaNode) childSchema); if (keys.contains(child.getNodeType())) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(child.getValue()); builder.withChild(leafBuilder.build()); } else { if (trim) { if (defaultVal == null || !defaultVal.equals(nodeVal)) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(child.getValue()); builder.withChild(leafBuilder.build()); } } else { if (defaultVal != null && defaultVal.equals(nodeVal)) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(child.getValue()); builder.withChild(leafBuilder.build()); } } @@ -623,21 +603,21 @@ public class BrokerFacade implements Closeable { for (final MapEntryNode mapEntryNode : result.getValue()) { final YangInstanceIdentifier actualNode = path.node(mapEntryNode.getIdentifier()); final DataSchemaNode childSchema = baseSchemaCtxTree.getChild(actualNode).getDataSchemaNode(); - final DataContainerNodeAttrBuilder mapEntryBuilder = + final DataContainerNodeBuilder mapEntryBuilder = Builders.mapEntryBuilder((ListSchemaNode) childSchema); buildMapEntryBuilder(mapEntryBuilder, mapEntryNode, baseSchemaCtxTree, actualNode, trim, keys); builder.withChild(mapEntryBuilder.build()); } } - private void buildCont(final DataContainerNodeAttrBuilder builder, + private void buildCont(final DataContainerNodeBuilder builder, final ContainerNode result, final DataSchemaContextTree baseSchemaCtxTree, final YangInstanceIdentifier actualPath, final boolean trim) { for (final DataContainerChild child : result.getValue()) { final YangInstanceIdentifier path = actualPath.node(child.getIdentifier()); final DataSchemaNode childSchema = baseSchemaCtxTree.getChild(path).getDataSchemaNode(); if (child instanceof ContainerNode) { - final DataContainerNodeAttrBuilder builderChild = + final DataContainerNodeBuilder builderChild = Builders.containerBuilder((ContainerSchemaNode) childSchema); buildCont(builderChild, result, baseSchemaCtxTree, actualPath, trim); builder.withChild(builderChild.build()); @@ -649,17 +629,17 @@ public class BrokerFacade implements Closeable { builder.withChild(childBuilder.build()); } else if (child instanceof LeafNode) { final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null); - final Object nodeVal = ((LeafNode) child).getValue(); - final NormalizedNodeAttrBuilder> leafBuilder = + final Object nodeVal = child.getValue(); + final NormalizedNodeBuilder> leafBuilder = Builders.leafBuilder((LeafSchemaNode) childSchema); if (trim) { if (defaultVal == null || !defaultVal.equals(nodeVal)) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(child.getValue()); builder.withChild(leafBuilder.build()); } } else { if (defaultVal != null && defaultVal.equals(nodeVal)) { - leafBuilder.withValue(((LeafNode) child).getValue()); + leafBuilder.withValue(child.getValue()); builder.withChild(leafBuilder.build()); } } @@ -670,26 +650,26 @@ public class BrokerFacade implements Closeable { /** * POST data and submit transaction {@link DOMDataReadWriteTransaction}. */ - private CheckedFuture postDataViaTransaction( - final DOMDataReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, + private FluentFuture postDataViaTransaction( + final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext 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.submit(); + return rwTransaction.commit(); } /** * POST data and do NOT submit transaction {@link DOMDataReadWriteTransaction}. */ private void postDataWithinTransaction( - final DOMDataReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, + final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext 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 DOMDataReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, + private void postData(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext, final String insert, final String point) { if (insert == null) { @@ -779,7 +759,7 @@ public class BrokerFacade implements Closeable { } } - private void insertWithPointLeafListPost(final DOMDataReadWriteTransaction rwTransaction, + 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 boolean before) { @@ -811,7 +791,7 @@ public class BrokerFacade implements Closeable { } } - private void insertWithPointListPost(final DOMDataReadWriteTransaction rwTransaction, + private void insertWithPointListPost(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext, final String point, final MapNode readList, final boolean before) { @@ -865,7 +845,7 @@ public class BrokerFacade implements Closeable { throw new RestconfDocumentedException("Insert parameter can be used only with list or leaf-list"); } - private static void makeNormalPost(final DOMDataReadWriteTransaction rwTransaction, + private static void makeNormalPost(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext) { final Collection> children; @@ -920,7 +900,7 @@ public class BrokerFacade implements Closeable { } } - private static void simplePostPut(final DOMDataReadWriteTransaction rwTransaction, + private static void simplePostPut(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext) { checkItemDoesNotExists(rwTransaction, datastore, path); @@ -928,14 +908,17 @@ public class BrokerFacade implements Closeable { rwTransaction.put(datastore, path, payload); } - private static boolean doesItemExist(final DOMDataReadWriteTransaction rwTransaction, + private static boolean doesItemExist(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType store, final YangInstanceIdentifier path) { try { - return rwTransaction.exists(store, path).checkedGet(); - } catch (ReadFailedException e) { + return rwTransaction.exists(store, path).get(); + } catch (InterruptedException e) { + rwTransaction.cancel(); + throw new RestconfDocumentedException("Could not determine the existence of path " + path, e); + } catch (ExecutionException e) { rwTransaction.cancel(); - throw new RestconfDocumentedException("Could not determine the existence of path " + path, - e, e.getErrorList()); + throw RestconfDocumentedException.decodeAndThrow("Could not determine the existence of path " + path, + Throwables.getCauseAs(e, ReadFailedException.class)); } } @@ -945,11 +928,10 @@ public class BrokerFacade implements Closeable { * @param store Used datastore * @param path Path to item to verify its existence */ - private static void checkItemExists(final DOMDataReadWriteTransaction rwTransaction, + private static void checkItemExists(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType store, final YangInstanceIdentifier path) { if (!doesItemExist(rwTransaction, store, path)) { - final String errMsg = "Operation via Restconf was not executed because data does not exist"; - LOG.trace("{}:{}", errMsg, path); + LOG.trace("Operation via Restconf was not executed because data at {} does not exist", path); rwTransaction.cancel(); throw new RestconfDocumentedException("Data does not exist for path: " + path, ErrorType.PROTOCOL, ErrorTag.DATA_MISSING); @@ -962,11 +944,10 @@ public class BrokerFacade implements Closeable { * @param store Used datastore * @param path Path to item to verify its existence */ - private static void checkItemDoesNotExists(final DOMDataReadWriteTransaction rwTransaction, + private static void checkItemDoesNotExists(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType store, final YangInstanceIdentifier path) { if (doesItemExist(rwTransaction, store, path)) { - final String errMsg = "Operation via Restconf was not executed because data already exists"; - LOG.trace("{}:{}", errMsg, path); + LOG.trace("Operation via Restconf was not executed because data at {} already exists", path); rwTransaction.cancel(); throw new RestconfDocumentedException("Data already exists for path: " + path, ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS); @@ -981,27 +962,27 @@ public class BrokerFacade implements Closeable { * @param insert * insert */ - private CheckedFuture putDataViaTransaction( - final DOMDataReadWriteTransaction readWriteTransaction, final LogicalDatastoreType datastore, + private FluentFuture putDataViaTransaction( + final DOMDataTreeReadWriteTransaction readWriteTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext 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.submit(); + return readWriteTransaction.commit(); } /** * PUT data and do NOT submit {@link DOMDataReadWriteTransaction}. */ private void putDataWithinTransaction( - final DOMDataReadWriteTransaction writeTransaction, final LogicalDatastoreType datastore, + final DOMDataTreeReadWriteTransaction writeTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext 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 DOMDataReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, + private void putData(final DOMDataTreeReadWriteTransaction rwTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext, final String insert, final String point) { if (insert == null) { @@ -1088,7 +1069,7 @@ public class BrokerFacade implements Closeable { } } - private void insertWithPointLeafListPut(final DOMDataWriteTransaction tx, + 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 boolean before) { @@ -1118,7 +1099,7 @@ public class BrokerFacade implements Closeable { } } - private void insertWithPointListPut(final DOMDataWriteTransaction tx, final LogicalDatastoreType datastore, + 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) { tx.delete(datastore, path.getParent()); @@ -1147,7 +1128,7 @@ public class BrokerFacade implements Closeable { } } - private static void makePut(final DOMDataWriteTransaction tx, final LogicalDatastoreType datastore, + private static 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); @@ -1163,27 +1144,28 @@ public class BrokerFacade implements Closeable { } private static void simplePut(final LogicalDatastoreType datastore, final YangInstanceIdentifier path, - final DOMDataWriteTransaction tx, final SchemaContext schemaContext, final NormalizedNode payload) { + final DOMDataTreeWriteTransaction tx, final SchemaContext schemaContext, + final NormalizedNode payload) { ensureParentsByMerge(datastore, path, tx, schemaContext); tx.put(datastore, path, payload); } - private static CheckedFuture deleteDataViaTransaction( - final DOMDataReadWriteTransaction readWriteTransaction, final LogicalDatastoreType datastore, + private static FluentFuture deleteDataViaTransaction( + final DOMDataTreeReadWriteTransaction readWriteTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path) { LOG.trace("Delete {} via Restconf: {}", datastore.name(), path); checkItemExists(readWriteTransaction, datastore, path); readWriteTransaction.delete(datastore, path); - return readWriteTransaction.submit(); + return readWriteTransaction.commit(); } - private static void deleteDataWithinTransaction(final DOMDataWriteTransaction tx, + private static void deleteDataWithinTransaction(final DOMDataTreeWriteTransaction tx, final LogicalDatastoreType datastore, final YangInstanceIdentifier path) { LOG.trace("Delete {} within Restconf Patch: {}", datastore.name(), path); tx.delete(datastore, path); } - private static void mergeDataWithinTransaction(final DOMDataWriteTransaction tx, + private static void mergeDataWithinTransaction(final DOMDataTreeWriteTransaction tx, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, final SchemaContext schemaContext) { LOG.trace("Merge {} within Restconf Patch: {} with payload {}", datastore.name(), path, payload); @@ -1207,7 +1189,7 @@ public class BrokerFacade implements Closeable { } private static void ensureParentsByMerge(final LogicalDatastoreType store, - final YangInstanceIdentifier normalizedPath, final DOMDataWriteTransaction tx, + final YangInstanceIdentifier normalizedPath, final DOMDataTreeWriteTransaction tx, final SchemaContext schemaContext) { final List normalizedPathWithoutChildArgs = new ArrayList<>(); YangInstanceIdentifier rootNormalizedPath = null; @@ -1236,6 +1218,11 @@ public class BrokerFacade implements Closeable { tx.merge(store, rootNormalizedPath, parentStructure); } + private static RestconfDocumentedException dataBrokerUnavailable(final YangInstanceIdentifier path) { + LOG.warn("DOM data broker service is not available for mount point {}", path); + return new RestconfDocumentedException("DOM data broker service is not available for mount point " + path); + } + private static final class PatchStatusContextHelper { PatchStatusContext status;