fix BP gen. XML related issue in projects dep. on serviceutils.upgrade 00/74400/1
authorMichael Vorburger <vorburger@redhat.com>
Tue, 24 Jul 2018 14:54:11 +0000 (16:54 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Tue, 24 Jul 2018 14:54:11 +0000 (16:54 +0200)
see genius change I91466c31c0526ff227700f23b48b9db0dfb15f5a
<https://git.opendaylight.org/gerrit/#/c/73678/> comments for full
background.

Change-Id: Icacba88d577a4fc5da61fd490a3c9fee13f7034f
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
upgrade/pom.xml
upgrade/src/main/java/org/opendaylight/serviceutils/upgrade/impl/UpgradeStateListener.java
upgrade/src/main/resources/org/opendaylight/blueprint/upgrade.xml

index 484252149163d210f46aaba62c65419daef16842..3b9bd75bef2ad7a20d2396b0360612256a91c4ad 100644 (file)
@@ -38,22 +38,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-binding-api</artifactId>
     </dependency>
-    <dependency>
-      <groupId>javax.inject</groupId>
-      <artifactId>javax.inject</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.ops4j.pax.cdi</groupId>
-      <artifactId>pax-cdi-api</artifactId>
-      <optional>true</optional>
-    </dependency>
   </dependencies>
   <build>
     <plugins>
-      <plugin>
-        <groupId>org.apache.aries.blueprint</groupId>
-        <artifactId>blueprint-maven-plugin</artifactId>
-      </plugin>
+      <!-- Do *NOT* use annotation based DI with the blueprint-maven-plugin here; the issue is that this
+           will cause problems in other projects having a dependency to this one (they would repeat and re-generate this project's BP XML). -->
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>build-helper-maven-plugin</artifactId>
index 31878ffcd0e6de9e08172e80180d885f744786b3..32784d613eaeed3fd9a1874ee6668720866105b7 100644 (file)
@@ -5,7 +5,6 @@
  * 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.serviceutils.upgrade.impl;
 
 import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
@@ -14,10 +13,6 @@ import java.util.Collection;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.annotation.Nonnull;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
@@ -29,13 +24,11 @@ import org.opendaylight.serviceutils.upgrade.UpgradeState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.upgrade.rev180702.UpgradeConfig;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.ops4j.pax.cdi.api.OsgiService;
-import org.ops4j.pax.cdi.api.OsgiServiceProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@Singleton
-@OsgiServiceProvider(classes = UpgradeState.class)
+// Do *NOT* use annotation based DI with the blueprint-maven-plugin here; the issue is that this will cause
+// problems in other projects having a dependency to this one (they would repeat and re-generate this project's BP XML).
 public class UpgradeStateListener implements ClusteredDataTreeChangeListener<UpgradeConfig>, UpgradeState {
     private static final Logger LOG = LoggerFactory.getLogger(UpgradeStateListener.class);
 
@@ -44,8 +37,7 @@ public class UpgradeStateListener implements ClusteredDataTreeChangeListener<Upg
         new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(UpgradeConfig.class));
     private final AtomicBoolean isUpgradeInProgress = new AtomicBoolean(false);
 
-    @Inject
-    public UpgradeStateListener(@OsgiService DataBroker dataBroker, UpgradeConfig upgradeConfig) {
+    public UpgradeStateListener(DataBroker dataBroker, UpgradeConfig upgradeConfig) {
         registration = dataBroker.registerDataTreeChangeListener(treeId, UpgradeStateListener.this);
         WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
         //TODO: DS Writes should ideally be done from one node to avoid ConflictingModExceptions
@@ -58,7 +50,6 @@ public class UpgradeStateListener implements ClusteredDataTreeChangeListener<Upg
         } // Possibility of OptimisticLockException?
     }
 
-    @PreDestroy
     public void close() {
         if (registration != null) {
             registration.close();
index eafc7de5fe3eb3b210a858c0c8242e5d478e9f9a..1de7ea44463769b0a4c09657ef2cd5649650d8f6 100644 (file)
@@ -10,10 +10,18 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
            xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
            odl:use-default-for-reference-types="true">
 
+  <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+
   <odl:clustered-app-config id="upgradeConfig"
                             binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.upgrade.rev180702.UpgradeConfig"
                             default-config-file-name="serviceutils-upgrade-config.xml"
                             update-strategy="none">
   </odl:clustered-app-config>
 
+  <bean id="upgradeStateListener" class="org.opendaylight.serviceutils.upgrade.impl.UpgradeStateListener" destroy-method="close">
+      <argument ref="dataBroker"/>
+      <argument ref="upgradeConfig"/>
+  </bean>
+  <service ref="upgradeStateListener" interface="org.opendaylight.serviceutils.upgrade.UpgradeState"/>
+
 </blueprint>