From: David Suarez Date: Tue, 12 Sep 2017 14:26:05 +0000 (+0200) Subject: Fix checkstyle issues to enforce it X-Git-Tag: release/oxygen~90 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=35cfadae941fb2a8722b40b829569d8754fa309e Fix checkstyle issues to enforce it Change-Id: I901673c4c8f478e914efd54d26bee56a80296868 Signed-off-by: David Suarez --- diff --git a/opendaylight/config/config-persister-feature-adapter/pom.xml b/opendaylight/config/config-persister-feature-adapter/pom.xml index d7fd2d0230..cd6f6b1b6f 100644 --- a/opendaylight/config/config-persister-feature-adapter/pom.xml +++ b/opendaylight/config/config-persister-feature-adapter/pom.xml @@ -51,6 +51,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + org.apache.felix maven-bundle-plugin diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/ConfigPusherFeatureActivator.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/ConfigPusherFeatureActivator.java index c20c6f9182..99334da488 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/ConfigPusherFeatureActivator.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/ConfigPusherFeatureActivator.java @@ -14,10 +14,9 @@ import org.osgi.framework.BundleContext; import org.osgi.util.tracker.ServiceTracker; public class ConfigPusherFeatureActivator implements BundleActivator { - - BundleContext bc = null; - ConfigPusherCustomizer cpc = null; - ServiceTracker cpst = null; + private BundleContext bc = null; + private ConfigPusherCustomizer cpc = null; + private ServiceTracker cpst = null; public void start(final BundleContext context) throws Exception { bc = context; @@ -27,11 +26,11 @@ public class ConfigPusherFeatureActivator implements BundleActivator { } public void stop(final BundleContext context) throws Exception { - if(cpst != null) { + if (cpst != null) { cpst.close(); cpst = null; } - if(cpc != null) { + if (cpc != null) { cpc.close(); cpc = null; } diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/AbstractFeatureWrapper.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/AbstractFeatureWrapper.java index bce4d3c0c5..3c8622a168 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/AbstractFeatureWrapper.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/AbstractFeatureWrapper.java @@ -10,14 +10,19 @@ package org.opendaylight.controller.configpusherfeature.internal; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.io.Files; + import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; + import javax.xml.bind.JAXBException; import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLStreamException; + import org.apache.karaf.features.BundleInfo; import org.apache.karaf.features.Capability; import org.apache.karaf.features.Conditional; @@ -32,6 +37,7 @@ import org.opendaylight.controller.config.persist.storage.file.xml.model.ConfigS import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; +import org.xml.sax.SAXException; /* * Wrap a Feature for the purposes of extracting the FeatureConfigSnapshotHolders from @@ -53,9 +59,9 @@ public class AbstractFeatureWrapper implements Feature { /* * @param f Feature to wrap */ - public AbstractFeatureWrapper(final Feature f) { - Preconditions.checkNotNull(f,"FeatureWrapper requires non-null Feature in constructor"); - this.feature = f; + public AbstractFeatureWrapper(final Feature feature) { + Preconditions.checkNotNull(feature, "FeatureWrapper requires non-null Feature in constructor"); + this.feature = feature; } /* @@ -64,11 +70,12 @@ public class AbstractFeatureWrapper implements Feature { */ public Set getFeatureConfigSnapshotHolders() throws Exception { final Set snapShotHolders = new LinkedHashSet<>(); - for(final ConfigFileInfo c: getConfigurationFiles()) { + for (final ConfigFileInfo c : getConfigurationFiles()) { // Skip non config snapshot XML files - if(isConfigSnapshot(c.getFinalname())) { - final Optional featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(c); - if(featureConfigSnapshotHolder.isPresent()) { + if (isConfigSnapshot(c.getFinalname())) { + final Optional featureConfigSnapshotHolder = + getFeatureConfigSnapshotHolder(c); + if (featureConfigSnapshotHolder.isPresent()) { snapShotHolders.add(featureConfigSnapshotHolder.get()); } } @@ -76,28 +83,29 @@ public class AbstractFeatureWrapper implements Feature { return snapShotHolders; } - protected Optional getFeatureConfigSnapshotHolder(final ConfigFileInfo c) { + protected Optional + getFeatureConfigSnapshotHolder(final ConfigFileInfo configFileInfo) { try { - return Optional.of(new FeatureConfigSnapshotHolder(c, this)); + return Optional.of(new FeatureConfigSnapshotHolder(configFileInfo, this)); } catch (final JAXBException e) { - LOG.warn("Unable to parse configuration snapshot. Config from '{}' will be IGNORED. " + - "Note that subsequent config files may fail due to this problem. " + - "Xml markup in this file needs to be fixed, for detailed information see enclosed exception.", - c.getFinalname(), e); + LOG.warn("Unable to parse configuration snapshot. Config from '{}' will be IGNORED. " + + "Note that subsequent config files may fail due to this problem. " + + "Xml markup in this file needs to be fixed, for detailed information see enclosed exception.", + configFileInfo.getFinalname(), e); } catch (final XMLStreamException e) { // Files that cannot be loaded are ignored as non config subsystem files e.g. jetty.xml LOG.debug("Unable to read configuration file '{}'. Not a configuration snapshot", - c.getFinalname(), e); + configFileInfo.getFinalname(), e); } return Optional.absent(); } private static boolean isConfigSnapshot(final String fileName) { - if(!Files.getFileExtension(fileName).equals(CONFIG_FILE_SUFFIX)) { + if (!Files.getFileExtension(fileName).equals(CONFIG_FILE_SUFFIX)) { return false; } - if(fileName.endsWith("jetty.xml")) { + if (fileName.endsWith("jetty.xml")) { // Special case - ignore the jetty.xml file as it contains a DTD and causes a "Connection refused" // error when it tries to go out to the network to retrieve it. We don't want it trying to go out // to the network nor do we want an error logged trying to parse it. @@ -105,7 +113,7 @@ public class AbstractFeatureWrapper implements Feature { } File file = new File(System.getProperty("karaf.home"), fileName); - try(FileInputStream fis = new FileInputStream(file)) { + try (FileInputStream fis = new FileInputStream(file)) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); builderFactory.setCoalescing(true); @@ -114,7 +122,7 @@ public class AbstractFeatureWrapper implements Feature { Element root = builderFactory.newDocumentBuilder().parse(fis).getDocumentElement(); return ConfigSnapshot.SNAPSHOT_ROOT_ELEMENT_NAME.equals(root.getLocalName()); - } catch (final Exception e) { + } catch (final ParserConfigurationException | IOException | SAXException e) { LOG.error("Could not parse XML file {}", file, e); return false; } diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ChildAwareFeatureWrapper.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ChildAwareFeatureWrapper.java index f51bf4738a..91295008ab 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ChildAwareFeatureWrapper.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ChildAwareFeatureWrapper.java @@ -9,9 +9,11 @@ package org.opendaylight.controller.configpusherfeature.internal; import com.google.common.base.Optional; import com.google.common.base.Preconditions; + import java.util.LinkedHashSet; import java.util.List; import java.util.Set; + import org.apache.felix.utils.version.VersionRange; import org.apache.felix.utils.version.VersionTable; import org.apache.karaf.features.Dependency; @@ -29,20 +31,21 @@ import org.slf4j.LoggerFactory; */ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements Feature { private static final Logger LOG = LoggerFactory.getLogger(ChildAwareFeatureWrapper.class); - private FeaturesService featuresService= null; + private FeaturesService featuresService = null; - protected ChildAwareFeatureWrapper(final Feature f) { + protected ChildAwareFeatureWrapper(final Feature feature) { // Don't use without a feature service } - /* - * @param f Feature to wrap - * @param s FeaturesService to look up dependencies + /* Constructor. + + * @param feature Feature to wrap + * @param featuresService FeaturesService to look up dependencies */ - ChildAwareFeatureWrapper(final Feature f, final FeaturesService s) throws Exception { - super(s.getFeature(f.getName(), f.getVersion())); - Preconditions.checkNotNull(s, "FeatureWrapper requires non-null FeatureService in constructor"); - this.featuresService = s; + ChildAwareFeatureWrapper(final Feature feature, final FeaturesService featuresService) throws Exception { + super(featuresService.getFeature(feature.getName(), feature.getVersion())); + Preconditions.checkNotNull(featuresService, "FeatureWrapper requires non-null FeatureService in constructor"); + this.featuresService = featuresService; } protected FeaturesService getFeaturesService() { @@ -56,12 +59,13 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements public Set getChildFeatures() throws Exception { List dependencies = feature.getDependencies(); Set childFeatures = new LinkedHashSet<>(); - if(dependencies != null) { - for(Dependency dependency: dependencies) { + if (dependencies != null) { + for (Dependency dependency : dependencies) { Feature fi = extractFeatureFromDependency(dependency); if (fi != null) { if (featuresService.getFeature(fi.getName(), fi.getVersion()) == null) { - LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi.getVersion()); + LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi + .getVersion()); } else { ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi, featuresService); childFeatures.add(wrappedFeature); @@ -75,10 +79,11 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements @Override public Set getFeatureConfigSnapshotHolders() throws Exception { Set snapShotHolders = new LinkedHashSet<>(); - for(ChildAwareFeatureWrapper c: getChildFeatures()) { - for(FeatureConfigSnapshotHolder h: c.getFeatureConfigSnapshotHolders()) { - final Optional featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(h.getFileInfo()); - if(featureConfigSnapshotHolder.isPresent()) { + for (ChildAwareFeatureWrapper c : getChildFeatures()) { + for (FeatureConfigSnapshotHolder h : c.getFeatureConfigSnapshotHolders()) { + final Optional featureConfigSnapshotHolder = + getFeatureConfigSnapshotHolder(h.getFileInfo()); + if (featureConfigSnapshotHolder.isPresent()) { snapShotHolders.add(featureConfigSnapshotHolder.get()); } } @@ -89,14 +94,14 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements protected Feature extractFeatureFromDependency(final Dependency dependency) throws Exception { Feature[] features = featuresService.listFeatures(); - VersionRange range = org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency.getVersion()) - ? VersionRange.ANY_VERSION : new VersionRange(dependency.getVersion(), true, true); + VersionRange range = org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency + .getVersion()) ? VersionRange.ANY_VERSION : new VersionRange(dependency.getVersion(), true, true); Feature fi = null; - for(Feature f: features) { + for (Feature f : features) { if (f.getName().equals(dependency.getName())) { - Version v = VersionTable.getVersion(f.getVersion()); - if (range.contains(v) && - (fi == null || VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0)) { + Version version = VersionTable.getVersion(f.getVersion()); + if (range.contains(version) && (fi == null || VersionTable.getVersion(fi.getVersion()) + .compareTo(version) < 0)) { fi = f; break; } @@ -104,5 +109,4 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements } return fi; } - } diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigFeaturesListener.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigFeaturesListener.java index 075db509f8..d5d590aadc 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigFeaturesListener.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigFeaturesListener.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.configpusherfeature.internal; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; + import org.apache.karaf.features.FeatureEvent; import org.apache.karaf.features.FeaturesListener; import org.apache.karaf.features.FeaturesService; @@ -17,14 +18,15 @@ import org.opendaylight.controller.config.persist.api.ConfigPusher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ConfigFeaturesListener implements FeaturesListener, AutoCloseable { +public class ConfigFeaturesListener implements FeaturesListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(ConfigFeaturesListener.class); private static final int QUEUE_SIZE = 1000; private BlockingQueue queue = new LinkedBlockingQueue<>(QUEUE_SIZE); Thread pushingThread = null; - public ConfigFeaturesListener(final ConfigPusher p, final FeaturesService f) { - pushingThread = new Thread(new ConfigPushingRunnable(p, f, queue), "ConfigFeatureListener - ConfigPusher"); + public ConfigFeaturesListener(final ConfigPusher configPusher, final FeaturesService featuresService) { + pushingThread = new Thread(new ConfigPushingRunnable(configPusher, featuresService, queue), + "ConfigFeatureListener - ConfigPusher"); pushingThread.start(); } @@ -40,7 +42,7 @@ public class ConfigFeaturesListener implements FeaturesListener, AutoCloseable @Override public void close() { - if(pushingThread != null) { + if (pushingThread != null) { pushingThread.interrupt(); pushingThread = null; } diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPusherCustomizer.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPusherCustomizer.java index ac10c68c8f..e665309c92 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPusherCustomizer.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPusherCustomizer.java @@ -20,7 +20,7 @@ public class ConfigPusherCustomizer implements ServiceTrackerCustomizer fsst = null; + private ServiceTracker fsst = null; @Override public ConfigPusher addingService(final ServiceReference configPusherServiceReference) { @@ -34,26 +34,28 @@ public class ConfigPusherCustomizer implements ServiceTrackerCustomizer configPusherServiceReference, final ConfigPusher configPusher) { + public void modifiedService(final ServiceReference configPusherServiceReference, + final ConfigPusher configPusher) { // we don't care if the properties change } @Override - public void removedService(final ServiceReference configPusherServiceReference, final ConfigPusher configPusher) { + public void removedService(final ServiceReference configPusherServiceReference, + final ConfigPusher configPusher) { this.close(); } @Override public void close() { - if(fsst != null) { + if (fsst != null) { fsst.close(); fsst = null; } - if(configFeaturesListener != null) { + if (configFeaturesListener != null) { configFeaturesListener.close(); configFeaturesListener = null; } - if(featureServiceCustomizer != null) { + if (featureServiceCustomizer != null) { featureServiceCustomizer.close(); featureServiceCustomizer = null; } diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPushingRunnable.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPushingRunnable.java index 48c494b5c7..010a273154 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPushingRunnable.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPushingRunnable.java @@ -8,10 +8,12 @@ package org.opendaylight.controller.configpusherfeature.internal; import com.google.common.collect.LinkedHashMultimap; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; + import org.apache.karaf.features.Feature; import org.apache.karaf.features.FeatureEvent; import org.apache.karaf.features.FeatureEvent.EventType; @@ -25,34 +27,37 @@ public class ConfigPushingRunnable implements Runnable { private static final int POLL_TIME = 1; private BlockingQueue queue; private FeatureConfigPusher configPusher; - public ConfigPushingRunnable(final ConfigPusher p, final FeaturesService f, final BlockingQueue q) { - queue = q; - configPusher = new FeatureConfigPusher(p, f); + + public ConfigPushingRunnable(final ConfigPusher configPusher, final FeaturesService featuresService, + final BlockingQueue featureEvents) { + queue = featureEvents; + this.configPusher = new FeatureConfigPusher(configPusher, featuresService); } @Override + @SuppressWarnings("IllegalCatch") public void run() { List toInstall = new ArrayList<>(); FeatureEvent event = null; - boolean interuppted = false; - while(true) { + boolean interrupted = false; + while (true) { try { - if(!interuppted) { - if(toInstall.isEmpty()) { + if (!interrupted) { + if (toInstall.isEmpty()) { event = queue.take(); } else { event = queue.poll(POLL_TIME, TimeUnit.MILLISECONDS); } - if(event != null && event.getFeature() !=null) { - processFeatureEvent(event,toInstall); + if (event != null && event.getFeature() != null) { + processFeatureEvent(event, toInstall); } - } else if(toInstall.isEmpty()) { + } else if (toInstall.isEmpty()) { LOG.error("ConfigPushingRunnable - exiting"); return; } } catch (final InterruptedException e) { - LOG.error("ConfigPushingRunnable - interupted"); - interuppted = true; + LOG.error("ConfigPushingRunnable - interrupted"); + interrupted = true; } catch (final Exception e) { LOG.error("Exception while processing features {} event {}", toInstall, event, e); } @@ -60,18 +65,18 @@ public class ConfigPushingRunnable implements Runnable { } protected void processFeatureEvent(final FeatureEvent event, final List toInstall) throws Exception { - if(event.getType() == EventType.FeatureInstalled) { + if (event.getType() == EventType.FeatureInstalled) { toInstall.add(event.getFeature()); - LinkedHashMultimap result = configPusher.pushConfigs(toInstall); + LinkedHashMultimap result = configPusher.pushConfigs(toInstall); toInstall.removeAll(result.keySet()); - } else if(event.getType() == EventType.FeatureUninstalled) { + } else if (event.getType() == EventType.FeatureUninstalled) { toInstall.remove(event.getFeature()); } } - protected void logPushResult(final LinkedHashMultimap results) { - for(Feature f:results.keySet()) { - LOG.info("Pushed configs for feature {} {}",f,results.get(f)); + protected void logPushResult(final LinkedHashMultimap results) { + for (Feature f : results.keySet()) { + LOG.info("Pushed configs for feature {} {}", f, results.get(f)); } } } 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 5d487e0b9c..6f304452a9 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 @@ -9,6 +9,7 @@ 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.Collections; @@ -16,6 +17,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; + import org.apache.karaf.features.Feature; import org.apache.karaf.features.FeaturesService; import org.opendaylight.controller.config.persist.api.ConfigPusher; @@ -46,15 +48,14 @@ public class FeatureConfigPusher { * LinkedHashMultimap to track which configs we pushed for each Feature installation * For future use */ - private final LinkedHashMultimap feature2configs = LinkedHashMultimap.create(); + private final LinkedHashMultimap feature2configs = LinkedHashMultimap + .create(); - /* - * @param p - ConfigPusher to push ConfigSnapshotHolders - */ - public FeatureConfigPusher(final ConfigPusher p, final FeaturesService f) { - pusher = p; - featuresService = f; + public FeatureConfigPusher(final ConfigPusher configPusher, final FeaturesService featuresService) { + pusher = configPusher; + this.featuresService = featuresService; } + /* * Push config files from Features to config subsystem * @param features - list of Features to extract config files from recursively and push @@ -64,8 +65,8 @@ 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(final List features) - throws Exception { + public LinkedHashMultimap pushConfigs( + final List features) throws Exception { LinkedHashMultimap pushedFeatures = LinkedHashMultimap.create(); for (Feature feature : features) { Set configSnapShots = pushConfig(feature); @@ -94,8 +95,8 @@ public class FeatureConfigPusher { // 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()); + LOG.debug("Feature: {}, {} is missing from features service. Skipping", feature.getName(), feature + .getVersion()); return Collections.emptySet(); } @@ -108,47 +109,47 @@ public class FeatureConfigPusher { return configs; } - private boolean isInstalled(final Feature feature) throws InterruptedException { - for (int retries = 0; retries < MAX_RETRIES; retries++) { - try { - List installedFeatures = Arrays.asList(featuresService.listInstalledFeatures()); - if (installedFeatures.contains(feature)) { - return true; - } - - LOG.info("Karaf Feature Service has not yet finished installing feature {}/{} (retry {})", - feature.getName(), feature.getVersion(), retries); - } catch (final Exception e) { - LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e); - } - - TimeUnit.MILLISECONDS.sleep(RETRY_PAUSE_MILLIS); - } - 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 Set pushConfig(final Set configs, - final Feature feature) throws InterruptedException { + final Feature feature) throws InterruptedException { Set configsToPush = new LinkedHashSet<>(configs); configsToPush.removeAll(pushedConfigs); 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())) { + 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); } Set configsPushed = new LinkedHashSet<>(pushedConfigs); configsPushed.retainAll(configs); return configsPushed; } + + @SuppressWarnings("IllegalCatch") + private boolean isInstalled(final Feature feature) throws InterruptedException { + for (int retries = 0; retries < MAX_RETRIES; retries++) { + try { + List installedFeatures = Arrays.asList(featuresService.listInstalledFeatures()); + if (installedFeatures.contains(feature)) { + return true; + } + + LOG.info("Karaf Feature Service has not yet finished installing feature {}/{} (retry {})", feature + .getName(), feature.getVersion(), retries); + } catch (final Exception e) { + LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e); + } + + TimeUnit.MILLISECONDS.sleep(RETRY_PAUSE_MILLIS); + } + 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; + } } diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java index 7107cc994d..f99e763177 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java @@ -11,12 +11,14 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; + import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.SortedSet; + import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; @@ -24,6 +26,7 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.stream.StreamSource; + import org.apache.karaf.features.ConfigFileInfo; import org.apache.karaf.features.Feature; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; @@ -46,8 +49,9 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder { * @param holder - FeatureConfigSnapshotHolder that we * @param feature - new */ - public FeatureConfigSnapshotHolder(final FeatureConfigSnapshotHolder holder, final Feature feature) throws JAXBException, XMLStreamException { - this(holder.fileInfo,holder.getFeature()); + public FeatureConfigSnapshotHolder(final FeatureConfigSnapshotHolder holder, + final Feature feature) throws JAXBException, XMLStreamException { + this(holder.fileInfo, holder.getFeature()); this.featureChain.add(feature); } @@ -57,7 +61,8 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder { * @param fileInfo - ConfigFileInfo to read into the ConfigSnapshot * @param feature - Feature the ConfigFileInfo was attached to */ - public FeatureConfigSnapshotHolder(final ConfigFileInfo fileInfo, final Feature feature) throws JAXBException, XMLStreamException { + public FeatureConfigSnapshotHolder(final ConfigFileInfo fileInfo, + final Feature feature) throws JAXBException, XMLStreamException { Preconditions.checkNotNull(fileInfo); Preconditions.checkNotNull(fileInfo.getFinalname()); Preconditions.checkNotNull(feature); @@ -73,6 +78,7 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder { XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname()))); unmarshalled = (ConfigSnapshot) um.unmarshal(xsr); } + /* * (non-Javadoc) * @see java.lang.Object#hashCode() @@ -83,9 +89,11 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((unmarshalled != null && unmarshalled.getConfigSnapshot() == null) ? 0 : unmarshalled.getConfigSnapshot().hashCode()); + result = prime * result + ((unmarshalled != null && unmarshalled.getConfigSnapshot() == null) ? 0 : + unmarshalled.getConfigSnapshot().hashCode()); return result; } + /* * (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) @@ -103,8 +111,8 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder { if (getClass() != obj.getClass()) { return false; } - FeatureConfigSnapshotHolder fcsh = (FeatureConfigSnapshotHolder)obj; - if(this.unmarshalled.getConfigSnapshot().equals(fcsh.unmarshalled.getConfigSnapshot())) { + FeatureConfigSnapshotHolder fcsh = (FeatureConfigSnapshotHolder) obj; + if (this.unmarshalled.getConfigSnapshot().equals(fcsh.unmarshalled.getConfigSnapshot())) { return true; } return false; @@ -112,15 +120,11 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder { @Override public String toString() { - StringBuilder b = new StringBuilder(); - Path p = Paths.get(fileInfo.getFinalname()); - b.append(p.getFileName()) - .append("(") - .append(getCauseFeature()) - .append(",") - .append(getFeature()) - .append(")"); - return b.toString(); + StringBuilder stringBuilder = new StringBuilder(); + Path path = Paths.get(fileInfo.getFinalname()); + stringBuilder.append(path.getFileName()).append("(").append(getCauseFeature()).append(",").append(getFeature()) + .append(")"); + return stringBuilder.toString(); } @Override diff --git a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureServiceCustomizer.java b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureServiceCustomizer.java index 68ae3d31cb..9e9c26cbf3 100644 --- a/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureServiceCustomizer.java +++ b/opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureServiceCustomizer.java @@ -24,16 +24,18 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class FeatureServiceCustomizer implements ServiceTrackerCustomizer, AutoCloseable { +public class FeatureServiceCustomizer implements ServiceTrackerCustomizer, + AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(FeatureServiceCustomizer.class); private ConfigPusher configPusher = null; private ServiceRegistration registration; - FeatureServiceCustomizer(final ConfigPusher c) { - configPusher = c; + FeatureServiceCustomizer(final ConfigPusher configPusher) { + this.configPusher = configPusher; } @Override + @SuppressWarnings("IllegalCatch") public FeaturesService addingService(final ServiceReference reference) { BundleContext bc = reference.getBundle().getBundleContext(); final FeaturesService featureService = bc.getService(reference); @@ -57,14 +59,12 @@ public class FeatureServiceCustomizer implements ServiceTrackerCustomizer reference, - final FeaturesService service) { + public void modifiedService(final ServiceReference reference, final FeaturesService service) { // we don't care if the properties change } @Override - public void removedService(final ServiceReference reference, - final FeaturesService service) { + public void removedService(final ServiceReference reference, final FeaturesService service) { close(); }