Turn SessionIdProvider into a component 98/104298/5
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Feb 2023 18:11:04 +0000 (19:11 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 8 Feb 2023 12:41:29 +0000 (12:41 +0000)
SessionIdProvider is a service, make sure it is an interface with a
default provider, instantiated via OSGi DS. This make things a tad more
reasonable, as the provider will survive most reconfiguration.

JIRA: NETCONF-951
Change-Id: I18e95bca90ed886d13b4cc03e3a2f1b5169d7876
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-impl/pom.xml
netconf/mdsal-netconf-impl/src/main/resources/OSGI-INF/blueprint/mdsal-netconf-impl.xml
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/NetconfDeviceSimulator.java
protocol/netconf-impl/pom.xml
protocol/netconf-impl/src/main/java/org/opendaylight/netconf/impl/DefaultSessionIdProvider.java [new file with mode: 0644]
protocol/netconf-impl/src/main/java/org/opendaylight/netconf/impl/SessionIdProvider.java
protocol/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java
protocol/netconf-impl/src/test/java/org/opendaylight/netconf/impl/NetconfDispatcherImplTest.java

index 6666a3c4765c7934c9fcfe89a3cd0cb2d381c2be..04796b77f5f75b9b7a6c503578507033b2c404e2 100644 (file)
       <groupId>${project.groupId}</groupId>
       <artifactId>netconf-impl</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
index 999294f0fbc2154373b4292c132196e104513eb4..f766af9d7ba2ef6b6bd9d342288b88daede62b48 100644 (file)
@@ -26,6 +26,8 @@
     <reference id="scheduledThreadPool"
                interface="org.opendaylight.controller.config.threadpool.ScheduledThreadPool"
                odl:type="global-netconf-ssh-scheduled-executor"/>
+    <reference id="sessionIdProvider"
+               interface="org.opendaylight.netconf.impl.SessionIdProvider"/>
 
     <cm:property-placeholder persistent-id="org.opendaylight.netconf.impl" update-strategy="none">
         <cm:default-properties>
@@ -47,9 +49,6 @@
 
     <!--NetconfServerDispatcher -->
 
-    <bean id="sessionIdProvider"
-          class="org.opendaylight.netconf.impl.SessionIdProvider"/>
-
     <bean id="aggregatedNetconfOperationServiceFactoryMappers"
           class="org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory"
           destroy-method="close">
index 0a92bc109ceee289be25725c20782bd7c35283a7..973426bc5c0f6e3c2a31e229fca126c8681863e3 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.netconf.api.capability.BasicCapability;
 import org.opendaylight.netconf.api.capability.Capability;
 import org.opendaylight.netconf.api.capability.YangModuleCapability;
 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
+import org.opendaylight.netconf.impl.DefaultSessionIdProvider;
 import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl;
 import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
 import org.opendaylight.netconf.impl.ServerChannelInitializer;
@@ -110,7 +111,7 @@ public class NetconfDeviceSimulator implements Closeable {
         }));
         transformedCapabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0"));
         final NetconfMonitoringService monitoringService1 = new DummyMonitoringService(transformedCapabilities);
-        final SessionIdProvider idProvider = new SessionIdProvider();
+        final SessionIdProvider idProvider = new DefaultSessionIdProvider();
 
         final NetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory = createOperationServiceFactory(
             sourceProvider, transformedCapabilities, monitoringService1, idProvider);
index 60d64c923ce22012e6da2a20dfe94316f374b937..a339ea8905c89b7b897541606eb0ee6cd02dd080 100644 (file)
   <packaging>bundle</packaging>
 
   <dependencies>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>threadpool-config-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.netconf.model</groupId>
       <artifactId>rfc6022</artifactId>
     </dependency>
-    <!-- compile dependencies -->
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>netconf-api</artifactId>
       <artifactId>netconf-util</artifactId>
     </dependency>
     <dependency>
-      <groupId>com.google.guava</groupId>
-      <artifactId>guava</artifactId>
+      <groupId>com.guicedee.services</groupId>
+      <artifactId>javax.inject</artifactId>
+      <optional>true</optional>
     </dependency>
     <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>threadpool-config-api</artifactId>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
     </dependency>
-    <!-- test dependencies -->
+
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>mockito-configuration</artifactId>
     </dependency>
-
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>netconf-client</artifactId>
@@ -81,7 +84,6 @@
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
-
     <dependency>
       <groupId>org.xmlunit</groupId>
       <artifactId>xmlunit-legacy</artifactId>
diff --git a/protocol/netconf-impl/src/main/java/org/opendaylight/netconf/impl/DefaultSessionIdProvider.java b/protocol/netconf-impl/src/main/java/org/opendaylight/netconf/impl/DefaultSessionIdProvider.java
new file mode 100644 (file)
index 0000000..ad0ddf8
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.impl;
+
+import java.util.concurrent.atomic.AtomicLong;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * Default {@link SessionIdProvider}. Counts sessions from the start of the component.
+ */
+@Singleton
+@Component(immediate = true, property = "type=default")
+public final class DefaultSessionIdProvider implements SessionIdProvider {
+    private final AtomicLong sessionCounter = new AtomicLong();
+
+    @Inject
+    public DefaultSessionIdProvider() {
+        // Nothing here
+    }
+
+    @Override
+    public long getNextSessionId() {
+        return sessionCounter.incrementAndGet();
+    }
+
+    @Override
+    public long getCurrentSessionId() {
+        return sessionCounter.get();
+    }
+}
index 3e2537d409002e640618a86a00d55abcffbdf86d..b9d4e0c8433db42005c7d4357616be65d3f80b8c 100644 (file)
@@ -5,20 +5,11 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.impl;
 
-import java.util.concurrent.atomic.AtomicLong;
-
-public final class SessionIdProvider {
-
-    private final AtomicLong sessionCounter = new AtomicLong(0);
+public interface SessionIdProvider {
 
-    public long getNextSessionId() {
-        return sessionCounter.incrementAndGet();
-    }
+    long getNextSessionId();
 
-    public long getCurrentSessionId() {
-        return sessionCounter.get();
-    }
+    long getCurrentSessionId();
 }
index 56d17b233a4416c233a40a429c132aa31752f87c..1b45cfaa5387028026a8eb9257958da5d790e576 100644 (file)
@@ -158,7 +158,7 @@ public class ConcurrentClientsTest {
         factoriesListener.onAddNetconfOperationServiceFactory(
                 new TestingOperationServiceFactory(testingNetconfOperation));
 
-        SessionIdProvider idProvider = new SessionIdProvider();
+        SessionIdProvider idProvider = new DefaultSessionIdProvider();
 
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new
                 NetconfServerSessionNegotiatorFactoryBuilder()
index 2a1540d7d19862f029b6312c43b3aa76464df530..af5ce49e1e3de3ba5d85ece2095ce3d6e0a301b3 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.impl;
 
 import io.netty.channel.ChannelFuture;
@@ -19,19 +18,17 @@ import org.junit.Test;
 import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
 
 public class NetconfDispatcherImplTest {
-
     private EventLoopGroup nettyGroup;
     private NetconfServerDispatcherImpl dispatch;
     private HashedWheelTimer hashedWheelTimer;
 
-
     @Before
     public void setUp() throws Exception {
         nettyGroup = new NioEventLoopGroup();
 
         AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory();
 
-        SessionIdProvider idProvider = new SessionIdProvider();
+        SessionIdProvider idProvider = new DefaultSessionIdProvider();
         hashedWheelTimer = new HashedWheelTimer();
 
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory =