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