Turn RestconfStrategy into an abstract class 50/93050/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 14 Oct 2020 12:47:36 +0000 (14:47 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 14 Oct 2020 14:59:28 +0000 (14:59 +0000)
The interactions between RestconfStrategy and FooBarUtil.bazXyzzy()
show that strategies may have some common logic. We do want to
properly specialize these and have them hosted somewhere, where
they can be decomposed.

Turn RestconfStrategy into an abstract class, so that we gain full
control of it and mark an earmark
TransactionUtil.ensureParentsByMerge() for migration.

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

index 710a17f4223638dbcbf2ed9751c057a509894cbf..1c090a61600e5517d9b554c24b0216ba54bbc083 100644 (file)
@@ -23,12 +23,12 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 /**
- * Strategy that allow to communicate with netconf devices in terms of md-sal transactions.
+ * Implementation of RESTCONF operations using {@link DOMTransactionChain} and related concepts.
  *
  * @see DOMTransactionChain
  * @see DOMDataTreeReadWriteTransaction
  */
-public class MdsalRestconfStrategy implements RestconfStrategy {
+public final class MdsalRestconfStrategy extends RestconfStrategy {
     private final DOMTransactionChain transactionChain;
     private final TransactionChainHandler transactionChainHandler;
 
index 1110d542a186b022b9d3b780e1ba90508d09e4e0..51bdd14d09742793ada7ffb261d2bf3293add718 100644 (file)
@@ -31,9 +31,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Strategy that allow to communicate with netconf devices using pure netconf operations.
+ * Implementation of RESTCONF operations on top of a raw NETCONF backend.
+ *
+ * @see NetconfDataTreeService
  */
-public class NetconfRestconfStrategy implements RestconfStrategy {
+public final class NetconfRestconfStrategy extends RestconfStrategy {
     private static final Logger LOG = LoggerFactory.getLogger(NetconfRestconfStrategy.class);
 
     private final NetconfDataTreeService netconfService;
index e6148e38272d7a62accaf5f5c6fd3f552dbeb4ef..1795d9ea234f406ae0fea015b4c169f355b29e12 100644 (file)
@@ -20,21 +20,30 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 /**
- * This interface allows interact with netconf operations in different ways.
+ * Baseline execution strategy for various RESTCONF operations.
  *
  * @see NetconfRestconfStrategy
  * @see MdsalRestconfStrategy
  */
-public interface RestconfStrategy {
+// FIXME: it seems the first three operations deal with lifecycle of a transaction, while others invoke various
+//        operations. This should be handled through proper allocation indirection.
+public abstract class RestconfStrategy {
     /**
      * Lock the entire datastore.
      */
-    void prepareReadWriteExecution();
+    public abstract void prepareReadWriteExecution();
+
+    /**
+     * Confirm previous operations.
+     *
+     * @return a FluentFuture containing the result of the commit information
+     */
+    public abstract FluentFuture<? extends @NonNull CommitInfo> commit();
 
     /**
      * Rollback changes and unlock the datastore.
      */
-    void cancel();
+    public abstract void cancel();
 
     /**
      * Read data from the datastore.
@@ -43,7 +52,8 @@ public interface RestconfStrategy {
      * @param path the data object path
      * @return a ListenableFuture containing the result of the read
      */
-    ListenableFuture<Optional<NormalizedNode<?, ?>>> read(LogicalDatastoreType store, YangInstanceIdentifier path);
+    public abstract ListenableFuture<Optional<NormalizedNode<?, ?>>> read(LogicalDatastoreType store,
+        YangInstanceIdentifier path);
 
     /**
      * Check if data already exists in the datastore.
@@ -52,7 +62,7 @@ public interface RestconfStrategy {
      * @param path the data object path
      * @return a FluentFuture containing the result of the check
      */
-    FluentFuture<Boolean> exists(LogicalDatastoreType store, YangInstanceIdentifier path);
+    public abstract FluentFuture<Boolean> exists(LogicalDatastoreType store, YangInstanceIdentifier path);
 
     /**
      * Delete data from the datastore.
@@ -60,7 +70,7 @@ public interface RestconfStrategy {
      * @param store the logical data store which should be modified
      * @param path the data object path
      */
-    void delete(LogicalDatastoreType store, YangInstanceIdentifier path);
+    public abstract void delete(LogicalDatastoreType store, YangInstanceIdentifier path);
 
     /**
      * Merges a piece of data with the existing data at a specified path.
@@ -69,7 +79,7 @@ public interface RestconfStrategy {
      * @param path the data object path
      * @param data the data object to be merged to the specified path
      */
-    void merge(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data);
+    public abstract void merge(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data);
 
     /**
      * Stores a piece of data at the specified path.
@@ -78,7 +88,7 @@ public interface RestconfStrategy {
      * @param path the data object path
      * @param data the data object to be merged to the specified path
      */
-    void create(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data);
+    public abstract void create(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data);
 
     /**
      * Replace a piece of data at the specified path.
@@ -87,26 +97,21 @@ public interface RestconfStrategy {
      * @param path the data object path
      * @param data the data object to be merged to the specified path
      */
-    void replace(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data);
-
-    /**
-     * Confirm previous operations.
-     *
-     * @return a FluentFuture containing the result of the commit information
-     */
-    FluentFuture<? extends @NonNull CommitInfo> commit();
+    public abstract void replace(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data);
 
     /**
      * Get transaction chain for creating specific transaction for specific operation.
      *
      * @return transaction chain or null
      */
-    @Nullable DOMTransactionChain getTransactionChain();
+    // FIXME: these look like an implementation detail
+    public abstract @Nullable DOMTransactionChain getTransactionChain();
 
     /**
      * Get transaction chain handler for creating new transaction chain.
      *
      * @return {@link TransactionChainHandler} or null
      */
-    @Nullable TransactionChainHandler getTransactionChainHandler();
+    // FIXME: these look like an implementation detail
+    public abstract @Nullable TransactionChainHandler getTransactionChainHandler();
 }
index 5d71fe0c08b559e4fd13a6bb0b0d9a047c6de777..7aa1d1937badbbf64dd50dc886a13665abe4ad49 100644 (file)
@@ -20,7 +20,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
  * Util class for common methods of transactions.
- *
  */
 public final class TransactionUtil {
     private TransactionUtil() {
@@ -34,6 +33,8 @@ public final class TransactionUtil {
      * @param schemaContext {@link SchemaContext}
      * @param strategy      object that perform the actual DS operations
      */
+    // FIXME: this method should only be invoked in MdsalRestconfStrategy, and even then only if we are crossing
+    //        an implicit list.
     public static void ensureParentsByMerge(final YangInstanceIdentifier path, final SchemaContext schemaContext,
                                             final RestconfStrategy strategy) {
         final List<PathArgument> normalizedPathWithoutChildArgs = new ArrayList<>();