X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2FNetconfServerSessionNegotiatorFactory.java;h=9ffb8da1dd975fc6592e2b789e49e7f5492e0069;hb=1745f92957146128e8a4a111adb7ed830f737e0a;hp=8086b748d7e07e5c7d09bf29754847bf9d1526fd;hpb=38500d0f0e22f84bf31618d8b5e9aab37fdb897c;p=controller.git diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java index 8086b748d7..9ffb8da1dd 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java @@ -17,11 +17,13 @@ import java.io.InputStream; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; -import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences; import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener; +import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; import org.opendaylight.controller.netconf.util.NetconfUtil; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; import org.opendaylight.controller.netconf.util.xml.XMLNetconfUtil; import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.util.xml.XmlUtil; @@ -32,9 +34,12 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; -public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory { +import static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting; + +public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory { public static final String SERVER_HELLO_XML_LOCATION = "/server_hello.xml"; @@ -42,15 +47,20 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF private static final Document helloMessageTemplate = loadHelloMessageTemplate(); private final SessionIdProvider idProvider; - private final NetconfOperationServiceFactoryListener factoriesListener; + private final NetconfOperationProvider netconfOperationProvider; private final long connectionTimeoutMillis; + private final DefaultCommitNotificationProducer commitNotificationProducer; + private final SessionMonitoringService monitoringService; - public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationServiceFactoryListener factoriesListener, - SessionIdProvider idProvider, long connectionTimeoutMillis) { + public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationProvider netconfOperationProvider, + SessionIdProvider idProvider, long connectionTimeoutMillis, + DefaultCommitNotificationProducer commitNot, SessionMonitoringService monitoringService) { this.timer = timer; - this.factoriesListener = factoriesListener; + this.netconfOperationProvider = netconfOperationProvider; this.idProvider = idProvider; this.connectionTimeoutMillis = connectionTimeoutMillis; + this.commitNotificationProducer = commitNot; + this.monitoringService = monitoringService; } private static Document loadHelloMessageTemplate() { @@ -61,13 +71,30 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF return NetconfUtil.createMessage(resourceAsStream).getDocument(); } + /** + * + * @param defunctSessionListenerFactory will not be taken into account as session listener factory can + * only be created after snapshot is opened, thus this method constructs + * proper session listener factory. + * @param channel Underlying channel + * @param promise Promise to be notified + * @return session negotiator + */ @Override - public SessionNegotiator getSessionNegotiator(SessionListenerFactory sessionListenerFactory, Channel channel, - Promise promise) { + public SessionNegotiator getSessionNegotiator(SessionListenerFactory defunctSessionListenerFactory, + Channel channel, Promise promise) { long sessionId = idProvider.getNextSessionId(); + NetconfOperationServiceSnapshot netconfOperationServiceSnapshot = netconfOperationProvider.openSnapshot( + getNetconfSessionIdForReporting(sessionId)); + CapabilityProvider capabilityProvider = new CapabilityProviderImpl(netconfOperationServiceSnapshot); + + NetconfServerSessionPreferences proposal = new NetconfServerSessionPreferences( + createHelloMessage(sessionId, capabilityProvider), sessionId); + + NetconfServerSessionListenerFactory sessionListenerFactory = new NetconfServerSessionListenerFactory( + commitNotificationProducer, monitoringService, + netconfOperationServiceSnapshot, capabilityProvider); - NetconfServerSessionPreferences proposal = new NetconfServerSessionPreferences(createHelloMessage(sessionId), - sessionId); return new NetconfServerSessionNegotiator(proposal, promise, channel, timer, sessionListenerFactory.getSessionListener(), connectionTimeoutMillis); } @@ -77,7 +104,7 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF private static final XPathExpression capabilitiesXPath = XMLNetconfUtil .compileXPath("/netconf:hello/netconf:capabilities"); - private NetconfMessage createHelloMessage(long sessionId) { + private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) { Document helloMessageTemplate = getHelloTemplateClone(); // change session ID @@ -89,14 +116,12 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF final Element capabilitiesElement = (Element) XmlUtil.evaluateXPath(capabilitiesXPath, helloMessageTemplate, XPathConstants.NODE); - CapabilityProvider capabilityProvider = new CapabilityProviderImpl(factoriesListener.getSnapshot(sessionId)); - for (String capability : capabilityProvider.getCapabilities()) { - final Element capabilityElement = helloMessageTemplate.createElement(XmlNetconfConstants.CAPABILITY); + final Element capabilityElement = XmlUtil.createElement(helloMessageTemplate, XmlNetconfConstants.CAPABILITY, Optional.absent()); capabilityElement.setTextContent(capability); capabilitiesElement.appendChild(capabilityElement); } - return new NetconfMessage(helloMessageTemplate); + return new NetconfHelloMessage(helloMessageTemplate); } private synchronized Document getHelloTemplateClone() {