Migrate netconf-console to Karaf 4 way
[netconf.git] / netconf / mdsal-netconf-connector / src / main / java / org / opendaylight / netconf / mdsal / connector / ops / Unlock.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.netconf.mdsal.connector.ops;
9
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.api.xml.XmlUtil;
14 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
19
20 /* FIXME Duplicated code
21    netconf/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/
22    operations/UnLock.java
23 */
24 public class Unlock extends AbstractSingletonNetconfOperation {
25
26     private static final Logger LOG = LoggerFactory.getLogger(Unlock.class);
27
28     private static final String OPERATION_NAME = "unlock";
29
30     public Unlock(final String netconfSessionIdForReporting) {
31         super(netconfSessionIdForReporting);
32     }
33
34     @Override
35     protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement)
36             throws DocumentedException {
37         final Datastore targetDatastore = Lock.extractTargetParameter(operationElement);
38         if (targetDatastore == Datastore.candidate) {
39             LOG.debug("Unlocking candidate datastore on session: {}", getNetconfSessionIdForReporting());
40             return XmlUtil.createElement(document, XmlNetconfConstants.OK);
41         }
42
43         throw new DocumentedException("Unable to unlock " + targetDatastore + " datastore",
44                 DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
45                 DocumentedException.ErrorSeverity.ERROR);
46     }
47
48     @Override
49     protected String getOperationName() {
50         return OPERATION_NAME;
51     }
52
53 }