Convert OvsdbConnectionService into a Component 08/104408/10
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 15 Feb 2023 15:54:54 +0000 (16:54 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 24 Jan 2024 12:28:42 +0000 (13:28 +0100)
This is a rather simple component, but it is was convoluted by previous
attempts to have blueprint auto-generated. Convert it to Declarative
Services and ditch blueprint.

Since we are using ICertificateManager, which is satisfied via Blueprint
by aaa-cert, we need to also suppress generation of requirements.

JIRA: OVSDB-468
Change-Id: I47a5acd22314601672a04f76bf0686fbfdc90b55
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
library/impl/pom.xml
library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionServiceConfigurator.java [deleted file]
library/impl/src/main/resources/OSGI-INF/blueprint/library.xml [deleted file]
library/impl/src/main/resources/initial/library.cfg

index 04ff77e9f8eca95dcb0c1091d31f9907c2f898a6..538ce7f67d8e0726ad55b828c29fa38f6af2bc04 100644 (file)
@@ -106,6 +106,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <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>
 
     <!-- Testing Dependencies -->
     <dependency>
@@ -145,6 +149,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
               org.opendaylight.ovsdb.lib.*,
               org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.library.impl.rev141210
             </Export-Package>
+
+            <!-- FIXME: AAA-268: remove this instruction once aaa-cert exposes Provide-Capability -->
+            <_dsannotations-options>norequirements</_dsannotations-options>
           </instructions>
         </configuration>
       </plugin>
index e5d5210fc5eb085a525c8d45528fb6d911d88201..d2179a6b05164e608c91982a1c1d5bacb690e0ca 100644 (file)
@@ -54,6 +54,12 @@ import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
 import org.opendaylight.ovsdb.lib.jsonrpc.ExceptionHandler;
 import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcDecoder;
 import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcEndpoint;
+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;
 
@@ -74,7 +80,23 @@ import org.slf4j.LoggerFactory;
  * and a Singleton object in a non-OSGi environment.
  */
 @Singleton
+@Component(service = OvsdbConnection.class, configurationPid = "org.opendaylight.ovsdb.library")
+@Designate(ocd = OvsdbConnectionService.Configuration.class)
 public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
+    @ObjectClassDefinition
+    public @interface Configuration {
+        @AttributeDefinition
+        String ovsdb$_$listener$_$ip() default DEFAULT_LISTENER_IP;
+        @AttributeDefinition(min = "1", max = "65535")
+        int ovsdb$_$listener$_$port() default DEFAULT_LISTENER_PORT;
+        @AttributeDefinition
+        int ovsdb$_$rpc$_$task$_$timeout() default DEFAULT_RPC_TASK_TIMEOUT;
+        @AttributeDefinition
+        boolean use$_$ssl() default false;
+        @AttributeDefinition
+        int json$_$rpc$_$decoder$_$max$_$frame$_$length() default DEFAULT_JSON_RPC_DECODER_MAX_FRAME_LENGTH;
+    }
+
     private class ClientChannelInitializer extends ChannelInitializer<SocketChannel> {
         @Override
         public void initChannel(final SocketChannel channel) throws Exception {
@@ -180,9 +202,11 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionService.class);
     private static final int IDLE_READER_TIMEOUT = 30;
     private static final int READ_TIMEOUT = 180;
-    private static final String OVSDB_RPC_TASK_TIMEOUT_PARAM = "ovsdb-rpc-task-timeout";
-    private static final String USE_SSL = "use-ssl";
     private static final int RETRY_PERIOD = 100; // retry after 100 milliseconds
+    private static final String DEFAULT_LISTENER_IP = "0.0.0.0";
+    private static final int DEFAULT_LISTENER_PORT = 6640;
+    private static final int DEFAULT_RPC_TASK_TIMEOUT = 1000;
+    private static final int DEFAULT_JSON_RPC_DECODER_MAX_FRAME_LENGTH = 100000;
 
     private static final StringEncoder UTF8_ENCODER = new StringEncoder(StandardCharsets.UTF_8);
 
@@ -198,26 +222,53 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                 return null;
             });
 
