base UpgradeStateImpl on (cached) UpgradeConfig instead of Config 44/75644/4
authorMichael Vorburger <vorburger@redhat.com>
Fri, 31 Aug 2018 19:05:12 +0000 (21:05 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Thu, 6 Sep 2018 19:00:39 +0000 (19:00 +0000)
This gives a consistent view of the genius and serviceutils upgrade
state to overall code possibly using a mix of both.  Before this change,
they could potentially see an inconsistent view of the
isUpgradeInProgress flag since they're obtaining it from different
sources.

In reality we only set this during installation, and it should normally
get in sync quickly, so IRL it's very unlikely to be a problem, but it's
still good to do this right.

based on review feedback in I08601afb77ca9faaa29e2839aefcdfbcbbb66f5e

Change-Id: I771529de81b689ad89bed6e3698e247d45dcb151
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
mdsalutil/mdsalutil-impl/src/main/java/org/opendaylight/genius/mdsalutil/internal/UpgradeStateImpl.java
mdsalutil/mdsalutil-impl/src/main/java/org/opendaylight/genius/mdsalutil/internal/UpgradeStateListener.java

index e278e47bb6167cfe0a7e2e8795d0f4445211db74..b2d322ac816223cbe862b69a0b4ac76a07c7bf2e 100644 (file)
@@ -17,7 +17,8 @@ import org.opendaylight.genius.mdsalutil.UpgradeState;
 import org.opendaylight.genius.mdsalutil.cache.InstanceIdDataObjectCache;
 import org.opendaylight.infrautils.caches.CacheProvider;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsalutil.rev170830.Config;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsalutil.rev170830.ConfigBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.upgrade.rev180702.UpgradeConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.upgrade.rev180702.UpgradeConfigBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.ops4j.pax.cdi.api.OsgiService;
 import org.ops4j.pax.cdi.api.OsgiServiceProvider;
@@ -25,10 +26,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * {@link UpgradeState} (genius) API implementation which makes the (genius)
- * Config model in the datastore available as a service, with caching.
+ * {@link UpgradeState} (genius) API implementation which makes the
+ * UpgradeConfig model (from serviceutils) in the datastore available as a
+ * service, with caching.
  *
- * @see UpgradeStateListener
+ * <p>Note that the {@link UpgradeStateListener} (in genius) keeps the
+ * UpgradeConfig model (from serviceutils) up-to-date with the {@link Config}
+ * model (from genius).
  */
 @Singleton
 @Named("geniusUpgradeStateListener") // to distinguish the <bean id=".."> from serviceutils' UpgradeStateListener
@@ -37,22 +41,22 @@ public class UpgradeStateImpl implements UpgradeState {
 
     private static final Logger LOG = LoggerFactory.getLogger(UpgradeStateImpl.class);
 
-    private static final InstanceIdentifier<Config> CONFIG_IID = UpgradeStateListener.CONFIG_IID;
-    private static final Config NO_UPGRADE_CONFIG_DEFAULT = new ConfigBuilder().setUpgradeInProgress(false).build();
+    private static final InstanceIdentifier<UpgradeConfig> CONFIG_IID = InstanceIdentifier.create(UpgradeConfig.class);
+    private static final UpgradeConfig CONFIG_DEFAULT = new UpgradeConfigBuilder().setUpgradeInProgress(false).build();
 
-    private final InstanceIdDataObjectCache<Config> configCache;
+    private final InstanceIdDataObjectCache<UpgradeConfig> configCache;
 
     public UpgradeStateImpl(@OsgiService final DataBroker dataBroker, @OsgiService CacheProvider caches) {
-        configCache = new InstanceIdDataObjectCache<>(Config.class, dataBroker, CONFIGURATION, CONFIG_IID, caches);
+        configCache = new InstanceIdDataObjectCache<>(UpgradeConfig.class, dataBroker, CONFIGURATION, CONFIG_IID,
+                caches);
     }
 
     @Override
     public boolean isUpgradeInProgress() {
         try {
-            return configCache.get(CONFIG_IID).toJavaUtil().orElse(NO_UPGRADE_CONFIG_DEFAULT).isUpgradeInProgress();
+            return configCache.get(CONFIG_IID).toJavaUtil().orElse(CONFIG_DEFAULT).isUpgradeInProgress();
         } catch (ReadFailedException e) {
-            // TODO remove catch and propagate to caller; but needs to be caught in netvirt
-            // users
+            // TODO remove catch and propagate to caller; but needs to be caught in netvirt users
             LOG.error("isUpgradeInProgress() read failed, return false, may be wrong!", e);
             return false;
         }
index 61a717199ec5f9ed20fac193d38440923e396dca..907fdc506cecca3a276945876e0a0add962c5988 100644 (file)
@@ -38,7 +38,7 @@ public class UpgradeStateListener extends AbstractSyncDataTreeChangeListener<Con
 
     private static final Logger LOG = LoggerFactory.getLogger(UpgradeStateListener.class);
 
-    public static final InstanceIdentifier<Config> CONFIG_IID = InstanceIdentifier.create(Config.class);
+    private static final InstanceIdentifier<Config> CONFIG_IID = InstanceIdentifier.create(Config.class);
 
     private final UpgradeUtils upgradeUtils;