use annotations instead of XML for blueprint 86/77386/3
authorMichael Vorburger <vorburger@redhat.com>
Wed, 31 Oct 2018 17:50:04 +0000 (18:50 +0100)
committerMichael Vorburger <vorburger@redhat.com>
Mon, 12 Nov 2018 18:13:02 +0000 (18:13 +0000)
This makes it easier to wire openflowplugin in opendaylight-simple.
(It would also be useful to write component tests.)

The autowire.xml which is now automatically generated from the
annotations at build time is, of course, 100% identical to the
hand-written (and now deleted) arbitratorreconciliation-manager.xml

JIRA: OPNFLWPLUG-1046
Change-Id: Id9eaaebf45ab718751c88cdbbac06fb400264638
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
applications/arbitratorreconciliation/impl/pom.xml
applications/arbitratorreconciliation/impl/src/main/java/org/opendaylight/openflowplugin/applications/arbitratorreconciliation/impl/ArbitratorReconciliationManagerImpl.java
applications/arbitratorreconciliation/impl/src/main/resources/org/opendaylight/blueprint/arbitratorreconciliation-manager.xml [deleted file]

index 014ab20c958e02c3929af7bb4698cad9b8ea03ab..ffbe1211106ab92490fb8fc729dc32550d438482 100644 (file)
             <artifactId>upgrade</artifactId>
             <version>${serviceutils.version}</version>
         </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>blueprint-maven-plugin-annotation</artifactId>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.aries.blueprint</groupId>
+                <artifactId>blueprint-maven-plugin</artifactId>
+            </plugin>
+
             <!-- TODO Remove this when we upgrade to odlparent with a fix for ODLPARENT-146 -->
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
index 17e1cecf6a5ababfffac4a2143321e7b098fc188..55486918a04ccf1f6e102086a39ba66cfdadb16f 100644 (file)
@@ -15,7 +15,6 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -27,7 +26,11 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicLong;
-
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowplugin.api.OFConstants;
@@ -82,6 +85,7 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
 public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileService,
         ReconciliationNotificationListener, AutoCloseable {
 
@@ -102,8 +106,9 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
     private final ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
     private final Map<BigInteger, BundleDetails> bundleIdMap = new ConcurrentHashMap<>();
 
-    public ArbitratorReconciliationManagerImpl(final RpcProviderRegistry rpcRegistry,
-            final ReconciliationManager reconciliationManager, final UpgradeState upgradeState) {
+    @Inject
+    public ArbitratorReconciliationManagerImpl(@Reference RpcProviderRegistry rpcRegistry,
+            @Reference ReconciliationManager reconciliationManager, @Reference UpgradeState upgradeState) {
         Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry cannot be null !");
         this.reconciliationManager = Preconditions.checkNotNull(reconciliationManager,
                 "ReconciliationManager cannot be null!");
@@ -114,12 +119,14 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
         this.upgradeState = Preconditions.checkNotNull(upgradeState, "UpgradeState cannot be null!");
     }
 
+    @PostConstruct
     public void start() {
         registration = reconciliationManager.registerService(this);
         LOG.info("ArbitratorReconciliationManager has started successfully.");
     }
 
     @Override
+    @PreDestroy
     public void close() throws Exception {
         executor.shutdown();
         if (registration != null) {
@@ -150,8 +157,8 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
                         MoreExecutors.directExecutor());
             }
         }
-        return RpcResultBuilder.success((new CommitActiveBundleOutputBuilder()
-                .setResult(null).build()))
+        return RpcResultBuilder.success(new CommitActiveBundleOutputBuilder()
+                .setResult(null).build())
                 .withRpcErrors(Collections.singleton(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
                 null, "No active bundle found for the node" + nodeId.toString()))).buildFuture();
     }
@@ -165,16 +172,16 @@ public class ArbitratorReconciliationManagerImpl implements ArbitratorReconcileS
                 //This blocking call is used to prevent the applications from pushing flows and groups via the default
                 // pipeline when the commit bundle is ongoing.
                 bundleDetails.getResult().get();
-                return RpcResultBuilder.success((new GetActiveBundleOutputBuilder()
-                        .setResult(bundleDetails.getBundleId()).build())).buildFuture();
+                return RpcResultBuilder.success(new GetActiveBundleOutputBuilder()
+                        .setResult(bundleDetails.getBundleId()).build()).buildFuture();
             } catch (InterruptedException | ExecutionException | NullPointerException e) {
                 return RpcResultBuilder.<GetActiveBundleOutput>failed()
                         .withRpcErrors(Collections.singleton(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
                                 null, e.getMessage()))).buildFuture();
             }
         }
-        return RpcResultBuilder.success((new GetActiveBundleOutputBuilder()
-                .setResult(null).build())).buildFuture();
+        return RpcResultBuilder.success(new GetActiveBundleOutputBuilder()
+                .setResult(null).build()).buildFuture();
     }
 
     @Override
diff --git a/applications/arbitratorreconciliation/impl/src/main/resources/org/opendaylight/blueprint/arbitratorreconciliation-manager.xml b/applications/arbitratorreconciliation/impl/src/main/resources/org/opendaylight/blueprint/arbitratorreconciliation-manager.xml
deleted file mode 100644 (file)
index fa5ca37..0000000
+++ /dev/null
@@ -1,19 +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"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           odl:use-default-for-reference-types="true">
-
-    <reference id="rpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>
-    <reference id="reconciliationservice" interface="org.opendaylight.openflowplugin.applications.reconciliation.ReconciliationManager"/>
-    <reference id="upgradeState" interface="org.opendaylight.serviceutils.upgrade.UpgradeState"/>
-
-    <bean id="arbitratorReconciliationManager"
-          class="org.opendaylight.openflowplugin.applications.arbitratorreconciliation.impl.ArbitratorReconciliationManagerImpl"
-        init-method="start" destroy-method="close">
-        <argument ref="rpcRegistry"/>
-        <argument ref="reconciliationservice"/>
-        <argument ref="upgradeState"/>
-    </bean>
-
-</blueprint>