X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2Fmapping%2Foperations%2FDefaultCloseSession.java;h=3aa40b55a694dd3ac74d32d3ae5a462652b59e81;hb=refs%2Fchanges%2F13%2F23413%2F26;hp=1438515f040e41c547a8742010aec37b6ab2471b;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCloseSession.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCloseSession.java index 1438515f04..3aa40b55a6 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCloseSession.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCloseSession.java @@ -8,30 +8,36 @@ package org.opendaylight.controller.netconf.impl.mapping.operations; -import org.opendaylight.controller.netconf.api.NetconfDocumentedException; -import org.opendaylight.controller.netconf.api.NetconfOperationRouter; -import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; -import org.opendaylight.controller.netconf.util.mapping.AbstractNetconfOperation; -import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import java.util.Collections; +import org.opendaylight.controller.config.util.xml.DocumentedException; +import org.opendaylight.controller.config.util.xml.XmlElement; +import org.opendaylight.controller.config.util.xml.XmlUtil; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.impl.NetconfServerSession; +import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -public class DefaultCloseSession extends AbstractNetconfOperation { +public class DefaultCloseSession extends AbstractSingletonNetconfOperation implements DefaultNetconfOperation { + private static final Logger LOG = LoggerFactory.getLogger(DefaultCloseSession.class); + public static final String CLOSE_SESSION = "close-session"; - public DefaultCloseSession(String netconfSessionIdForReporting) { + private final AutoCloseable sessionResources; + private NetconfServerSession session; + + public DefaultCloseSession(String netconfSessionIdForReporting, AutoCloseable sessionResources) { super(netconfSessionIdForReporting); + this.sessionResources = sessionResources; } @Override - protected HandlingPriority canHandle(String operationName, String netconfOperationNamespace) { - if (operationName.equals(CLOSE_SESSION) == false) - return HandlingPriority.CANNOT_HANDLE; - if (netconfOperationNamespace.equals(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0) == false) - return HandlingPriority.CANNOT_HANDLE; - - return HandlingPriority.HANDLE_WITH_MAX_PRIORITY; + protected String getOperationName() { + return CLOSE_SESSION; } /** @@ -40,9 +46,24 @@ public class DefaultCloseSession extends AbstractNetconfOperation { * instances */ @Override - protected Element handle(Document document, XmlElement operationElement, NetconfOperationRouter opRouter) - throws NetconfDocumentedException { - opRouter.close(); - return document.createElement(XmlNetconfConstants.OK); + protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) + throws DocumentedException { + try { + sessionResources.close(); + Preconditions.checkNotNull(session, "Session was not set").delayedClose(); + LOG.info("Session {} closing", session.getSessionId()); + } catch (Exception e) { + throw new DocumentedException("Unable to properly close session " + + getNetconfSessionIdForReporting(), DocumentedException.ErrorType.application, + DocumentedException.ErrorTag.operation_failed, + DocumentedException.ErrorSeverity.error, Collections.singletonMap( + DocumentedException.ErrorSeverity.error.toString(), e.getMessage())); + } + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); + } + + @Override + public void setNetconfSession(final NetconfServerSession s) { + this.session = s; } }