X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=netconf%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2Fsal%2FLockChangeListener.java;fp=netconf%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2Fsal%2FLockChangeListener.java;h=2092057d48ffc3aeeda7d51f7ca24867f395716c;hb=a0833fb27c69d919a4420c6ecbd11a3b2a1119cb;hp=0000000000000000000000000000000000000000;hpb=243a7afbd100cfefc2fbca223912c561c049620b;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/LockChangeListener.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/LockChangeListener.java new file mode 100644 index 0000000000..2092057d48 --- /dev/null +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/LockChangeListener.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019 Lumina Networks, Inc. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.netconf.sal.connect.netconf.sal; + +import java.util.Collection; +import org.opendaylight.mdsal.binding.api.DataObjectModification; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.netconf.node.fields.optional.topology.node.DatastoreLock; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class LockChangeListener implements DataTreeChangeListener { + + private static final Logger LOG = LoggerFactory.getLogger(LockChangeListener.class); + + private final NetconfDeviceDataBroker netconfDeviceDataBroker; + + LockChangeListener(final DOMDataBroker netconfDeviceDataBrokder) { + this.netconfDeviceDataBroker = (NetconfDeviceDataBroker)netconfDeviceDataBrokder; + } + + @Override + public void onDataTreeChanged(final Collection> changes) { + for (final DataTreeModification change : changes) { + final DataObjectModification rootNode = change.getRootNode(); + switch (rootNode.getModificationType()) { + case SUBTREE_MODIFIED: + case WRITE: + if (!rootNode.getDataAfter().isDatastoreLockAllowed()) { + LOG.warn("With blocking the lock/unlock operations, the user is coming to" + + "operate in a manner which is not supported. It must not exist" + + "any concurrent access to the data store - it may interfere with" + + "data consistency."); + } + netconfDeviceDataBroker.setLockAllowed(rootNode.getDataAfter().isDatastoreLockAllowed()); + break; + case DELETE: + netconfDeviceDataBroker.setLockAllowed(true); + break; + default: + LOG.debug("Unsupported modification type: {}.", rootNode.getModificationType()); + } + } + } +}