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 com.google.common.base.Preconditions;
13 import java.util.Collections;
14 import org.opendaylight.controller.config.util.xml.DocumentedException;
15 import org.opendaylight.controller.config.util.xml.XmlElement;
16 import org.opendaylight.controller.config.util.xml.XmlUtil;
17 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
18 import org.opendaylight.controller.netconf.impl.NetconfServerSession;
19 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.w3c.dom.Document;
23 import org.w3c.dom.Element;
25 public class DefaultCloseSession extends AbstractSingletonNetconfOperation implements DefaultNetconfOperation {
26 private static final Logger LOG = LoggerFactory.getLogger(DefaultCloseSession.class);
28 public static final String CLOSE_SESSION = "close-session";
30 private final AutoCloseable sessionResources;
31 private NetconfServerSession session;
33 public DefaultCloseSession(String netconfSessionIdForReporting, AutoCloseable sessionResources) {
34 super(netconfSessionIdForReporting);
35 this.sessionResources = sessionResources;
39 protected String getOperationName() {
44 * Close netconf operation router associated to this session, which in turn
45 * closes NetconfOperationServiceSnapshot with all NetconfOperationService
49 protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement)
50 throws DocumentedException {
52 sessionResources.close();
53 Preconditions.checkNotNull(session, "Session was not set").delayedClose();
54 LOG.info("Session {} closing", session.getSessionId());
55 } catch (Exception e) {
56 throw new DocumentedException("Unable to properly close session "
57 + getNetconfSessionIdForReporting(), DocumentedException.ErrorType.application,
58 DocumentedException.ErrorTag.operation_failed,
59 DocumentedException.ErrorSeverity.error, Collections.singletonMap(
60 DocumentedException.ErrorSeverity.error.toString(), e.getMessage()));
62 return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
66 public void setNetconfSession(final NetconfServerSession s) {