Eliminate blueprint from test-extension 14/110214/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 10 Feb 2024 12:56:22 +0000 (13:56 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 10 Feb 2024 15:53:35 +0000 (16:53 +0100)
This is a simple component, migrate it.

JIRA: OPNFLWPLUG-1112
Change-Id: I3fccec39289314aa23bc906cc57b2138f408bf81
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
extension/test-extension/pom.xml
extension/test-extension/src/main/java/org/opendaylight/openflowplugin/extension/test/Test.java
extension/test-extension/src/main/resources/OSGI-INF/blueprint/test-extension.xml [deleted file]

index 6fbaa66b8acdcc03903c88b9a82a850d5b52cb09..86bbbb677a3f2d07959f1571da2e7a4d660e0364 100644 (file)
     <packaging>bundle</packaging>
 
     <dependencies>
+        <dependency>
+            <groupId>com.guicedee.services</groupId>
+            <artifactId>javax.inject</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>jakarta.annotation</groupId>
+            <artifactId>jakarta.annotation-api</artifactId>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.openflowplugin</groupId>
             <artifactId>openflowplugin-extension-nicira</artifactId>
             <groupId>org.opendaylight.infrautils</groupId>
             <artifactId>infrautils-util</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+        </dependency>
 
         <!-- OpenFlowJava-API models -->
         <dependency>
index f4b3c2911995bc34110ef2f7c297eb4dcba1dce5..696afcc33996a1a2f5ee00454677f933fa462fe4 100644 (file)
@@ -9,7 +9,12 @@ package org.opendaylight.openflowplugin.extension.test;
 
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
@@ -38,9 +43,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegLoadNodesNodeTableFlowApplyActionsCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.NxRegLoadBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.load.grouping.nx.reg.load.DstBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev130819.TestFlow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev130819.TestFlowInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev130819.TestFlowOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev130819.TestService;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -49,6 +55,10 @@ import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.common.Uint64;
 import org.opendaylight.yangtools.yang.common.Uint8;
+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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,13 +67,31 @@ import org.slf4j.LoggerFactory;
  *
  * @author msunal
  */
-public class Test implements TestService {
+@Singleton
+@Component(service = { })
+public final class Test implements TestFlow, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(Test.class);
 
-    private AddFlow addFlow;
+    private final AddFlow addFlow;
+    private final Registration reg;
 
+    @Inject
+    @Activate
+    public Test(@Reference final RpcConsumerRegistry rpcService,
+            @Reference final RpcProviderService rpcProviderService) {
+        addFlow = rpcService.getRpc(AddFlow.class);
+        reg = rpcProviderService.registerRpcImplementation(this);
+    }
+
+    @PreDestroy
+    @Deactivate
     @Override
-    public ListenableFuture<RpcResult<TestFlowOutput>> testFlow(final TestFlowInput input) {
+    public void close() {
+        reg.close();
+    }
+
+    @Override
+    public ListenableFuture<RpcResult<TestFlowOutput>> invoke(final TestFlowInput input) {
         // Construct the flow instance id
         final InstanceIdentifier<Node> flowInstanceId = InstanceIdentifier
                 .builder(Nodes.class) // File under nodes
@@ -128,8 +156,4 @@ public class Test implements TestService {
             LoggingFutures.addErrorLogging(addFlow.invoke(addFlowInput), LOG, "addFlow");
         }
     }
-
-    public void setAddFlow(final AddFlow addFlow) {
-        this.addFlow = addFlow;
-    }
 }
diff --git a/extension/test-extension/src/main/resources/OSGI-INF/blueprint/test-extension.xml b/extension/test-extension/src/main/resources/OSGI-INF/blueprint/test-extension.xml
deleted file mode 100644 (file)
index 0b2b93c..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
-
-  <odl:rpc-service id="salFlowService"
-      interface="org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService"/>
-
-  <bean id="test" class="org.opendaylight.openflowplugin.extension.test.Test">
-    <property name="flowService" ref="salFlowService"/>
-  </bean>
-
-  <odl:rpc-implementation ref="test"/>
-
-</blueprint>