733543aabdc262a7c3d5692a2629e6bc2b05982d
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / compat / PreLithiumTransactionContextImpl.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.compat;
9
10 import akka.actor.ActorSelection;
11 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
12 import org.opendaylight.controller.cluster.datastore.OperationLimiter;
13 import org.opendaylight.controller.cluster.datastore.RemoteTransactionContext;
14 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
15 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
16 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
17 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
18 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import scala.concurrent.Future;
24
25 /**
26  * Implementation of TransactionContextImpl used when talking to a pre-Lithium controller that doesn't
27  * support the BatchedModifications message.
28  *
29  * @author Thomas Pantelis
30  */
31 @Deprecated
32 public class PreLithiumTransactionContextImpl extends RemoteTransactionContext {
33     private static final Logger LOG = LoggerFactory.getLogger(PreLithiumTransactionContextImpl.class);
34
35     private final String transactionPath;
36
37     public PreLithiumTransactionContextImpl(String transactionPath, ActorSelection actor,
38             ActorContext actorContext, boolean isTxActorLocal,
39             short remoteTransactionVersion, OperationLimiter limiter) {
40         super(actor, actorContext, isTxActorLocal, remoteTransactionVersion, limiter);
41         this.transactionPath = transactionPath;
42     }
43
44     @Override
45     public void deleteData(YangInstanceIdentifier path) {
46         executeOperationAsync(new DeleteData(path, getRemoteTransactionVersion()));
47     }
48
49     @Override
50     public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
51         executeOperationAsync(new MergeData(path, data, getRemoteTransactionVersion()));
52     }
53
54     @Override
55     public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
56         executeOperationAsync(new WriteData(path, data, getRemoteTransactionVersion()));
57     }
58
59     @Override
60     public Future<ActorSelection> readyTransaction() {
61         LOG.debug("Tx {} readyTransaction called", getIdentifier());
62
63         // Send the ReadyTransaction message to the Tx actor.
64
65         Future<Object> lastReplyFuture = executeOperationAsync(ReadyTransaction.INSTANCE);
66
67         return transformReadyReply(lastReplyFuture);
68     }
69
70     @Override
71     protected Future<ActorSelection> transformReadyReply(final Future<Object> readyReplyFuture) {
72         // In base Helium we used to return the local path of the actor which represented
73         // a remote ThreePhaseCommitCohort. The local path would then be converted to
74         // a remote path using this resolvePath method. To maintain compatibility with
75         // a Helium node we need to continue to do this conversion.
76         // At some point in the future when upgrades from Helium are not supported
77         // we could remove this code to resolvePath and just use the cohortPath as the
78         // resolved cohortPath
79         if (getRemoteTransactionVersion() < DataStoreVersions.HELIUM_1_VERSION) {
80             return PreLithiumTransactionReadyReplyMapper.transform(readyReplyFuture, getActorContext(), getIdentifier(), transactionPath);
81         } else {
82             return super.transformReadyReply(readyReplyFuture);
83         }
84     }
85
86     @Override
87     public boolean supportsDirectCommit() {
88         return false;
89     }
90
91     @Override
92     public Future<Object> directCommit() {
93         throw new UnsupportedOperationException("directCommit is not supported for " + getClass());
94     }
95 }