Migrate ntfbenchmark to OSGi DS 22/97722/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 3 Oct 2021 14:33:33 +0000 (16:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Oct 2021 06:56:59 +0000 (08:56 +0200)
Ditch blueprint and use turn NtfBenchmarkProvider into a simple
component.

JIRA: CONTROLLER-2001
Change-Id: I68dd5559f61c28bbdcbff54815af7d287e948a50
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
benchmark/ntfbenchmark/pom.xml
benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchmarkProvider.java
benchmark/ntfbenchmark/src/main/resources/OSGI-INF/blueprint/ntfbenchmark.xml [deleted file]

index fe84081df2ce87e239692f9aab4223646a143dd6..aa9e50cefd48fc0b65012fd6836840a29ce3a6de 100644 (file)
@@ -28,5 +28,19 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>org.opendaylight.mdsal</groupId>
       <artifactId>mdsal-binding-api</artifactId>
     </dependency>
       <groupId>org.opendaylight.mdsal</groupId>
       <artifactId>mdsal-binding-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.guicedee.services</groupId>
+      <artifactId>javax.inject</artifactId>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>javax.annotation</groupId>
+      <artifactId>javax.annotation-api</artifactId>
+      <optional>true</optional>
+    </dependency>
   </dependencies>
 </project>
   </dependencies>
 </project>
index 50b0478628beb68ff332ba738b28f7b78c20c1eb..acd5af61436a9be62f886e8e1fdfa6372c286c6a 100644 (file)
@@ -8,6 +8,7 @@
 package ntfbenchmark.impl;
 
 import static com.google.common.base.Verify.verifyNotNull;
 package ntfbenchmark.impl;
 
 import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
@@ -16,8 +17,12 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.binding.api.NotificationService;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.NtfbenchmarkService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestInput.ProducerType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.NtfbenchmarkService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestInput.ProducerType;
@@ -26,32 +31,45 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbench
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatusInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatusOutput;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatusInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatusOutput;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.common.Uint32;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.RequireServiceComponentRuntime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NtfbenchmarkProvider implements AutoCloseable, NtfbenchmarkService {
+@Singleton
+@Component(service = {})
+@RequireServiceComponentRuntime
+public final class NtfbenchmarkProvider implements AutoCloseable, NtfbenchmarkService {
     private static final Logger LOG = LoggerFactory.getLogger(NtfbenchmarkProvider.class);
     private static final int TEST_TIMEOUT = 5;
 
     private final NotificationService listenService;
     private final NotificationPublishService publishService;
     private static final Logger LOG = LoggerFactory.getLogger(NtfbenchmarkProvider.class);
     private static final int TEST_TIMEOUT = 5;
 
     private final NotificationService listenService;
     private final NotificationPublishService publishService;
-
-    public NtfbenchmarkProvider(final NotificationService listenServiceDependency,
-            final NotificationPublishService publishServiceDependency) {
-        LOG.debug("NtfbenchmarkProvider Constructor");
-        listenService = listenServiceDependency;
-        publishService = publishServiceDependency;
-    }
-
-    public void init() {
-        LOG.info("NtfbenchmarkProvider initiated");
+    private final Registration reg;
+
+    @Inject
+    @Activate
+    public NtfbenchmarkProvider(@Reference final NotificationService listenService,
+            @Reference final NotificationPublishService publishService,
+            @Reference final RpcProviderService rpcService) {
+        this.listenService = requireNonNull(listenService);
+        this.publishService = requireNonNull(publishService);
+        reg = rpcService.registerRpcImplementation(NtfbenchmarkService.class, this);
+        LOG.debug("NtfbenchmarkProvider initiated");
     }
 
     @Override
     }
 
     @Override
+    @PreDestroy
+    @Deactivate
     public void close() {
     public void close() {
+        reg.close();
         LOG.info("NtfbenchmarkProvider closed");
     }
 
         LOG.info("NtfbenchmarkProvider closed");
     }
 
@@ -119,17 +137,16 @@ public class NtfbenchmarkProvider implements AutoCloseable, NtfbenchmarkService
                 allProducersError += abstractNtfbenchProducer.getNtfError();
             }
 
                 allProducersError += abstractNtfbenchProducer.getNtfError();
             }
 
-            final StartTestOutput output =
-                    new StartTestOutputBuilder()
-                            .setProducerElapsedTime(Uint32.valueOf(producerElapsedTime / 1000000))
-                            .setListenerElapsedTime(Uint32.valueOf(listenerElapsedTime / 1000000))
-                            .setListenerOk(Uint32.valueOf(allListeners))
-                            .setProducerOk(Uint32.valueOf(allProducersOk))
-                            .setProducerError(Uint32.valueOf(allProducersError))
-                            .setProducerRate(Uint32.valueOf((allProducersOk + allProducersError) * 1000000000
-                                / producerElapsedTime))
-                            .setListenerRate(Uint32.valueOf(allListeners * 1000000000 / listenerElapsedTime))
-                           .build();
+            final StartTestOutput output = new StartTestOutputBuilder()
+                .setProducerElapsedTime(Uint32.valueOf(producerElapsedTime / 1000000))
+                .setListenerElapsedTime(Uint32.valueOf(listenerElapsedTime / 1000000))
+                .setListenerOk(Uint32.valueOf(allListeners))
+                .setProducerOk(Uint32.valueOf(allProducersOk))
+                .setProducerError(Uint32.valueOf(allProducersError))
+                .setProducerRate(
+                    Uint32.valueOf((allProducersOk + allProducersError) * 1000000000 / producerElapsedTime))
+                .setListenerRate(Uint32.valueOf(allListeners * 1000000000 / listenerElapsedTime))
+                .build();
             return RpcResultBuilder.success(output).buildFuture();
         } finally {
             for (final ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
             return RpcResultBuilder.success(output).buildFuture();
         } finally {
             for (final ListenerRegistration<NtfbenchTestListener> listenerRegistration : listeners) {
@@ -140,8 +157,6 @@ public class NtfbenchmarkProvider implements AutoCloseable, NtfbenchmarkService
 
     @Override
     public ListenableFuture<RpcResult<TestStatusOutput>> testStatus(final TestStatusInput input) {
 
     @Override
     public ListenableFuture<RpcResult<TestStatusOutput>> testStatus(final TestStatusInput input) {
-        // TODO Auto-generated method stub
-        return null;
+        throw new UnsupportedOperationException("Not implemented");
     }
     }
-
 }
 }
diff --git a/benchmark/ntfbenchmark/src/main/resources/OSGI-INF/blueprint/ntfbenchmark.xml b/benchmark/ntfbenchmark/src/main/resources/OSGI-INF/blueprint/ntfbenchmark.xml
deleted file mode 100644 (file)
index 0b36361..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2017 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"
-           odl:use-default-for-reference-types="true">
-
-  <reference id="publishService" interface="org.opendaylight.mdsal.binding.api.NotificationPublishService"/>
-  <reference id="listenerService" interface="org.opendaylight.mdsal.binding.api.NotificationService"/>
-
-  <bean id="provider" class="ntfbenchmark.impl.NtfbenchmarkProvider"
-          init-method="init" destroy-method="close">
-    <argument ref="publishService"/>
-    <argument ref="listenerService"/>
-  </bean>
-
-  <odl:rpc-implementation ref="provider"/>
-</blueprint>