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.OperationLimiter;
13 import org.opendaylight.controller.cluster.datastore.RemoteTransactionContext;
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.VersionedExternalizableMessage;
19 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
20 import org.opendaylight.controller.cluster.datastore.modification.AbstractModification;
21 import org.opendaylight.controller.cluster.datastore.modification.DeleteModification;
22 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
23 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
24 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import scala.concurrent.Future;
32 * Implementation of TransactionContextImpl used when talking to a pre-Lithium controller that doesn't
33 * support the BatchedModifications message.
35 * @author Thomas Pantelis
38 public class PreLithiumTransactionContextImpl extends RemoteTransactionContext {
39 private static final Logger LOG = LoggerFactory.getLogger(PreLithiumTransactionContextImpl.class);
41 private final String transactionPath;
43 public PreLithiumTransactionContextImpl(TransactionIdentifier identifier, String transactionPath, ActorSelection actor,
44 ActorContext actorContext, boolean isTxActorLocal,
45 short remoteTransactionVersion, OperationLimiter limiter) {
46 super(identifier, actor, actorContext, isTxActorLocal, remoteTransactionVersion, limiter);
47 this.transactionPath = transactionPath;
51 public void executeModification(AbstractModification modification) {
52 final short remoteTransactionVersion = getRemoteTransactionVersion();
53 final YangInstanceIdentifier path = modification.getPath();
54 VersionedExternalizableMessage msg = null;
56 if(modification instanceof DeleteModification) {
57 msg = new DeleteData(path, remoteTransactionVersion);
58 } else if(modification instanceof WriteModification) {
59 final NormalizedNode<?, ?> data = ((WriteModification) modification).getData();
61 // be sure to check for Merge before Write, since Merge is a subclass of Write
62 if(modification instanceof MergeModification) {
63 msg = new MergeData(path, data, remoteTransactionVersion);
65 msg = new WriteData(path, data, remoteTransactionVersion);
68 LOG.error("Invalid modification type " + modification.getClass().getName());
72 executeOperationAsync(msg);
77 public Future<ActorSelection> readyTransaction() {
78 LOG.debug("Tx {} readyTransaction called", getIdentifier());
80 // Send the ReadyTransaction message to the Tx actor.
82 Future<Object> lastReplyFuture = executeOperationAsync(ReadyTransaction.INSTANCE);
84 return transformReadyReply(lastReplyFuture);
88 protected Future<ActorSelection> transformReadyReply(final Future<Object> readyReplyFuture) {
89 // In base Helium we used to return the local path of the actor which represented
90 // a remote ThreePhaseCommitCohort. The local path would then be converted to
91 // a remote path using this resolvePath method. To maintain compatibility with
92 // a Helium node we need to continue to do this conversion.
93 // At some point in the future when upgrades from Helium are not supported
94 // we could remove this code to resolvePath and just use the cohortPath as the
95 // resolved cohortPath
96 if (getRemoteTransactionVersion() < DataStoreVersions.HELIUM_1_VERSION) {
97 return PreLithiumTransactionReadyReplyMapper.transform(readyReplyFuture, getActorContext(), getIdentifier(), transactionPath);
99 return super.transformReadyReply(readyReplyFuture);
104 public boolean supportsDirectCommit() {
109 public Future<Object> directCommit() {
110 throw new UnsupportedOperationException("directCommit is not supported for " + getClass());