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%2FNetconfServerSessionListener.java;h=86cfac0b606537973ab1bdeb32bcbad3d23aba7a;hp=686adcad8550a3401809235cc0bda6e660782738;hb=90eec30ff127328e9945a097eb251b7afa54b93c;hpb=a8a5f3741b19fba443c0ee6bf0df663bf43ee034 diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java index 686adcad85..86cfac0b60 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java @@ -8,48 +8,64 @@ package org.opendaylight.controller.netconf.impl; -import static com.google.common.base.Preconditions.checkState; - +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.api.NetconfSession; +import org.opendaylight.controller.netconf.api.NetconfOperationRouter; +import org.opendaylight.controller.netconf.api.NetconfSessionListener; import org.opendaylight.controller.netconf.api.NetconfTerminationReason; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouterImpl; +import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; import org.opendaylight.controller.netconf.util.messages.SendErrorExceptionUtil; 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.opendaylight.protocol.framework.SessionListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; - -public class NetconfServerSessionListener implements - SessionListener { +import static com.google.common.base.Preconditions.checkState; - static final Logger logger = LoggerFactory.getLogger(NetconfServerSessionListener.class); +public class NetconfServerSessionListener implements NetconfSessionListener { public static final String MESSAGE_ID = "message-id"; - private NetconfOperationRouterImpl operationRouter; + static final Logger logger = LoggerFactory.getLogger(NetconfServerSessionListener.class); + private final SessionMonitoringService monitoringService; + private final NetconfOperationRouter operationRouter; + private final AutoCloseable onSessionDownCloseable; - public NetconfServerSessionListener(NetconfOperationRouterImpl operationRouter) { + public NetconfServerSessionListener(NetconfOperationRouter operationRouter, SessionMonitoringService monitoringService, + AutoCloseable onSessionDownCloseable) { this.operationRouter = operationRouter; + this.monitoringService = monitoringService; + this.onSessionDownCloseable = onSessionDownCloseable; } @Override public void onSessionUp(NetconfServerSession netconfNetconfServerSession) { - + monitoringService.onSessionUp(netconfNetconfServerSession); } @Override - public void onSessionDown(NetconfServerSession netconfNetconfServerSession, Exception e) { - logger.debug("Session {} down, reason: {}", netconfNetconfServerSession, e.getMessage()); + public void onSessionDown(NetconfServerSession netconfNetconfServerSession, Exception cause) { + logger.debug("Session {} down, reason: {}", netconfNetconfServerSession, cause.getMessage()); + onDown(netconfNetconfServerSession); + } + + public void onDown(NetconfServerSession netconfNetconfServerSession) { + monitoringService.onSessionDown(netconfNetconfServerSession); - operationRouter.close(); + try { + operationRouter.close(); + } catch (Exception closingEx) { + logger.debug("Ignoring exception while closing operationRouter", closingEx); + } + try { + onSessionDownCloseable.close(); + } catch(Exception ex){ + logger.debug("Ignoring exception while closing onSessionDownCloseable", ex); + } } @Override @@ -57,8 +73,7 @@ public class NetconfServerSessionListener implements NetconfTerminationReason netconfTerminationReason) { logger.debug("Session {} terminated, reason: {}", netconfNetconfServerSession, netconfTerminationReason.getErrorMessage()); - - operationRouter.close(); + onDown(netconfNetconfServerSession); } @Override @@ -70,7 +85,7 @@ public class NetconfServerSessionListener implements // schemas final NetconfMessage message = processDocument(netconfMessage, session); - logger.debug("Respondign with message {}", XmlUtil.toString(message.getDocument())); + logger.debug("Responding with message {}", XmlUtil.toString(message.getDocument())); session.sendMessage(message); if (isCloseSession(netconfMessage)) { @@ -78,10 +93,13 @@ public class NetconfServerSessionListener implements } } catch (final RuntimeException e) { - logger.error("Unexpected exception", e); // TODO: should send generic error or close session? + logger.error("Unexpected exception", e); + session.onIncommingRpcFail(); throw new RuntimeException("Unable to process incoming message " + netconfMessage, e); } catch (NetconfDocumentedException e) { + session.onOutgoingRpcError(); + session.onIncommingRpcFail(); SendErrorExceptionUtil.sendErrorMessage(session, e, netconfMessage); } } @@ -93,7 +111,7 @@ public class NetconfServerSessionListener implements } private NetconfMessage processDocument(final NetconfMessage netconfMessage, - NetconfSession session) throws NetconfDocumentedException { + NetconfServerSession session) throws NetconfDocumentedException { final Document incommingDocument = netconfMessage.getDocument(); final Node rootNode = incommingDocument.getDocumentElement(); @@ -104,6 +122,9 @@ public class NetconfServerSessionListener implements final Document responseDocument = XmlUtil.newDocument(); Document rpcReply = operationRouter.onNetconfMessage( incommingDocument, session); + + session.onIncommingRpcSuccess(); + responseDocument.appendChild(responseDocument.importNode(rpcReply.getDocumentElement(), true)); return new NetconfMessage(responseDocument); } else {