BUG 3200 : Serialize a child node even when it is UNMODIFIED
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / TransactionProxy.java
index f12fdd99eab792080069f38bebe1a721a71f1b32..5081c9b4f8f652e55e5241733051bc8064aa96e2 100644 (file)
@@ -31,6 +31,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 import org.opendaylight.controller.cluster.datastore.compat.PreLithiumTransactionContextImpl;
 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
+import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
 import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory;
 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
 import org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregator;
@@ -61,23 +62,6 @@ import scala.concurrent.Promise;
  */
 public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIdentifier> implements DOMStoreReadWriteTransaction {
 
-    public static enum TransactionType {
-        READ_ONLY,
-        WRITE_ONLY,
-        READ_WRITE;
-
-        // Cache all values
-        private static final TransactionType[] VALUES = values();
-
-        public static TransactionType fromInt(final int type) {
-            try {
-                return VALUES[type];
-            } catch (IndexOutOfBoundsException e) {
-                throw new IllegalArgumentException("In TransactionType enum value " + type, e);
-            }
-        }
-    }
-
     private static enum TransactionState {
         OPEN,
         READY,
@@ -113,7 +97,6 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
 
     private final TransactionType transactionType;
     final ActorContext actorContext;
-    private final String transactionChainId;
     private final SchemaContext schemaContext;
     private TransactionState state = TransactionState.OPEN;
 
@@ -126,25 +109,24 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
     }
 
     public TransactionProxy(ActorContext actorContext, TransactionType transactionType, String transactionChainId) {
-        super(createIdentifier(actorContext));
+        super(createIdentifier(actorContext, transactionChainId));
         this.actorContext = Preconditions.checkNotNull(actorContext,
             "actorContext should not be null");
         this.transactionType = Preconditions.checkNotNull(transactionType,
             "transactionType should not be null");
         this.schemaContext = Preconditions.checkNotNull(actorContext.getSchemaContext(),
             "schemaContext should not be null");
-        this.transactionChainId = transactionChainId;
 
         LOG.debug("Created txn {} of type {} on chain {}", getIdentifier(), transactionType, transactionChainId);
     }
 
-    private static TransactionIdentifier createIdentifier(ActorContext actorContext) {
+    private static TransactionIdentifier createIdentifier(ActorContext actorContext, String transactionChainId) {
         String memberName = actorContext.getCurrentMemberName();
         if (memberName == null) {
             memberName = "UNKNOWN-MEMBER";
         }
 
-        return new TransactionIdentifier(memberName, counter.getAndIncrement());
+        return TransactionIdentifier.create(memberName, counter.getAndIncrement(), transactionChainId);
     }
 
     @VisibleForTesting
@@ -159,7 +141,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
         return false;
     }
 
-    private boolean isRootPath(YangInstanceIdentifier path){
+    private static boolean isRootPath(YangInstanceIdentifier path) {
         return !path.getPathArguments().iterator().hasNext();
     }
 
@@ -380,7 +362,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
         TransactionFutureCallback txFutureCallback = txFutureCallbackMap.values().iterator().next();
 
         LOG.debug("Tx {} Readying transaction for shard {} on chain {}", getIdentifier(),
-                txFutureCallback.getShardName(), transactionChainId);
+                txFutureCallback.getShardName(), getTransactionChainId());
 
         final OperationCallback.Reference operationCallbackRef =
                 new OperationCallback.Reference(OperationCallback.NO_OP_CALLBACK);
@@ -420,7 +402,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
         for(TransactionFutureCallback txFutureCallback : txFutureCallbackMap.values()) {
 
             LOG.debug("Tx {} Readying transaction for shard {} on chain {}", getIdentifier(),
-                        txFutureCallback.getShardName(), transactionChainId);
+                        txFutureCallback.getShardName(), getTransactionChainId());
 
             final TransactionContext transactionContext = txFutureCallback.getTransactionContext();
             final Future<ActorSelection> future;
@@ -477,7 +459,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
         return ShardStrategyFactory.getStrategy(path).findShard(path);
     }
 
-    protected Future<ActorSelection> sendFindPrimaryShardAsync(String shardName) {
+    protected Future<PrimaryShardInfo> sendFindPrimaryShardAsync(String shardName) {
         return actorContext.findPrimaryShardAsync(shardName);
     }
 
@@ -497,20 +479,20 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
     private TransactionFutureCallback getOrCreateTxFutureCallback(String shardName) {
         TransactionFutureCallback txFutureCallback = txFutureCallbackMap.get(shardName);
         if(txFutureCallback == null) {
-            Future<ActorSelection> findPrimaryFuture = sendFindPrimaryShardAsync(shardName);
+            Future<PrimaryShardInfo> findPrimaryFuture = sendFindPrimaryShardAsync(shardName);
 
             final TransactionFutureCallback newTxFutureCallback = new TransactionFutureCallback(this, shardName);
 
             txFutureCallback = newTxFutureCallback;
             txFutureCallbackMap.put(shardName, txFutureCallback);
 
-            findPrimaryFuture.onComplete(new OnComplete<ActorSelection>() {
+            findPrimaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
                 @Override
-                public void onComplete(Throwable failure, ActorSelection primaryShard) {
+                public void onComplete(Throwable failure, PrimaryShardInfo primaryShardInfo) {
                     if(failure != null) {
                         newTxFutureCallback.createTransactionContext(failure, null);
                     } else {
-                        newTxFutureCallback.setPrimaryShard(primaryShard);
+                        newTxFutureCallback.setPrimaryShard(primaryShardInfo.getPrimaryShardActor());
                     }
                 }
             }, actorContext.getClientDispatcher());
@@ -520,7 +502,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
     }
 
     String getTransactionChainId() {
-        return transactionChainId;
+        return getIdentifier().getChainId();
     }
 
     protected ActorContext getActorContext() {
@@ -557,11 +539,11 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
 
         if(remoteTransactionVersion < DataStoreVersions.LITHIUM_VERSION) {
             return new PreLithiumTransactionContextImpl(transactionPath, transactionActor, getIdentifier(),
-                    transactionChainId, actorContext, schemaContext, isTxActorLocal, remoteTransactionVersion,
+                    actorContext, isTxActorLocal, remoteTransactionVersion,
                     operationCompleter);
         } else {
-            return new TransactionContextImpl(transactionActor, getIdentifier(), transactionChainId,
-                    actorContext, schemaContext, isTxActorLocal, remoteTransactionVersion, operationCompleter);
+            return new TransactionContextImpl(transactionActor, getIdentifier(),
+                    actorContext, isTxActorLocal, remoteTransactionVersion, operationCompleter);
         }
     }
 }