import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
+import org.opendaylight.controller.config.util.xml.DocumentedException;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
import org.opendaylight.controller.netconf.api.NetconfMessage;
import org.opendaylight.controller.netconf.api.NetconfSessionListener;
import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
-import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter;
import org.opendaylight.controller.netconf.util.messages.SendErrorExceptionUtil;
-import org.opendaylight.controller.netconf.util.xml.XmlElement;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
private final NetconfOperationRouter operationRouter;
private final AutoCloseable onSessionDownCloseable;
- public NetconfServerSessionListener(final NetconfOperationRouter operationRouter, NetconfMonitoringService monitoringService,
+ public NetconfServerSessionListener(final NetconfOperationRouter operationRouter, final NetconfMonitoringService monitoringService,
final AutoCloseable onSessionDownCloseable) {
this.operationRouter = operationRouter;
this.monitoringService = monitoringService;
@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
}
@Override
session);
LOG.debug("Responding with message {}", message);
session.sendMessage(message);
-
- if (isCloseSession(netconfMessage)) {
- closeNetconfSession(session);
- }
-
} catch (final RuntimeException e) {
// TODO: should send generic error or close session?
LOG.error("Unexpected exception", e);
session.onIncommingRpcFail();
throw new IllegalStateException("Unable to process incoming message " + netconfMessage, e);
- } catch (NetconfDocumentedException e) {
+ } catch (DocumentedException e) {
LOG.trace("Error occurred while processing message",e);
session.onOutgoingRpcError();
session.onIncommingRpcFail();
}
}
- private void closeNetconfSession(final NetconfServerSession session) {
- // destroy NetconfOperationService
- session.close();
- LOG.info("Session {} closed successfully", session.getSessionId());
- }
-
-
-
private NetconfMessage processDocument(final NetconfMessage netconfMessage, final NetconfServerSession session)
- throws NetconfDocumentedException {
+ throws DocumentedException {
final Document incomingDocument = netconfMessage.getDocument();
final Node rootNode = incomingDocument.getDocumentElement();
* unexpected element Description: An unexpected element is present.
*/
// TODO add message to error info
- throw new NetconfDocumentedException("Unknown tag " + rootNode.getNodeName(),
- NetconfDocumentedException.ErrorType.protocol, NetconfDocumentedException.ErrorTag.unknown_element,
- NetconfDocumentedException.ErrorSeverity.error, ImmutableMap.of("bad-element",
+ throw new DocumentedException("Unknown tag " + rootNode.getNodeName(),
+ DocumentedException.ErrorType.protocol, DocumentedException.ErrorTag.unknown_element,
+ DocumentedException.ErrorSeverity.error, ImmutableMap.of("bad-element",
rootNode.getNodeName()));
}
}
- private void checkMessageId(final Node rootNode) throws NetconfDocumentedException {
+ private static void checkMessageId(final Node rootNode) throws DocumentedException {
NamedNodeMap attributes = rootNode.getAttributes();
return;
}
- throw new NetconfDocumentedException("Missing attribute" + rootNode.getNodeName(),
- NetconfDocumentedException.ErrorType.protocol, NetconfDocumentedException.ErrorTag.missing_attribute,
- NetconfDocumentedException.ErrorSeverity.error,
- ImmutableMap.of(NetconfDocumentedException.ErrorTag.missing_attribute.toString(),
+ throw new DocumentedException("Missing attribute" + rootNode.getNodeName(),
+ DocumentedException.ErrorType.protocol, DocumentedException.ErrorTag.missing_attribute,
+ DocumentedException.ErrorSeverity.error,
+ ImmutableMap.of(DocumentedException.ErrorTag.missing_attribute.toString(),
XmlNetconfConstants.MESSAGE_ID));
}
-
- private static boolean isCloseSession(final NetconfMessage incomingDocument) {
- final Document document = incomingDocument.getDocument();
- XmlElement rpcElement = XmlElement.fromDomDocument(document);
- if (rpcElement.getOnlyChildElementOptionally(DefaultCloseSession.CLOSE_SESSION).isPresent()) {
- return true;
- }
-
- return false;
- }
}