Improve RestconfStrategy API surface 38/107838/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 12 Sep 2023 15:09:10 +0000 (17:09 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 12 Sep 2023 17:36:38 +0000 (17:36 +0000)
We have a number of methods which are only used internally, which formed
our (ugly) API surface. Hide them so we are free to evolve them.

Change-Id: I219d90e5f709c59e98739a73971a577f14659e9f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/BatchedExistenceCheck.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfStrategy.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfTransaction.java

index 8bb7b240c0691a837f8452f10f8d52101223e9f0..25c339cc7757f9f0340e16d49c08f3a2cc1dac0f 100644 (file)
@@ -35,12 +35,11 @@ final class BatchedExistenceCheck {
         outstanding = total;
     }
 
-    static BatchedExistenceCheck start(final DOMDataTreeReadOperations tx,
-                                       final LogicalDatastoreType datastore, final YangInstanceIdentifier parentPath,
-                                       final Collection<? extends NormalizedNode> children) {
-        final BatchedExistenceCheck ret = new BatchedExistenceCheck(children.size());
-        for (NormalizedNode child : children) {
-            final YangInstanceIdentifier path = parentPath.node(child.name());
+    static BatchedExistenceCheck start(final DOMDataTreeReadOperations tx, final LogicalDatastoreType datastore,
+            final YangInstanceIdentifier parentPath, final Collection<? extends NormalizedNode> children) {
+        final var ret = new BatchedExistenceCheck(children.size());
+        for (var child : children) {
+            final var path = parentPath.node(child.name());
             tx.exists(datastore, path).addCallback(new FutureCallback<Boolean>() {
                 @Override
                 public void onSuccess(final Boolean result) {
index 48105427e2167132397500af0d2ae19781cfad49..43c85a192ccefe703f324458ae44c1606d800d80 100644 (file)
@@ -43,12 +43,12 @@ public final class MdsalRestconfStrategy extends RestconfStrategy {
     }
 
     @Override
-    public RestconfTransaction prepareWriteExecution() {
+    RestconfTransaction prepareWriteExecution() {
         return new MdsalRestconfTransaction(dataBroker);
     }
 
     @Override
-    protected void delete(final SettableRestconfFuture<Empty> future, final YangInstanceIdentifier path) {
+    void delete(final SettableRestconfFuture<Empty> future, final YangInstanceIdentifier path) {
         final var tx = dataBroker.newReadWriteTransaction();
         tx.exists(CONFIGURATION, path).addCallback(new FutureCallback<>() {
             @Override
@@ -87,7 +87,7 @@ public final class MdsalRestconfStrategy extends RestconfStrategy {
     }
 
     @Override
-    public ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
+    ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
             final YangInstanceIdentifier path) {
         try (var tx = dataBroker.newReadOnlyTransaction()) {
             return tx.read(store, path);
@@ -95,8 +95,8 @@ public final class MdsalRestconfStrategy extends RestconfStrategy {
     }
 
     @Override
-    public ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
-            final YangInstanceIdentifier path, final List<YangInstanceIdentifier> fields) {
+    ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store, final YangInstanceIdentifier path,
+            final List<YangInstanceIdentifier> fields) {
         return Futures.immediateFailedFuture(new UnsupportedOperationException(
                 "Reading of selected subtrees is currently not supported in: " + MdsalRestconfStrategy.class));
     }
index fa9bf1b610a3fc218c9d7aadab32ec2d86980795..d8714cd310d78ef60b00860688f63b9a15e92599 100644 (file)
@@ -38,7 +38,7 @@ public final class NetconfRestconfStrategy extends RestconfStrategy {
     }
 
     @Override
-    protected void delete(final SettableRestconfFuture<Empty> future, final YangInstanceIdentifier path) {
+    void delete(final SettableRestconfFuture<Empty> future, final YangInstanceIdentifier path) {
         final var tx = prepareWriteExecution();
         tx.delete(path);
         Futures.addCallback(tx.commit(), new FutureCallback<CommitInfo>() {
@@ -55,12 +55,12 @@ public final class NetconfRestconfStrategy extends RestconfStrategy {
     }
 
     @Override
-    public RestconfTransaction prepareWriteExecution() {
+    RestconfTransaction prepareWriteExecution() {
         return new NetconfRestconfTransaction(netconfService);
     }
 
     @Override
-    public ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
+    ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
             final YangInstanceIdentifier path) {
         return switch (store) {
             case CONFIGURATION -> netconfService.getConfig(path);
@@ -69,7 +69,7 @@ public final class NetconfRestconfStrategy extends RestconfStrategy {
     }
 
     @Override
-    public ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
+    ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
             final YangInstanceIdentifier path, final List<YangInstanceIdentifier> fields) {
         return switch (store) {
             case CONFIGURATION -> netconfService.getConfig(path, fields);
index d35cca7f7d19db399672db61d2a71f3f162899f1..e0ed5bf6f79c5f807573295618075ce4688abd8c 100644 (file)
@@ -74,7 +74,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
     }
 
     @Override
-    public void cancel() {
+    void cancel() {
         resultsFutures.clear();
         executeWithLogging(netconfService::discardChanges);
         executeWithLogging(netconfService::unlock);
@@ -127,7 +127,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
     }
 
     @Override
-    public ListenableFuture<? extends @NonNull CommitInfo> commit() {
+    ListenableFuture<? extends @NonNull CommitInfo> commit() {
         final SettableFuture<CommitInfo> commitResult = SettableFuture.create();
 
         // First complete all resultsFutures and merge them ...
index 781855a17120625c3a618024f3db97e2afb1808f..69b505afd50e8981b4faf341fd139dd7ba5015d4 100644 (file)
@@ -137,7 +137,7 @@ public abstract class RestconfStrategy {
      * @return A {@link RestconfTransaction}. This transaction needs to be either committed or canceled before doing
      *         anything else.
      */
-    public abstract RestconfTransaction prepareWriteExecution();
+    abstract RestconfTransaction prepareWriteExecution();
 
     /**
      * Read data from the datastore.
@@ -146,7 +146,7 @@ public abstract class RestconfStrategy {
      * @param path the data object path
      * @return a ListenableFuture containing the result of the read
      */
-    public abstract ListenableFuture<Optional<NormalizedNode>> read(LogicalDatastoreType store,
+    abstract ListenableFuture<Optional<NormalizedNode>> read(LogicalDatastoreType store,
         YangInstanceIdentifier path);
 
     /**
@@ -157,7 +157,7 @@ public abstract class RestconfStrategy {
      * @param fields paths to selected fields relative to parent path
      * @return a ListenableFuture containing the result of the read
      */
-    public abstract ListenableFuture<Optional<NormalizedNode>> read(LogicalDatastoreType store,
+    abstract ListenableFuture<Optional<NormalizedNode>> read(LogicalDatastoreType store,
             YangInstanceIdentifier path, List<YangInstanceIdentifier> fields);
 
     /**
@@ -184,7 +184,7 @@ public abstract class RestconfStrategy {
         return ret;
     }
 
-    protected abstract void delete(@NonNull SettableRestconfFuture<Empty> future, @NonNull YangInstanceIdentifier path);
+    abstract void delete(@NonNull SettableRestconfFuture<Empty> future, @NonNull YangInstanceIdentifier path);
 
     /**
      * Merge data into the configuration datastore, as outlined in
@@ -620,6 +620,27 @@ public abstract class RestconfStrategy {
         };
     }
 
+    private @Nullable NormalizedNode readDataViaTransaction(final LogicalDatastoreType store,
+            final YangInstanceIdentifier path) {
+        return TransactionUtil.syncAccess(read(store, path), path).orElse(null);
+    }
+
+    /**
+     * Read specific type of data {@link LogicalDatastoreType} via transaction in {@link RestconfStrategy} with
+     * specified subtrees that should only be read.
+     *
+     * @param store                 datastore type
+     * @param path                  parent path to selected fields
+     * @param closeTransactionChain if it is set to {@code true}, after transaction it will close transactionChain
+     *                              in {@link RestconfStrategy} if any
+     * @param fields                paths to selected subtrees which should be read, relative to to the parent path
+     * @return {@link NormalizedNode}
+     */
+    private @Nullable NormalizedNode readDataViaTransaction(final @NonNull LogicalDatastoreType store,
+            final @NonNull YangInstanceIdentifier path, final @NonNull List<YangInstanceIdentifier> fields) {
+        return TransactionUtil.syncAccess(read(store, path, fields), path).orElse(null);
+    }
+
     private static NormalizedNode prepareDataByParamWithDef(final NormalizedNode readData,
             final YangInstanceIdentifier path, final WithDefaultsMode defaultsMode, final EffectiveModelContext ctx) {
         final boolean trim = switch (defaultsMode) {
@@ -777,27 +798,6 @@ public abstract class RestconfStrategy {
         return childCtx;
     }
 
-    private @Nullable NormalizedNode readDataViaTransaction(final LogicalDatastoreType store,
-            final YangInstanceIdentifier path) {
-        return TransactionUtil.syncAccess(read(store, path), path).orElse(null);
-    }
-
-    /**
-     * Read specific type of data {@link LogicalDatastoreType} via transaction in {@link RestconfStrategy} with
-     * specified subtrees that should only be read.
-     *
-     * @param store                 datastore type
-     * @param path                  parent path to selected fields
-     * @param closeTransactionChain if it is set to {@code true}, after transaction it will close transactionChain
-     *                              in {@link RestconfStrategy} if any
-     * @param fields                paths to selected subtrees which should be read, relative to to the parent path
-     * @return {@link NormalizedNode}
-     */
-    private @Nullable NormalizedNode readDataViaTransaction(final @NonNull LogicalDatastoreType store,
-            final @NonNull YangInstanceIdentifier path, final @NonNull List<YangInstanceIdentifier> fields) {
-        return TransactionUtil.syncAccess(read(store, path, fields), path).orElse(null);
-    }
-
     private static NormalizedNode mergeConfigAndSTateDataIfNeeded(final NormalizedNode stateDataNode,
                                                                   final NormalizedNode configDataNode) {
         // if no data exists
index e97bc96b3989333944f6a93eb6f7da4ff4c6e3f1..8eddae84c5f3b4e9d3bb394d0480e07db16bab1e 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.restconf.nb.rfc8040.rests.transactions;
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Optional;
@@ -32,8 +31,7 @@ import org.slf4j.LoggerFactory;
  */
 // FIXME: it seems the first two operations deal with lifecycle of a transaction, while others invoke various
 //        operations. This should be handled through proper allocation indirection.
-@Beta
-public abstract class RestconfTransaction {
+abstract class RestconfTransaction {
     private static final Logger LOG = LoggerFactory.getLogger(RestconfTransaction.class);
 
     RestconfTransaction() {
@@ -44,21 +42,21 @@ public abstract class RestconfTransaction {
      * Rollback changes and unlock the datastore.
      */
     // FIXME: this looks synchronous, but it should not be
-    public abstract void cancel();
+    abstract void cancel();
 
     /**
      * Confirm previous operations.
      *
      * @return a FluentFuture containing the result of the commit information
      */
-    public abstract ListenableFuture<? extends @NonNull CommitInfo> commit();
+    abstract ListenableFuture<? extends @NonNull CommitInfo> commit();
 
     /**
      * Delete data from the datastore.
      *
      * @param path the data object path
      */
-    public final void delete(final YangInstanceIdentifier path) {
+    final void delete(final YangInstanceIdentifier path) {
         LOG.trace("Delete {}", path);
         deleteImpl(requireNonNull(path));
     }
@@ -70,7 +68,7 @@ public abstract class RestconfTransaction {
      *
      * @param path the data object path
      */
-    public final void remove(final YangInstanceIdentifier path) {
+    final void remove(final YangInstanceIdentifier path) {
         LOG.trace("Remove {}", path);
         removeImpl(requireNonNull(path));
     }
@@ -83,7 +81,7 @@ public abstract class RestconfTransaction {
      * @param path the data object path
      * @param data the data object to be merged to the specified path
      */
-    public final void merge(final YangInstanceIdentifier path, final NormalizedNode data) {
+    final void merge(final YangInstanceIdentifier path, final NormalizedNode data) {
         LOG.trace("Merge {}", path);
         LOG.trace(Markers.confidential(), "Merge with {}", data.prettyTree());
         mergeImpl(requireNonNull(path), data);
@@ -98,7 +96,7 @@ public abstract class RestconfTransaction {
      * @param data    the data object to be merged to the specified path
      * @param context static view of compiled yang files
      */
-    public final void create(final YangInstanceIdentifier path, final NormalizedNode data,
+    final void create(final YangInstanceIdentifier path, final NormalizedNode data,
             final EffectiveModelContext context) {
         LOG.trace("Create {}", path);
         LOG.trace(Markers.confidential(), "Create as {}", data.prettyTree());
@@ -115,7 +113,7 @@ public abstract class RestconfTransaction {
      * @param data    the data object to be merged to the specified path
      * @param context static view of compiled yang files
      */
-    public final void replace(final YangInstanceIdentifier path, final NormalizedNode data,
+    final void replace(final YangInstanceIdentifier path, final NormalizedNode data,
             final EffectiveModelContext context) {
         LOG.trace("Replace {}", path);
         LOG.trace(Markers.confidential(), "Replace with {}", data.prettyTree());
@@ -164,5 +162,4 @@ public abstract class RestconfTransaction {
         merge(rootNormalizedPath,
             ImmutableNodes.fromInstanceId(context, YangInstanceIdentifier.of(normalizedPathWithoutChildArgs)));
     }
-
 }