X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-persister-feature-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfigpusherfeature%2Finternal%2FFeatureConfigPusher.java;h=50757fb7b90961df577d1dc1d7675bbf56ea8bb5;hp=1c094ad2dcea5b4def01253d4e6507a1b60a61f1;hb=8b1ea7f69a0183c988d3861a8b6c90e465d687ae;hpb=a3ff4b68093e6d675a92159e0efa2525af32d644 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..50757fb7b9 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,25 +7,28 @@ */ package org.opendaylight.controller.configpusherfeature.internal; +import com.google.common.base.Optional; +import com.google.common.collect.LinkedHashMultimap; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; - +import java.util.Set; import org.apache.karaf.features.Feature; import org.apache.karaf.features.FeaturesService; import org.opendaylight.controller.config.persist.api.ConfigPusher; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; +import org.opendaylight.controller.config.persist.storage.file.xml.XmlFileStorageAdapter; 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; /* @@ -34,7 +37,7 @@ public class FeatureConfigPusher { * chains. Also, preserves the *original* Feature chain for which we pushed the config. * (which is handy for logging). */ - LinkedHashSet pushedConfigs = new LinkedHashSet(); + Set pushedConfigs = new LinkedHashSet<>(); /* * LinkedHashMultimap to track which configs we pushed for each Feature installation * For future use @@ -44,7 +47,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,43 +60,78 @@ 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 { - LinkedHashMultimap pushedFeatures = LinkedHashMultimap.create(); - for(Feature feature: features) { - LinkedHashSet configSnapShots = pushConfig(feature); - if(!configSnapShots.isEmpty()) { - pushedFeatures.putAll(feature,configSnapShots); + public LinkedHashMultimap pushConfigs(final List features) throws Exception { + LinkedHashMultimap pushedFeatures = LinkedHashMultimap.create(); + for (Feature feature : features) { + + + Set configSnapShots = pushConfig(feature); + if (!configSnapShots.isEmpty()) { + pushedFeatures.putAll(feature, configSnapShots); } } return pushedFeatures; } - private LinkedHashSet pushConfig(Feature feature) throws Exception, InterruptedException { - LinkedHashSet configs = new LinkedHashSet(); + private Set pushConfig(final Feature feature) throws Exception { + Set configs = new LinkedHashSet<>(); if(isInstalled(feature)) { - ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(feature,featuresService); - configs = wrappedFeature.getFeatureConfigSnapshotHolders(); - if(!configs.isEmpty()) { - configs = pushConfig(configs); - feature2configs.putAll(feature, configs); + // FIXME Workaround for BUG-2836, features service returns null for feature: standard-condition-webconsole_0_0_0, 3.0.1 + if(featuresService.getFeature(feature.getName(), feature.getVersion()) == null) { + LOG.debug("Feature: {}, {} is missing from features service. Skipping", feature.getName(), feature.getVersion()); + } else { + ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(feature, featuresService); + configs = wrappedFeature.getFeatureConfigSnapshotHolders(); + if (!configs.isEmpty()) { + configs = pushConfig(configs, feature); + feature2configs.putAll(feature, configs); + } } } 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 < MAX_RETRIES; retries++) { + try { + List 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) { + LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, 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 { - LinkedHashSet configsToPush = new LinkedHashSet(configs); + private Set pushConfig(final Set configs, final Feature feature) + throws InterruptedException { + Set configsToPush = new LinkedHashSet<>(configs); configsToPush.removeAll(pushedConfigs); - if(!configsToPush.isEmpty()) { - pusher.pushConfigs(new ArrayList(configsToPush)); + if (!configsToPush.isEmpty()) { + + // Ignore features that are present in persisted current config + final Optional currentCfgPusher = XmlFileStorageAdapter.getInstance(); + if (currentCfgPusher.isPresent() && + currentCfgPusher.get().getPersistedFeatures().contains(feature.getId())) { + LOG.warn("Ignoring default configuration {} for feature {}, the configuration is present in {}", + configsToPush, feature.getId(), currentCfgPusher.get()); + } else { + pusher.pushConfigs(new ArrayList(configsToPush)); + } + pushedConfigs.addAll(configsToPush); } - LinkedHashSet configsPushed = new LinkedHashSet(pushedConfigs); + Set configsPushed = new LinkedHashSet<>(pushedConfigs); configsPushed.retainAll(configs); return configsPushed; }