2 * Copyright (c) 2016 Cisco 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
9 package org.opendaylight.netconf.topology.singleton.impl.tx;
11 import akka.actor.ActorSystem;
12 import akka.dispatch.OnComplete;
13 import com.google.common.base.Function;
14 import com.google.common.util.concurrent.CheckedFuture;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import com.google.common.util.concurrent.SettableFuture;
18 import javax.annotation.Nullable;
19 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
23 import org.opendaylight.netconf.topology.singleton.api.NetconfDOMTransaction;
24 import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
29 import scala.concurrent.Future;
31 public class NetconfWriteOnlyTransaction implements DOMDataWriteTransaction {
33 private final NetconfDOMTransaction delegate;
34 private final ActorSystem actorSystem;
36 public NetconfWriteOnlyTransaction(final ActorSystem actorSystem, final NetconfDOMTransaction delegate) {
37 this.delegate = delegate;
38 this.actorSystem = actorSystem;
42 public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
43 final NormalizedNode<?,?> data) {
44 delegate.put(store, new NormalizedNodeMessage(path, data));
48 public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
49 final NormalizedNode<?,?> data) {
50 delegate.merge(store, new NormalizedNodeMessage(path, data));
54 public boolean cancel() {
55 return delegate.cancel();
59 public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
60 delegate.delete(store, path);
64 public CheckedFuture<Void, TransactionCommitFailedException> submit() {
65 final Future<Void> submit = delegate.submit();
66 final SettableFuture<Void> settFuture = SettableFuture.create();
67 final CheckedFuture<Void, TransactionCommitFailedException> checkedFuture;
68 checkedFuture = Futures.makeChecked(settFuture, new Function<Exception, TransactionCommitFailedException>() {
71 public TransactionCommitFailedException apply(Exception input) {
72 return new TransactionCommitFailedException("Transaction commit failed", input);
75 submit.onComplete(new OnComplete<Void>() {
77 public void onComplete(Throwable throwable, Void object) throws Throwable {
78 if (throwable == null) {
79 settFuture.set(object);
81 settFuture.setException(throwable);
84 }, actorSystem.dispatcher());
89 public ListenableFuture<RpcResult<TransactionStatus>> commit() {
90 final Future<Void> commit = delegate.submit();
91 final SettableFuture<RpcResult<TransactionStatus>> settFuture = SettableFuture.create();
92 commit.onComplete(new OnComplete<Void>() {
94 public void onComplete(final Throwable throwable, final Void result) throws Throwable {
95 if (throwable == null) {
96 TransactionStatus status = TransactionStatus.SUBMITED;
97 RpcResult<TransactionStatus> rpcResult = RpcResultBuilder.success(status).build();
98 settFuture.set(rpcResult);
100 settFuture.setException(throwable);
103 }, actorSystem.dispatcher());
108 public Object getIdentifier() {