CDS: do not propagate SchemaContext
[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.OperationCompleter;
13 import org.opendaylight.controller.cluster.datastore.TransactionContextImpl;
14 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
15 import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
16 import org.opendaylight.controller.cluster.datastore.messages.MergeData;
17 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
18 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply;
19 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
20 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import scala.concurrent.Future;
26
27 /**
28  * Implementation of TransactionContextImpl used when talking to a pre-Lithium controller that doesn't
29  * support the BatchedModifications message.
30  *
31  * @author Thomas Pantelis
32  */
33 public class PreLithiumTransactionContextImpl extends TransactionContextImpl {
34     private static final Logger LOG = LoggerFactory.getLogger(PreLithiumTransactionContextImpl.class);
35
36     private final String transactionPath;
37
38     public PreLithiumTransactionContextImpl(String transactionPath, ActorSelection actor, TransactionIdentifier identifier,
39             String transactionChainId, ActorContext actorContext, boolean isTxActorLocal,
40             short remoteTransactionVersion, OperationCompleter operationCompleter) {
41         super(actor, identifier, transactionChainId, actorContext, isTxActorLocal,
42                 remoteTransactionVersion, operationCompleter);
43         this.transactionPath = transactionPath;
44     }
45
46     @Override
47     public void deleteData(YangInstanceIdentifier path) {
48         executeOperationAsync(new DeleteData(path, getRemoteTransactionVersion()));
49     }
50
51     @Override
52     public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
53         executeOperationAsync(new MergeData(path, data, getRemoteTransactionVersion()));
54     }
55
56     @Override
57     public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
58         executeOperationAsync(new WriteData(path, data, getRemoteTransactionVersion()));
59     }
60
61     @Override
62     public Future<ActorSelection> readyTransaction() {
63         LOG.debug("Tx {} readyTransaction called", getIdentifier());
64
65         // Send the ReadyTransaction message to the Tx actor.
66
67         Future<Object> lastReplyFuture = executeOperationAsync(ReadyTransaction.INSTANCE);
68
69         return transformReadyReply(lastReplyFuture);
70     }
71
72     @Override
73     protected String extractCohortPathFrom(ReadyTransactionReply readyTxReply) {
74         // In base Helium we used to return the local path of the actor which represented
75         // a remote ThreePhaseCommitCohort. The local path would then be converted to
76         // a remote path using this resolvePath method. To maintain compatibility with
77         // a Helium node we need to continue to do this conversion.
78         // At some point in the future when upgrades from Helium are not supported
79         // we could remove this code to resolvePath and just use the cohortPath as the
80         // resolved cohortPath
81         if(getRemoteTransactionVersion() < DataStoreVersions.HELIUM_1_VERSION) {
82             return getActorContext().resolvePath(transactionPath, readyTxReply.getCohortPath());
83         }
84
85         return readyTxReply.getCohortPath();
86     }
87
88     @Override
89     public boolean supportsDirectCommit() {
90         return false;
91     }
92
93     @Override
94     public Future<Object> directCommit() {
95         throw new UnsupportedOperationException("directCommit is not supported for " + getClass());
96     }
97 }