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 org.opendaylight.controller.netconf.api.NetconfDocumentedException;
12 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
13 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
14 import org.opendaylight.controller.netconf.util.xml.XmlElement;
15 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
19 import com.google.common.base.Optional;
21 import java.util.Collections;
23 public class DefaultCloseSession extends AbstractSingletonNetconfOperation {
24 public static final String CLOSE_SESSION = "close-session";
25 private final AutoCloseable sessionResources;
27 public DefaultCloseSession(String netconfSessionIdForReporting, AutoCloseable sessionResources) {
28 super(netconfSessionIdForReporting);
29 this.sessionResources = sessionResources;
33 protected String getOperationName() {
38 * Close netconf operation router associated to this session, which in turn
39 * closes NetconfOperationServiceSnapshot with all NetconfOperationService
43 protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement)
44 throws NetconfDocumentedException {
46 sessionResources.close();
47 } catch (Exception e) {
48 throw new NetconfDocumentedException("Unable to properly close session "
49 + getNetconfSessionIdForReporting(), NetconfDocumentedException.ErrorType.application,
50 NetconfDocumentedException.ErrorTag.operation_failed,
51 NetconfDocumentedException.ErrorSeverity.error, Collections.singletonMap(
52 NetconfDocumentedException.ErrorSeverity.error.toString(), e.getMessage()));
54 return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());