BUG 2743 - Added support for runtime RPC's to netconf mdsal northbound.
[controller.git] / opendaylight / netconf / mdsal-netconf-connector / src / main / java / org / opendaylight / controller / 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
9 package org.opendaylight.controller.netconf.mdsal.connector.ops;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
13 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
14 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
15 import org.opendaylight.controller.netconf.util.xml.XmlElement;
16 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
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
24     private static final Logger LOG = LoggerFactory.getLogger(Unlock.class);
25
26     private static final String OPERATION_NAME = "unlock";
27     private static final String TARGET_KEY = "target";
28
29     public Unlock(final String netconfSessionIdForReporting) {
30         super(netconfSessionIdForReporting);
31     }
32
33     @Override
34     protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException {
35         final Datastore targetDatastore = Lock.extractTargetParameter(operationElement);
36         if (targetDatastore == Datastore.candidate) {
37             LOG.debug("Unlocking candidate datastore on session: {}", getNetconfSessionIdForReporting());
38             return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
39         }
40
41         throw new NetconfDocumentedException("Unable to unlock " + targetDatastore + " datastore", NetconfDocumentedException.ErrorType.application,
42                 NetconfDocumentedException.ErrorTag.operation_not_supported, NetconfDocumentedException.ErrorSeverity.error);
43     }
44
45     @Override
46     protected String getOperationName() {
47         return OPERATION_NAME;
48     }
49
50 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.