Convert mdsal-netconf-tcp to OSGi DS 17/104317/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 16:59:44 +0000 (17:59 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 18:00:00 +0000 (19:00 +0100)
Create a disabled component instead using Declarative Services. This
enables it to be used without touching any code, just the SCR console.

JIRA: NETCONF-957
Change-Id: Id4fc561c3c8671de421b1410c3291390f87fbf56
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-tcp/pom.xml
netconf/mdsal-netconf-tcp/src/main/java/org/opendaylight/netconf/tcp/NetconfNorthboundTcpServer.java
netconf/mdsal-netconf-tcp/src/main/resources/OSGI-INF/blueprint/netconf-tcp.xml [deleted file]

index 4ea926baf4fe57cf9951f095b7fd5fb9c16691c7..7a3b899afea051d09d8f802aa579456c79ab97c1 100644 (file)
 
   <dependencies>
     <dependency>
-      <groupId>${project.groupId}</groupId>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-transport</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
+      <artifactId>rfc6991-ietf-inet-types</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.netconf</groupId>
       <artifactId>netconf-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.metatype.annotations</artifactId>
+    </dependency>
   </dependencies>
-
 </project>
index 423e65e14e5eb7ec988672c8269e7e84a03dbd3e..7e8a1d0fbea06e2eb8e4c320f460eee817c67a83 100644 (file)
@@ -8,26 +8,47 @@
 package org.opendaylight.netconf.tcp;
 
 import io.netty.channel.ChannelFuture;
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import org.opendaylight.netconf.api.NetconfServerDispatcher;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Create an MD-SAL NETCONF server using TCP.
  */
-public class NetconfNorthboundTcpServer implements AutoCloseable {
+@Component(service = { }, configurationPid = "org.opendaylight.netconf.tcp", enabled = false)
+@Designate(ocd = NetconfNorthboundTcpServer.Configuration.class)
+public final class NetconfNorthboundTcpServer implements AutoCloseable {
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition
+        String bindingAddress() default "0.0.0.0";
+        @AttributeDefinition(min = "1", max = "65535")
+        int portNumber() default 2831;
+    }
+
     private static final Logger LOG = LoggerFactory.getLogger(NetconfNorthboundTcpServer.class);
 
     private final ChannelFuture tcpServer;
 
-    public NetconfNorthboundTcpServer(final NetconfServerDispatcher netconfServerDispatcher, final String address,
-            final String port) {
+    @Activate
+    public NetconfNorthboundTcpServer(
+            @Reference(target = "(type=netconf-server-dispatcher)") final NetconfServerDispatcher serverDispatcher,
+            final Configuration configuration) {
+        this(serverDispatcher, configuration.bindingAddress(), configuration.portNumber());
+    }
+
+    public NetconfNorthboundTcpServer(final NetconfServerDispatcher serverDispatcher, final String address,
+            final int port) {
         final InetSocketAddress inetAddress = getInetAddress(address, port);
-        tcpServer = netconfServerDispatcher.createServer(inetAddress);
+        tcpServer = serverDispatcher.createServer(inetAddress);
         tcpServer.addListener(future -> {
             if (future.isDone() && future.isSuccess()) {
                 LOG.info("Netconf TCP endpoint started successfully at {}", inetAddress);
@@ -38,12 +59,6 @@ public class NetconfNorthboundTcpServer implements AutoCloseable {
         });
     }
 
-    private static InetSocketAddress getInetAddress(final String bindingAddress, final String portNumber) {
-        final IpAddress ipAddress = IetfInetUtil.ipAddressFor(bindingAddress);
-        final InetAddress inetAd = IetfInetUtil.INSTANCE.inetAddressFor(ipAddress);
-        return new InetSocketAddress(inetAd, Integer.parseInt(portNumber));
-    }
-
     @Override
     public void close() {
         if (tcpServer.isDone()) {
@@ -52,4 +67,9 @@ public class NetconfNorthboundTcpServer implements AutoCloseable {
             tcpServer.cancel(true);
         }
     }
+
+    private static InetSocketAddress getInetAddress(final String bindingAddress, final int portNumber) {
+        final var inetAd = IetfInetUtil.INSTANCE.inetAddressFor(IetfInetUtil.ipAddressFor(bindingAddress));
+        return new InetSocketAddress(inetAd, portNumber);
+    }
 }
diff --git a/netconf/mdsal-netconf-tcp/src/main/resources/OSGI-INF/blueprint/netconf-tcp.xml b/netconf/mdsal-netconf-tcp/src/main/resources/OSGI-INF/blueprint/netconf-tcp.xml
deleted file mode 100644 (file)
index b41b38b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2016 Inocybe Technologies Inc. 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
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.3.0"
-           odl:restart-dependents-on-updates="true">
-
-    <reference id="netconfServerDispatcher"
-               interface="org.opendaylight.netconf.api.NetconfServerDispatcher"
-               odl:type="netconf-server-dispatcher"/>
-
-    <!-- NETCONF TCP server for MD-SAL (listening by default on port 2831)-->
-
-    <cm:property-placeholder persistent-id="org.opendaylight.netconf.tcp" update-strategy="none">
-        <cm:default-properties>
-            <cm:property name="bindingAddress" value="0.0.0.0"/>
-            <cm:property name="portNumber" value="2831"/>
-        </cm:default-properties>
-    </cm:property-placeholder>
-
-    <!-- If you need/want to use a TCP NETCONF server to interact with MD-SAL, uncomment bellow bean -->
-
-    <!--
-    <bean id="netconfMdsalTcpServer"
-          class="org.opendaylight.netconf.tcp.NetconfNorthboundTcpServer"
-          destroy-method="close">
-        <argument ref="netconfServerDispatcher"/>
-        <argument value="${bindingAddress}"/>
-        <argument value="${portNumber}"/>
-    </bean>
-    -->
-
-</blueprint>
\ No newline at end of file