+    // FIXME: these should not be static
     private static final Set<OvsdbConnectionListener> CONNECTION_LISTENERS = ConcurrentHashMap.newKeySet();
     private static final Map<OvsdbClient, Channel> CONNECTIONS = new ConcurrentHashMap<>();
 
     private final NettyBootstrapFactory bootstrapFactory;
-
-    private volatile boolean useSSL = false;
     private final ICertificateManager certManagerSrv;
 
-    private volatile int jsonRpcDecoderMaxFrameLength = 100000;
-    private volatile Channel serverChannel;
+    private final boolean useSSL;
+    private final int jsonRpcDecoderMaxFrameLength;
 
     private final AtomicBoolean singletonCreated = new AtomicBoolean(false);
-    private volatile String listenerIp = "0.0.0.0";
-    private volatile int listenerPort = 6640;
+    private volatile Channel serverChannel;
+
+    private final String listenerIp;
+    private final int listenerPort;
 
     @Inject
     public OvsdbConnectionService(final NettyBootstrapFactory bootstrapFactory,
             final ICertificateManager certManagerSrv) {
+        this(bootstrapFactory, certManagerSrv, DEFAULT_LISTENER_IP, DEFAULT_LISTENER_PORT, DEFAULT_RPC_TASK_TIMEOUT,
+            false, DEFAULT_JSON_RPC_DECODER_MAX_FRAME_LENGTH);
+    }
+
+    @Activate
+    public OvsdbConnectionService(@Reference final NettyBootstrapFactory bootstrapFactory,
+            @Reference(target = "(type=default-certificate-manager)") final ICertificateManager certManagerSrv,
+            final Configuration configuration) {
+        this(bootstrapFactory, certManagerSrv, configuration.ovsdb$_$listener$_$ip(),
+            configuration.ovsdb$_$listener$_$port(), configuration.ovsdb$_$rpc$_$task$_$timeout(),
+            configuration.use$_$ssl(), configuration.json$_$rpc$_$decoder$_$max$_$frame$_$length());
+    }
+
+    public OvsdbConnectionService(final NettyBootstrapFactory bootstrapFactory,
+            final ICertificateManager certManagerSrv, final String listenerIp, final int listenerPort,
+            final int ovsdbRpcTaskTimeout, final boolean useSSL, final int jsonRpcDecoderMaxFrameLength) {
         this.bootstrapFactory = requireNonNull(bootstrapFactory);
-        this.certManagerSrv = certManagerSrv;
+        this.certManagerSrv = requireNonNull(certManagerSrv);
+        this.listenerIp = requireNonNull(listenerIp);
+        this.listenerPort = listenerPort;
+        this.useSSL = useSSL;
+        this.jsonRpcDecoderMaxFrameLength = jsonRpcDecoderMaxFrameLength;
+
+        // FIXME: static state!
+        JsonRpcEndpoint.setReaperInterval(ovsdbRpcTaskTimeout);
+        LOG.info("OVSDB IP for listening connection is set to : {}", listenerIp);
+        LOG.info("OVSDB port for listening connection is set to : {}", listenerPort);
+        LOG.info("Json Rpc Decoder Max Frame Length set to : {}", jsonRpcDecoderMaxFrameLength);
     }
 
     /**
@@ -385,7 +436,6 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
      * OVSDB Passive listening thread that uses Netty ServerBootstrap to open
      * passive connection with Ssl and handle channel callbacks.
      */
-    @SuppressWarnings("checkstyle:IllegalCatch")
     private void ovsdbManagerWithSsl(final String ip, final int port, final ServerChannelInitializer channelHandler) {
         bootstrapFactory.newServer()
             .handler(new LoggingHandler(LogLevel.INFO))
@@ -583,52 +633,4 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
             });
         }
     }
