import com.google.common.collect.ImmutableMap;
import org.opendaylight.controller.config.util.xml.DocumentedException;
import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.NetconfSessionListener;
import org.opendaylight.netconf.api.NetconfTerminationReason;
import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
+import org.opendaylight.netconf.api.monitoring.SessionEvent;
+import org.opendaylight.netconf.api.monitoring.SessionListener;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.impl.osgi.NetconfOperationRouter;
import org.opendaylight.netconf.util.messages.SubtreeFilter;
+import org.opendaylight.netconf.notifications.NetconfNotification;
+import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
public class NetconfServerSessionListener implements NetconfSessionListener<NetconfServerSession> {
private static final Logger LOG = LoggerFactory.getLogger(NetconfServerSessionListener.class);
- private final NetconfMonitoringService monitoringService;
+ private final SessionListener monitoringSessionListener;
private final NetconfOperationRouter operationRouter;
private final AutoCloseable onSessionDownCloseable;
public NetconfServerSessionListener(final NetconfOperationRouter operationRouter, final NetconfMonitoringService monitoringService,
final AutoCloseable onSessionDownCloseable) {
this.operationRouter = operationRouter;
- this.monitoringService = monitoringService;
+ this.monitoringSessionListener = monitoringService.getSessionListener();
this.onSessionDownCloseable = onSessionDownCloseable;
}
@Override
public void onSessionUp(final NetconfServerSession netconfNetconfServerSession) {
- monitoringService.onSessionUp(netconfNetconfServerSession);
- // FIXME monitoring service should be also notified about all the other changes to netconf session (from ietf-netconf-monitoring point of view)
- // This means also notifying after every message is processed
+ monitoringSessionListener.onSessionUp(netconfNetconfServerSession);
}
@Override
}
public void onDown(final NetconfServerSession netconfNetconfServerSession) {
- monitoringService.onSessionDown(netconfNetconfServerSession);
+ monitoringSessionListener.onSessionDown(netconfNetconfServerSession);
try {
operationRouter.close();
try {
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
+ // there is no validation since the document may contain yang schemas
final NetconfMessage message = processDocument(netconfMessage,
session);
LOG.debug("Responding with message {}", message);
session.sendMessage(message);
+ monitoringSessionListener.onSessionEvent(SessionEvent.inRpcSuccess(session));
} catch (final RuntimeException e) {
// TODO: should send generic error or close session?
LOG.error("Unexpected exception", e);
session.onIncommingRpcFail();
+ monitoringSessionListener.onSessionEvent(SessionEvent.inRpcFail(session));
throw new IllegalStateException("Unable to process incoming message " + netconfMessage, e);
} catch (DocumentedException e) {
LOG.trace("Error occurred while processing message",e);
session.onOutgoingRpcError();
session.onIncommingRpcFail();
+ monitoringSessionListener.onSessionEvent(SessionEvent.inRpcFail(session));
+ monitoringSessionListener.onSessionEvent(SessionEvent.outRpcError(session));
SendErrorExceptionUtil.sendErrorMessage(session, e, netconfMessage);
}
}
+ public void onNotification(final NetconfServerSession session, final NetconfNotification notification) {
+ monitoringSessionListener.onSessionEvent(SessionEvent.notification(session));
+ }
+
private NetconfMessage processDocument(final NetconfMessage netconfMessage, final NetconfServerSession session)
throws DocumentedException {