2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.compat;
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.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import scala.concurrent.Future;
29 * Implementation of TransactionContextImpl used when talking to a pre-Lithium controller that doesn't
30 * support the BatchedModifications message.
32 * @author Thomas Pantelis
34 public class PreLithiumTransactionContextImpl extends TransactionContextImpl {
35 private static final Logger LOG = LoggerFactory.getLogger(PreLithiumTransactionContextImpl.class);
37 private final String transactionPath;
39 public PreLithiumTransactionContextImpl(String transactionPath, ActorSelection actor, TransactionIdentifier identifier,
40 String transactionChainId, ActorContext actorContext, SchemaContext schemaContext, boolean isTxActorLocal,
41 short remoteTransactionVersion, OperationCompleter operationCompleter) {
42 super(actor, identifier, transactionChainId, actorContext, schemaContext, isTxActorLocal,
43 remoteTransactionVersion, operationCompleter);
44 this.transactionPath = transactionPath;
48 public void deleteData(YangInstanceIdentifier path) {
49 executeOperationAsync(new DeleteData(path, getRemoteTransactionVersion()));
53 public void mergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
54 executeOperationAsync(new MergeData(path, data, getRemoteTransactionVersion()));
58 public void writeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
59 executeOperationAsync(new WriteData(path, data, getRemoteTransactionVersion()));
63 public Future<ActorSelection> readyTransaction() {
64 LOG.debug("Tx {} readyTransaction called", getIdentifier());
66 // Send the ReadyTransaction message to the Tx actor.
68 Future<Object> lastReplyFuture = executeOperationAsync(ReadyTransaction.INSTANCE);
70 return transformReadyReply(lastReplyFuture);
74 protected String extractCohortPathFrom(ReadyTransactionReply readyTxReply) {
75 // In base Helium we used to return the local path of the actor which represented
76 // a remote ThreePhaseCommitCohort. The local path would then be converted to
77 // a remote path using this resolvePath method. To maintain compatibility with
78 // a Helium node we need to continue to do this conversion.
79 // At some point in the future when upgrades from Helium are not supported
80 // we could remove this code to resolvePath and just use the cohortPath as the
81 // resolved cohortPath
82 if(getRemoteTransactionVersion() < DataStoreVersions.HELIUM_1_VERSION) {
83 return getActorContext().resolvePath(transactionPath, readyTxReply.getCohortPath());
86 return readyTxReply.getCohortPath();