X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2Fmapping%2Foperations%2FDefaultCloseSession.java;h=8c7465b02961197e4a1bc5c836d10d00c0441be5;hp=1438515f040e41c547a8742010aec37b6ab2471b;hb=ecd49a2e11021576f51052ad54f785c9b0e65122;hpb=2e7347fdc0eb7734ff59a4f902227a93ab6afece 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..8c7465b029 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,28 @@ package org.opendaylight.controller.netconf.impl.mapping.operations; +import com.google.common.base.Optional; +import java.util.Collections; 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.api.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation; import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; -public class DefaultCloseSession extends AbstractNetconfOperation { +public class DefaultCloseSession extends AbstractSingletonNetconfOperation { public static final String CLOSE_SESSION = "close-session"; + private final AutoCloseable sessionResources; - public DefaultCloseSession(String netconfSessionIdForReporting) { + 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 +38,17 @@ public class DefaultCloseSession extends AbstractNetconfOperation { * instances */ @Override - protected Element handle(Document document, XmlElement operationElement, NetconfOperationRouter opRouter) + protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws NetconfDocumentedException { - opRouter.close(); - return document.createElement(XmlNetconfConstants.OK); + try { + sessionResources.close(); + } catch (Exception e) { + throw new NetconfDocumentedException("Unable to properly close session " + + getNetconfSessionIdForReporting(), NetconfDocumentedException.ErrorType.application, + NetconfDocumentedException.ErrorTag.operation_failed, + NetconfDocumentedException.ErrorSeverity.error, Collections.singletonMap( + NetconfDocumentedException.ErrorSeverity.error.toString(), e.getMessage())); + } + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); } }