Merge "Fix modules Restconf call for mounted devices"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / sal / NetconfDeviceDataBroker.java
1 /*
2  * Copyright (c) 2014 Cisco 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
9 package org.opendaylight.controller.sal.connect.netconf.sal;
10
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
18 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
19 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
20 import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences;
21 import org.opendaylight.controller.sal.connect.netconf.sal.tx.ReadOnlyTx;
22 import org.opendaylight.controller.sal.connect.netconf.sal.tx.ReadWriteTx;
23 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteCandidateRunningTx;
24 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteCandidateTx;
25 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteRunningTx;
26 import org.opendaylight.controller.sal.connect.netconf.util.NetconfBaseOps;
27 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
31
32 final class NetconfDeviceDataBroker implements DOMDataBroker {
33     private final RemoteDeviceId id;
34     private final NetconfBaseOps netconfOps;
35     private final NetconfSessionPreferences netconfSessionPreferences;
36
37     public NetconfDeviceDataBroker(final RemoteDeviceId id, final SchemaContext schemaContext, final DOMRpcService rpc, final NetconfSessionPreferences netconfSessionPreferences) {
38         this.id = id;
39         this.netconfOps = new NetconfBaseOps(rpc, schemaContext);
40         this.netconfSessionPreferences = netconfSessionPreferences;
41     }
42
43     @Override
44     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
45         return new ReadOnlyTx(netconfOps, id);
46     }
47
48     @Override
49     public DOMDataReadWriteTransaction newReadWriteTransaction() {
50         return new ReadWriteTx(newReadOnlyTransaction(), newWriteOnlyTransaction());
51     }
52
53     @Override
54     public DOMDataWriteTransaction newWriteOnlyTransaction() {
55         if(netconfSessionPreferences.isCandidateSupported()) {
56             if(netconfSessionPreferences.isRunningWritable()) {
57                 return new WriteCandidateRunningTx(id, netconfOps, netconfSessionPreferences);
58             } else {
59                 return new WriteCandidateTx(id, netconfOps, netconfSessionPreferences);
60             }
61         } else {
62             return new WriteRunningTx(id, netconfOps, netconfSessionPreferences);
63         }
64     }
65
66     @Override
67     public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
68         throw new UnsupportedOperationException(id + ": Data change listeners not supported for netconf mount point");
69     }
70
71     @Override
72     public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
73         throw new UnsupportedOperationException(id + ": Transaction chains not supported for netconf mount point");
74     }
75
76 }