Remove dependency on Exificient due to licensing incompatibility
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / NetconfServerSessionListener.java
index 4f71ab9bb55f207f72418338e49b4b4d7c1cfe02..43e55d746a4ee59d1ec9bb35245f74e0edbca018 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 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;
@@ -31,21 +32,25 @@ public class NetconfServerSessionListener implements
 
     static final Logger logger = LoggerFactory.getLogger(NetconfServerSessionListener.class);
     public static final String MESSAGE_ID = "message-id";
+    private final SessionMonitoringService monitoringService;
 
     private NetconfOperationRouterImpl operationRouter;
 
-    public NetconfServerSessionListener(NetconfOperationRouterImpl operationRouter) {
+    public NetconfServerSessionListener(NetconfOperationRouterImpl operationRouter,
+                                        SessionMonitoringService monitoringService) {
         this.operationRouter = operationRouter;
+        this.monitoringService = monitoringService;
     }
 
     @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());
+        monitoringService.onSessionDown(netconfNetconfServerSession);
 
         operationRouter.close();
     }
@@ -55,6 +60,7 @@ public class NetconfServerSessionListener implements
             NetconfTerminationReason netconfTerminationReason) {
         logger.debug("Session {} terminated, reason: {}", netconfNetconfServerSession,
                 netconfTerminationReason.getErrorMessage());
+        monitoringService.onSessionDown(netconfNetconfServerSession);
 
         operationRouter.close();
     }
@@ -66,8 +72,9 @@ public class NetconfServerSessionListener implements
             Preconditions.checkState(operationRouter != null, "Cannot handle message, session up was not yet received");
             // FIXME: there is no validation since the document may contain yang
             // schemas
-            final NetconfMessage message = processDocument(netconfMessage);
-            logger.debug("Respondign with message {}", XmlUtil.toString(message.getDocument()));
+            final NetconfMessage message = processDocument(netconfMessage,
+                    session);
+            logger.debug("Responding with message {}", XmlUtil.toString(message.getDocument()));
             session.sendMessage(message);
 
             if (isCloseSession(netconfMessage)) {
@@ -75,10 +82,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);
         }
     }
@@ -89,16 +99,21 @@ public class NetconfServerSessionListener implements
         logger.info("Session {} closed successfully", session.getSessionId());
     }
 
-    private NetconfMessage processDocument(final NetconfMessage netconfMessage) throws NetconfDocumentedException {
+    private NetconfMessage processDocument(final NetconfMessage netconfMessage,
+            NetconfServerSession session) throws NetconfDocumentedException {
 
         final Document incommingDocument = netconfMessage.getDocument();
         final Node rootNode = incommingDocument.getDocumentElement();
 
-        if (rootNode.getNodeName().equals(XmlNetconfConstants.RPC_KEY)) {
+        if (rootNode.getLocalName().equals(XmlNetconfConstants.RPC_KEY)) {
             final String messageId = rootNode.getAttributes().getNamedItem(MESSAGE_ID).getTextContent();
             checkState(messageId != null);
             final Document responseDocument = XmlUtil.newDocument();
-            Document rpcReply = operationRouter.onNetconfMessage(incommingDocument);
+            Document rpcReply = operationRouter.onNetconfMessage(
+                    incommingDocument, session);
+
+            session.onIncommingRpcSuccess();
+
             responseDocument.appendChild(responseDocument.importNode(rpcReply.getDocumentElement(), true));
             return new NetconfMessage(responseDocument);
         } else {