Integrate netconf-mapping-api into netconf-server
[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.server.api.operations.AbstractSingletonNetconfOperation;
14 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
15 import org.opendaylight.yangtools.yang.common.ErrorTag;
16 import org.opendaylight.yangtools.yang.common.ErrorType;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.w3c.dom.Document;
20 import org.w3c.dom.Element;
21
22 public class Unlock extends AbstractSingletonNetconfOperation {
23     private static final Logger LOG = LoggerFactory.getLogger(Unlock.class);
24     private static final String OPERATION_NAME = "unlock";
25
26     public Unlock(final String netconfSessionIdForReporting) {
27         super(netconfSessionIdForReporting);
28     }
29
30     @Override
31     protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement)
32             throws DocumentedException {
33         final Datastore targetDatastore = Lock.extractTargetParameter(operationElement);
34         if (targetDatastore == Datastore.candidate) {
35             LOG.debug("Unlocking candidate datastore on session: {}", getNetconfSessionIdForReporting());
36             return document.createElement(XmlNetconfConstants.OK);
37         }
38
39         throw new DocumentedException("Unable to unlock " + targetDatastore + " datastore",
40                 ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
41     }
42
43     @Override
44     protected String getOperationName() {
45         return OPERATION_NAME;
46     }
47 }