2 * Copyright (c) 2014 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
9 package org.opendaylight.netconf.confignetconfconnector.operations;
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.config.facade.xml.Datastore;
13 import org.opendaylight.controller.config.util.xml.DocumentedException;
14 import org.opendaylight.controller.config.util.xml.XmlElement;
15 import org.opendaylight.controller.config.util.xml.XmlUtil;
16 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
17 import org.opendaylight.netconf.util.mapping.AbstractLastNetconfOperation;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.w3c.dom.Document;
21 import org.w3c.dom.Element;
24 * Simple unlock implementation that pretends to unlock candidate datastore.
25 * Candidate datastore is allocated per session and is private so no real locking is needed
26 * (JMX is the only possible interference)
28 public class UnLock extends AbstractLastNetconfOperation {
30 private static final Logger LOG = LoggerFactory.getLogger(UnLock.class);
32 private static final String UNLOCK = "unlock";
34 public UnLock(final String netconfSessionIdForReporting) {
35 super(netconfSessionIdForReporting);
39 protected Element handleWithNoSubsequentOperations(final Document document,
40 final XmlElement operationElement) throws DocumentedException {
41 final Datastore targetDatastore = Lock.extractTargetParameter(operationElement);
42 if (targetDatastore == Datastore.candidate) {
43 // Since candidate datastore instances are allocated per session and not accessible anywhere else,
45 LOG.debug("Unlocking {} datastore on session: {}", targetDatastore, getNetconfSessionIdForReporting());
46 // TODO this should fail if we are not locked
47 return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent());
50 // Not supported running lock
51 throw new DocumentedException("Unable to unlock " + Datastore.running + " datastore",
52 DocumentedException.ErrorType.APPLICATION,
53 DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, DocumentedException.ErrorSeverity.ERROR);
57 protected String getOperationName() {