Netconf stack by default locks the data store before issuing
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / LockChangeListener.java
1 /*
2  * Copyright (c) 2019 Lumina Networks, Inc. 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 package org.opendaylight.netconf.sal.connect.netconf.sal;
9
10 import java.util.Collection;
11 import org.opendaylight.mdsal.binding.api.DataObjectModification;
12 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
13 import org.opendaylight.mdsal.binding.api.DataTreeModification;
14 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.netconf.node.fields.optional.topology.node.DatastoreLock;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 final class LockChangeListener implements DataTreeChangeListener<DatastoreLock> {
20
21     private static final Logger LOG = LoggerFactory.getLogger(LockChangeListener.class);
22
23     private final NetconfDeviceDataBroker netconfDeviceDataBroker;
24
25     LockChangeListener(final DOMDataBroker netconfDeviceDataBrokder) {
26         this.netconfDeviceDataBroker = (NetconfDeviceDataBroker)netconfDeviceDataBrokder;
27     }
28
29     @Override
30     public void onDataTreeChanged(final Collection<DataTreeModification<DatastoreLock>> changes) {
31         for (final DataTreeModification<DatastoreLock> change : changes) {
32             final DataObjectModification<DatastoreLock> rootNode = change.getRootNode();
33             switch (rootNode.getModificationType()) {
34                 case SUBTREE_MODIFIED:
35                 case WRITE:
36                     if (!rootNode.getDataAfter().isDatastoreLockAllowed()) {
37                         LOG.warn("With blocking the lock/unlock operations, the user is coming to"
38                                  + "operate in a manner which is not supported. It must not exist"
39                                  + "any concurrent access to the data store - it may interfere with"
40                                  + "data consistency.");
41                     }
42                     netconfDeviceDataBroker.setLockAllowed(rootNode.getDataAfter().isDatastoreLockAllowed());
43                     break;
44                 case DELETE:
45                     netconfDeviceDataBroker.setLockAllowed(true);
46                     break;
47                 default:
48                     LOG.debug("Unsupported modification type: {}.", rootNode.getModificationType());
49             }
50         }
51     }
52 }