-
-    public void setOvsdbRpcTaskTimeout(final int timeout) {
-        JsonRpcEndpoint.setReaperInterval(timeout);
-    }
-
-    /**
-     * Set useSSL flag.
-     *
-     * @param flag boolean for using ssl
-     */
-    public void setUseSsl(final boolean flag) {
-        useSSL = flag;
-    }
-
-    /**
-     * Blueprint property setter method. Blueprint call this method and set the value of json rpc decoder
-     * max frame length to the value configured for config option (json-rpc-decoder-max-frame-length) in
-     * the configuration file. This option is only configured at the  boot time of the controller. Any
-     * change at the run time will have no impact.
-     * @param maxFrameLength Max frame length (default : 100000)
-     */
-    public void setJsonRpcDecoderMaxFrameLength(final int maxFrameLength) {
-        jsonRpcDecoderMaxFrameLength = maxFrameLength;
-        LOG.info("Json Rpc Decoder Max Frame Length set to : {}", jsonRpcDecoderMaxFrameLength);
-    }
-
-    public void setOvsdbListenerIp(final String ip) {
-        LOG.info("OVSDB IP for listening connection is set to : {}", ip);
-        listenerIp = ip;
-    }
-
-    public void setOvsdbListenerPort(final int portNumber) {
-        LOG.info("OVSDB port for listening connection is set to : {}", portNumber);
-        listenerPort = portNumber;
-    }
-
-    public void updateConfigParameter(final Map<String, Object> configParameters) {
-        if (configParameters != null && !configParameters.isEmpty()) {
-            LOG.debug("Config parameters received : {}", configParameters.entrySet());
-            for (Map.Entry<String, Object> paramEntry : configParameters.entrySet()) {
-                if (paramEntry.getKey().equalsIgnoreCase(OVSDB_RPC_TASK_TIMEOUT_PARAM)) {
-                    setOvsdbRpcTaskTimeout(Integer.parseInt((String)paramEntry.getValue()));
-                } else if (paramEntry.getKey().equalsIgnoreCase(USE_SSL)) {
-                    useSSL = Boolean.parseBoolean(paramEntry.getValue().toString());
-                }
-            }
-        }
-    }
 }
diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionServiceConfigurator.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionServiceConfigurator.java
deleted file mode 100644 (file)
index 55835ad..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright © 2014, 2017 Red Hat, 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
- */
-
-package org.opendaylight.ovsdb.lib.impl;
-
-import java.util.Map;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class OvsdbConnectionServiceConfigurator {
-
-    private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionServiceConfigurator.class);
-
-    private static final String JSON_RPC_DECODER_MAX_FRAME_LENGTH_PARAM = "json-rpc-decoder-max-frame-length";
-    private static final String USE_SSL_PARAM = "use-ssl";
-    private static final String OVSDB_RPC_TASK_TIMEOUT_PARAM = "ovsdb-rpc-task-timeout";
-    private static final String OVSDB_LISTENER_PORT_PARAM = "ovsdb-listener-port";
-    private final OvsdbConnectionService ovsdbconnection;
-
-    public OvsdbConnectionServiceConfigurator(OvsdbConnectionService ovsdbconnection) {
-        this.ovsdbconnection = ovsdbconnection;
-    }
-
-    public void setOvsdbRpcTaskTimeout(int timeout) {
-        ovsdbconnection.setOvsdbRpcTaskTimeout(timeout);
-    }
-
-    public void setUseSsl(boolean flag) {
-        ovsdbconnection.setUseSsl(flag);
-    }
-
-    public void setJsonRpcDecoderMaxFrameLength(int maxFrameLength) {
-        ovsdbconnection.setJsonRpcDecoderMaxFrameLength(maxFrameLength);
-    }
-
-    public void setOvsdbListenerIp(String ip) {
-        ovsdbconnection.setOvsdbListenerIp(ip);
-    }
-
-    public void setOvsdbListenerPort(int portNumber) {
-        ovsdbconnection.setOvsdbListenerPort(portNumber);
-    }
-
-    public void updateConfigParameter(Map<String, Object> configParameters) {
-        if (configParameters != null && !configParameters.isEmpty()) {
-            LOG.debug("Config parameters received : {}", configParameters.entrySet());
-            for (Map.Entry<String, Object> paramEntry : configParameters.entrySet()) {
-                if (paramEntry.getKey().equalsIgnoreCase(OVSDB_RPC_TASK_TIMEOUT_PARAM)) {
-                    ovsdbconnection.setOvsdbRpcTaskTimeout(Integer.parseInt((String) paramEntry.getValue()));
-                } else if (paramEntry.getKey().equalsIgnoreCase(USE_SSL_PARAM)) {
-                    ovsdbconnection.setUseSsl(Boolean.parseBoolean(paramEntry.getValue().toString()));
-                }
-
-            }
-        }
-    }
-}
-
diff --git a/library/impl/src/main/resources/OSGI-INF/blueprint/library.xml b/library/impl/src/main/resources/OSGI-INF/blueprint/library.xml
deleted file mode 100644 (file)
index 9a955e7..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
-
-  <!-- Read default values at startup and inject to OvsdbConnectionService-->
-  <cm:property-placeholder persistent-id="org.opendaylight.ovsdb.library" update-strategy="none">
-    <!-- Setting default values, in case library.cfg file is not present
-    or config property is commented out. This will be overridden if user
-    specify the property in library.cfg file-->
-    <cm:default-properties>
-      <cm:property name="ovsdb-listener-ip" value="0.0.0.0"/>
-      <cm:property name="ovsdb-listener-port" value="6640"/>
-      <cm:property name="ovsdb-rpc-task-timeout" value="1000"/>
-      <cm:property name="use-ssl" value="false"/>
-      <cm:property name="json-rpc-decoder-max-frame-length" value="100000"/>
-    </cm:default-properties>
-  </cm:property-placeholder>
-
-  <!-- Notify OvsdbConnectionService with any change in the config properties value-->
-  <bean id="ovsdbConnectionServiceConfigurator" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionServiceConfigurator">
-    <argument ref="ovsdbConnectionService"/>
-    <cm:managed-properties persistent-id="org.opendaylight.ovsdb.library"
-                           update-strategy="component-managed"
-                           update-method="updateConfigParameter"/>
-    <property name="ovsdbListenerIp" value="${ovsdb-listener-ip}"/>
-    <property name="ovsdbListenerPort" value="${ovsdb-listener-port}"/>
-    <property name="ovsdbRpcTaskTimeout" value="${ovsdb-rpc-task-timeout}"/>
-    <property name="useSsl" value="${use-ssl}"/>
-    <property name="jsonRpcDecoderMaxFrameLength" value="${json-rpc-decoder-max-frame-length}"/>
-  </bean>
-
-  <reference id="certificateManager" interface="org.opendaylight.aaa.cert.api.ICertificateManager"
-             filter="type=default-certificate-manager"/>
-  <reference id="nettyBootstrapFactory" interface="org.opendaylight.ovsdb.lib.impl.NettyBootstrapFactory"/>
-
-  <bean id="ovsdbConnectionService" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService">
-    <argument ref="nettyBootstrapFactory"/>
-    <argument ref="certificateManager"/>
-  </bean>
-
-  <service ref="ovsdbConnectionService" interface="org.opendaylight.ovsdb.lib.OvsdbConnection"/>
-</blueprint>
index fce90c040ed6b0c95f6d0594a9cc0dd324e7a9f6..9eca8b84d090f94dac2beb5119682e444581ab22 100644 (file)
@@ -1,7 +1,3 @@
-#********************************************************************************************
-#                               Boot Time Configuration                                     *
-#                   Config knob changes will require controller restart                     *
-#********************************************************************************************
 #Ovsdb plugin's (OVS, HwVtep) support both active and passive connections. OVSDB library by
 #default listens on all IPs for switch initiated connections. Use following config
 #knob for changing this default IP.
@@ -18,17 +14,11 @@ use-ssl = false
 #Set Json Rpc decoder max frame length value. If the OVSDB node contains large configurations
 #that can cause connection related issue while reading the configuration from the OVSDB node
 #database. Increasing the max frame lenge helps resolve the issue. Please see following bug
-#report for more details ( https://bugs.opendaylight.org/show_bug.cgi?id=2732 &
-#https://bugs.opendaylight.org/show_bug.cgi?id=2487). Default value set to 100000.
+#report for more details ( https://jira.opendaylight.org/browse/OVSDB-140 &
+#https://jira.opendaylight.org/browse/OVSDB-134). Default value set to 100000.
 json-rpc-decoder-max-frame-length = 100000
 
-
-#********************************************************************************************
-#                               Run Time Configuration                                      *
-#                   Config knob changes doesn't require controller resart                   *
-#********************************************************************************************
 #Timeout value (in millisecond) after which OVSDB rpc task will be cancelled.Default value is
 #set to 1000ms, please uncomment and override the value if requires.Changing the value don't
 #require controller restart.
 ovsdb-rpc-task-timeout = 1000
-