2 * Copyright (c) 2014 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
8 package org.opendaylight.netconf.client.mdsal.spi;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import java.util.List;
13 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
16 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
17 import org.opendaylight.mdsal.dom.spi.PingPongMergingDOMDataBroker;
18 import org.opendaylight.netconf.client.mdsal.api.NetconfSessionPreferences;
19 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
20 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices.Rpcs;
21 import org.opendaylight.netconf.client.mdsal.impl.NetconfBaseOps;
22 import org.opendaylight.netconf.dom.api.tx.NetconfDOMDataBrokerFieldsExtension;
23 import org.opendaylight.netconf.dom.api.tx.NetconfDOMFieldsReadTransaction;
24 import org.opendaylight.netconf.dom.api.tx.NetconfDOMFieldsReadWriteTransaction;
25 import org.opendaylight.netconf.dom.api.tx.NetconfDOMFieldsTransactionChain;
26 import org.opendaylight.yangtools.yang.data.api.schema.MountPointContext;
28 public final class NetconfDeviceDataBroker implements PingPongMergingDOMDataBroker {
29 private final NetconfDOMDataBrokerFieldsExtension fieldsExtension = new NetconfDOMDataBrokerFieldsExtensionImpl();
30 private final RemoteDeviceId id;
31 private final NetconfBaseOps netconfOps;
32 private final boolean rollbackSupport;
33 private final boolean candidateSupported;
34 private final boolean runningWritable;
35 private final boolean lockDatastore;
37 public NetconfDeviceDataBroker(final RemoteDeviceId id, final MountPointContext mountContext, final Rpcs rpcs,
38 final NetconfSessionPreferences netconfSessionPreferences, final boolean lockDatastore) {
40 netconfOps = new NetconfBaseOps(rpcs, mountContext);
41 // get specific attributes from netconf preferences and get rid of it
42 // no need to keep the entire preferences object, its quite big with all the capability QNames
43 candidateSupported = netconfSessionPreferences.isCandidateSupported();
44 runningWritable = netconfSessionPreferences.isRunningWritable();
45 rollbackSupport = netconfSessionPreferences.isRollbackSupported();
46 checkArgument(candidateSupported || runningWritable,
47 "Device %s has advertised neither :writable-running nor :candidate capability. At least one of these "
48 + "should be advertised. Failed to establish a session.", id.name());
49 this.lockDatastore = lockDatastore;
53 public DOMDataTreeReadTransaction newReadOnlyTransaction() {
54 return new ReadOnlyTx(netconfOps, id);
58 public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
59 return new ReadWriteTx<>(newReadOnlyTransaction(), newWriteOnlyTransaction());
63 public DOMDataTreeWriteTransaction newWriteOnlyTransaction() {
64 final AbstractWriteTx ret;
65 if (candidateSupported) {
66 ret = runningWritable ? new WriteCandidateRunningTx(id, netconfOps, rollbackSupport, lockDatastore)
67 : new WriteCandidateTx(id, netconfOps, rollbackSupport, lockDatastore);
69 ret = new WriteRunningTx(id, netconfOps, rollbackSupport, lockDatastore);
76 public DOMTransactionChain createTransactionChain() {
77 return new TxChain(this);
81 public List<Extension> supportedExtensions() {
82 return List.of(fieldsExtension);
85 private final class NetconfDOMDataBrokerFieldsExtensionImpl implements NetconfDOMDataBrokerFieldsExtension {
87 public NetconfDOMFieldsReadTransaction newReadOnlyTransaction() {
88 return new FieldsAwareReadOnlyTx(netconfOps, id);
92 public NetconfDOMFieldsReadWriteTransaction newReadWriteTransaction() {
93 return new FieldsAwareReadWriteTx(newReadOnlyTransaction(), newWriteOnlyTransaction());
97 public NetconfDOMFieldsTransactionChain createTransactionChain() {
98 return new FieldsAwareTxChain(NetconfDeviceDataBroker.this, this);