2 * Copyright (c) 2013 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.controller.netconf.impl.mapping.operations;
11 import java.util.Collections;
13 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
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.XmlNetconfConstants;
17 import org.w3c.dom.Document;
18 import org.w3c.dom.Element;
20 public class DefaultCloseSession extends AbstractSingletonNetconfOperation {
21 public static final String CLOSE_SESSION = "close-session";
22 private final AutoCloseable sessionResources;
24 public DefaultCloseSession(String netconfSessionIdForReporting, AutoCloseable sessionResources) {
25 super(netconfSessionIdForReporting);
26 this.sessionResources = sessionResources;
30 protected String getOperationName() {
35 * Close netconf operation router associated to this session, which in turn
36 * closes NetconfOperationServiceSnapshot with all NetconfOperationService
40 protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement)
41 throws NetconfDocumentedException {
43 sessionResources.close();
44 } catch (Exception e) {
45 throw new NetconfDocumentedException("Unable to properly close session "
46 + getNetconfSessionIdForReporting(), NetconfDocumentedException.ErrorType.application,
47 NetconfDocumentedException.ErrorTag.operation_failed,
48 NetconfDocumentedException.ErrorSeverity.error, Collections.singletonMap(
49 NetconfDocumentedException.ErrorSeverity.error.toString(), e.getMessage()));
51 return document.createElement(XmlNetconfConstants.OK);