X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-persister-feature-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfigpusherfeature%2Finternal%2FFeatureConfigPusher.java;h=7b90580a660cac0a03a4b90c0c0f8d40a1d2eb68;hb=d7ce37f576bcf35aa29665db89cadf854487f338;hp=1c094ad2dcea5b4def01253d4e6507a1b60a61f1;hpb=b725fdb758008195a98f7fad0fd3804c363170aa;p=controller.git diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigPusher.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigPusher.java index 1c094ad2dc..7b90580a66 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigPusher.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigPusher.java @@ -7,11 +7,11 @@ */ package org.opendaylight.controller.configpusherfeature.internal; +import com.google.common.collect.LinkedHashMultimap; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; - import org.apache.karaf.features.Feature; import org.apache.karaf.features.FeaturesService; import org.opendaylight.controller.config.persist.api.ConfigPusher; @@ -19,13 +19,13 @@ import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.collect.LinkedHashMultimap; - /* * Simple class to push configs to the config subsystem from Feature's configfiles */ public class FeatureConfigPusher { - private static final Logger logger = LoggerFactory.getLogger(FeatureConfigPusher.class); + private static final Logger LOG = LoggerFactory.getLogger(FeatureConfigPusher.class); + private static final int MAX_RETRIES=100; + private static final int RETRY_PAUSE_MILLIS=1; private FeaturesService featuresService = null; private ConfigPusher pusher = null; /* @@ -44,7 +44,7 @@ public class FeatureConfigPusher { /* * @param p - ConfigPusher to push ConfigSnapshotHolders */ - public FeatureConfigPusher(ConfigPusher p, FeaturesService f) { + public FeatureConfigPusher(final ConfigPusher p, final FeaturesService f) { pusher = p; featuresService = f; } @@ -57,7 +57,7 @@ public class FeatureConfigPusher { * If a Feature is not in the returned LinkedHashMultimap then we couldn't push its configs * (Ususally because it was not yet installed) */ - public LinkedHashMultimap pushConfigs(List features) throws Exception, InterruptedException { + public LinkedHashMultimap pushConfigs(final List features) throws Exception, InterruptedException { LinkedHashMultimap pushedFeatures = LinkedHashMultimap.create(); for(Feature feature: features) { LinkedHashSet configSnapShots = pushConfig(feature); @@ -68,7 +68,7 @@ public class FeatureConfigPusher { return pushedFeatures; } - private LinkedHashSet pushConfig(Feature feature) throws Exception, InterruptedException { + private LinkedHashSet pushConfig(final Feature feature) throws Exception, InterruptedException { LinkedHashSet configs = new LinkedHashSet(); if(isInstalled(feature)) { ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(feature,featuresService); @@ -81,12 +81,34 @@ public class FeatureConfigPusher { return configs; } - private boolean isInstalled(Feature feature) { - List installedFeatures = Arrays.asList(featuresService.listInstalledFeatures()); - return installedFeatures.contains(feature); + private boolean isInstalled(final Feature feature) { + for(int retries=0;retries installedFeatures = Arrays.asList(featuresService.listInstalledFeatures()); + if(installedFeatures.contains(feature)) { + return true; + } else { + LOG.warn("Karaf featuresService.listInstalledFeatures() has not yet finished installing feature (retry {}) {} {}",retries,feature.getName(),feature.getVersion()); + } + } catch (Exception e) { + if(retries < MAX_RETRIES) { + LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e); + } else { + LOG.error("Giving up on Karaf featuresService.listInstalledFeatures() which has thrown an exception, retry {}", retries, e); + throw e; + } + } + try { + Thread.sleep(RETRY_PAUSE_MILLIS); + } catch (InterruptedException e1) { + throw new IllegalStateException(e1); + } + } + LOG.error("Giving up (after {} retries) on Karaf featuresService.listInstalledFeatures() which has not yet finished installing feature {} {}",MAX_RETRIES,feature.getName(),feature.getVersion()); + return false; } - private LinkedHashSet pushConfig(LinkedHashSet configs) throws InterruptedException { + private LinkedHashSet pushConfig(final LinkedHashSet configs) throws InterruptedException { LinkedHashSet configsToPush = new LinkedHashSet(configs); configsToPush.removeAll(pushedConfigs); if(!configsToPush.isEmpty()) {