2 * Copyright (c) 2015 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.mdsal.connector.ops;
10 import org.opendaylight.netconf.api.DocumentedException;
11 import org.opendaylight.netconf.api.xml.XmlElement;
12 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
13 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
19 /* FIXME Duplicated code
20 netconf/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/
21 confignetconfconnector/operations/Lock.java
23 public class Lock extends AbstractSingletonNetconfOperation {
25 private static final Logger LOG = LoggerFactory.getLogger(Lock.class);
27 private static final String OPERATION_NAME = "lock";
28 private static final String TARGET_KEY = "target";
30 public Lock(final String netconfSessionIdForReporting) {
31 super(netconfSessionIdForReporting);
35 protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement)
36 throws DocumentedException {
37 final Datastore targetDatastore = extractTargetParameter(operationElement);
38 if (targetDatastore == Datastore.candidate) {
39 LOG.debug("Locking candidate datastore on session: {}", getNetconfSessionIdForReporting());
40 return document.createElement(XmlNetconfConstants.OK);
43 throw new DocumentedException("Unable to lock " + targetDatastore + " datastore",
44 DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
45 DocumentedException.ErrorSeverity.ERROR);
48 static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException {
49 final XmlElement targetElement = operationElement.getOnlyChildElementWithSameNamespace(TARGET_KEY);
50 final XmlElement targetChildNode = targetElement.getOnlyChildElementWithSameNamespace();
51 return Datastore.valueOf(targetChildNode.getName());
55 protected String getOperationName() {
56 return OPERATION_NAME;