Removed sonar warnings. 06/46706/5
authorDana Kutenicsova <dana.kutenics@gmail.com>
Wed, 5 Oct 2016 20:38:38 +0000 (22:38 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 15 Nov 2016 13:40:54 +0000 (13:40 +0000)
Change-Id: I53136e343bd54e9f0a687044037bc61deebb05b4
Signed-off-by: Dana Kutenicsova <dana.kutenics@gmail.com>
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/AbstractFeatureWrapper.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ChildAwareFeatureWrapper.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPushingRunnable.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigPusher.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureServiceCustomizer.java

index f43765901d15ed60b1ac9a364a1ab4f92b8749e3..eec788252932435afe4b4607968364a78ac33028 100644 (file)
@@ -14,6 +14,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.io.FileInputStream;
 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.stream.XMLStreamException;
 import javax.xml.bind.JAXBException;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.stream.XMLStreamException;
@@ -57,8 +58,8 @@ public class AbstractFeatureWrapper implements Feature {
      * Get FeatureConfigSnapshotHolders appropriate to feed to the config subsystem
      * from the underlying Feature Config files
      */
      * Get FeatureConfigSnapshotHolders appropriate to feed to the config subsystem
      * from the underlying Feature Config files
      */
-    public LinkedHashSet<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
-        final LinkedHashSet <FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
+    public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
+        final Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
         for(final ConfigFileInfo c: getConfigurationFiles()) {
             // Skip non config snapshot XML files
             if(isConfigSnapshot(c.getFinalname())) {
         for(final ConfigFileInfo c: getConfigurationFiles()) {
             // Skip non config snapshot XML files
             if(isConfigSnapshot(c.getFinalname())) {
index 672784a54b3fc520a7c3613c90037a2235dcac87..a9d06853a27b9dfa4aa8bf4a6e04984e9d130b3f 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.util.LinkedHashSet;
 import java.util.List;
 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;
 import org.apache.felix.utils.version.VersionRange;
 import org.apache.felix.utils.version.VersionTable;
 import org.apache.karaf.features.Dependency;
@@ -52,17 +53,17 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
      * Get FeatureConfigSnapshotHolders appropriate to feed to the config subsystem
      * from the underlying Feature Config files and those of its children recursively
      */
      * Get FeatureConfigSnapshotHolders appropriate to feed to the config subsystem
      * from the underlying Feature Config files and those of its children recursively
      */
-    public LinkedHashSet <? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
+    public Set<? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
         List<Dependency> dependencies = feature.getDependencies();
         List<Dependency> dependencies = feature.getDependencies();
-        LinkedHashSet <ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
+        Set<ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
         if(dependencies != null) {
             for(Dependency dependency: dependencies) {
                 Feature fi = extractFeatureFromDependency(dependency);
         if(dependencies != null) {
             for(Dependency dependency: dependencies) {
                 Feature fi = extractFeatureFromDependency(dependency);
-                if(fi != null) {
-                    if(featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
+                if (fi != null) {
+                    if (featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
                         LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi.getVersion());
                     } else {
                         LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi.getVersion());
                     } else {
-                        ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi,featuresService);
+                        ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi, featuresService);
                         childFeatures.add(wrappedFeature);
                     }
                 }
                         childFeatures.add(wrappedFeature);
                     }
                 }
@@ -72,8 +73,8 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
     }
 
     @Override
     }
 
     @Override
-    public LinkedHashSet<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
-        LinkedHashSet <FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
+    public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
+        Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
         for(ChildAwareFeatureWrapper c: getChildFeatures()) {
             for(FeatureConfigSnapshotHolder h: c.getFeatureConfigSnapshotHolders()) {
                 final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(h.getFileInfo());
         for(ChildAwareFeatureWrapper c: getChildFeatures()) {
             for(FeatureConfigSnapshotHolder h: c.getFeatureConfigSnapshotHolders()) {
                 final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(h.getFileInfo());
index e94d6155c9b60bef56337ecf32e66981e86c5154..cfdad560945f29cac2549274d09be37d9c704854 100644 (file)
@@ -59,7 +59,7 @@ public class ConfigPushingRunnable implements Runnable {
         }
     }
 
         }
     }
 
-    protected void processFeatureEvent(FeatureEvent event, List<Feature> toInstall) throws InterruptedException, Exception {
+    protected void processFeatureEvent(FeatureEvent event, List<Feature> toInstall) throws Exception {
         if(event.getType() == EventType.FeatureInstalled) {
             toInstall.add(event.getFeature());
             LinkedHashMultimap<Feature,FeatureConfigSnapshotHolder> result = configPusher.pushConfigs(toInstall);
         if(event.getType() == EventType.FeatureInstalled) {
             toInstall.add(event.getFeature());
             LinkedHashMultimap<Feature,FeatureConfigSnapshotHolder> result = configPusher.pushConfigs(toInstall);
index f11da079c6da920bebf75ddc98800be2ae8de8b6..50757fb7b90961df577d1dc1d7675bbf56ea8bb5 100644 (file)
@@ -13,6 +13,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashSet;
 import java.util.List;
 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.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeaturesService;
 import org.opendaylight.controller.config.persist.api.ConfigPusher;
@@ -36,7 +37,7 @@ public class FeatureConfigPusher {
      * chains.  Also, preserves the *original* Feature chain for which we pushed the config.
      * (which is handy for logging).
      */
      * chains.  Also, preserves the *original* Feature chain for which we pushed the config.
      * (which is handy for logging).
      */
-    LinkedHashSet<FeatureConfigSnapshotHolder> pushedConfigs = new LinkedHashSet<>();
+    Set<FeatureConfigSnapshotHolder> pushedConfigs = new LinkedHashSet<>();
     /*
      * LinkedHashMultimap to track which configs we pushed for each Feature installation
      * For future use
     /*
      * LinkedHashMultimap to track which configs we pushed for each Feature installation
      * For future use
@@ -64,7 +65,7 @@ public class FeatureConfigPusher {
         for (Feature feature : features) {
 
 
         for (Feature feature : features) {
 
 
-            LinkedHashSet<FeatureConfigSnapshotHolder> configSnapShots = pushConfig(feature);
+            Set<FeatureConfigSnapshotHolder> configSnapShots = pushConfig(feature);
             if (!configSnapShots.isEmpty()) {
                 pushedFeatures.putAll(feature, configSnapShots);
             }
             if (!configSnapShots.isEmpty()) {
                 pushedFeatures.putAll(feature, configSnapShots);
             }
@@ -72,8 +73,8 @@ public class FeatureConfigPusher {
         return pushedFeatures;
     }
 
         return pushedFeatures;
     }
 
-    private LinkedHashSet<FeatureConfigSnapshotHolder> pushConfig(final Feature feature) throws Exception {
-        LinkedHashSet<FeatureConfigSnapshotHolder> configs = new LinkedHashSet<>();
+    private Set<FeatureConfigSnapshotHolder> pushConfig(final Feature feature) throws Exception {
+        Set<FeatureConfigSnapshotHolder> configs = new LinkedHashSet<>();
         if(isInstalled(feature)) {
             // 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) {
         if(isInstalled(feature)) {
             // 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) {
@@ -91,7 +92,7 @@ public class FeatureConfigPusher {
     }
 
     private boolean isInstalled(final Feature feature) {
     }
 
     private boolean isInstalled(final Feature feature) {
-        for(int retries=0;retries<MAX_RETRIES;retries++) {
+        for (int retries = 0; retries < MAX_RETRIES; retries++) {
             try {
                 List<Feature> installedFeatures = Arrays.asList(featuresService.listInstalledFeatures());
                 if(installedFeatures.contains(feature)) {
             try {
                 List<Feature> installedFeatures = Arrays.asList(featuresService.listInstalledFeatures());
                 if(installedFeatures.contains(feature)) {
@@ -100,12 +101,7 @@ public class FeatureConfigPusher {
                     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 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;
-                }
+                LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e);
             }
             try {
                 Thread.sleep(RETRY_PAUSE_MILLIS);
             }
             try {
                 Thread.sleep(RETRY_PAUSE_MILLIS);
@@ -117,8 +113,9 @@ public class FeatureConfigPusher {
         return false;
     }
 
         return false;
     }
 
-    private LinkedHashSet<FeatureConfigSnapshotHolder> pushConfig(final LinkedHashSet<FeatureConfigSnapshotHolder> configs, final Feature feature) throws InterruptedException {
-        LinkedHashSet<FeatureConfigSnapshotHolder> configsToPush = new LinkedHashSet<>(configs);
+    private Set<FeatureConfigSnapshotHolder> pushConfig(final Set<FeatureConfigSnapshotHolder> configs, final Feature feature)
+            throws InterruptedException {
+        Set<FeatureConfigSnapshotHolder> configsToPush = new LinkedHashSet<>(configs);
         configsToPush.removeAll(pushedConfigs);
         if (!configsToPush.isEmpty()) {
 
         configsToPush.removeAll(pushedConfigs);
         if (!configsToPush.isEmpty()) {
 
@@ -134,7 +131,7 @@ public class FeatureConfigPusher {
 
             pushedConfigs.addAll(configsToPush);
         }
 
             pushedConfigs.addAll(configsToPush);
         }
-        LinkedHashSet<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
+        Set<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
         configsPushed.retainAll(configs);
         return configsPushed;
     }
         configsPushed.retainAll(configs);
         return configsPushed;
     }
index 135211727add6ad076fd56f7dcb66f3bee9c6b29..70f736689577d6d7b3dbc655372d318873eec7d6 100644 (file)
@@ -71,7 +71,7 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
         xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
 
         XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname())));
         xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
 
         XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname())));
-        unmarshalled = ((ConfigSnapshot) um.unmarshal(xsr));
+        unmarshalled = (ConfigSnapshot) um.unmarshal(xsr);
     }
     /*
      * (non-Javadoc)
     }
     /*
      * (non-Javadoc)
index c941e894359f0560044136db0f40c78972c91c12..5ce58ef0532ce1805d5be6d9d2850a4bed8003d2 100644 (file)
@@ -23,14 +23,12 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
 public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>, AutoCloseable {
     private ConfigPusher configPusher = null;
 
 public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>, AutoCloseable {
     private ConfigPusher configPusher = null;
-    private ConfigFeaturesListener configFeaturesListener = null;
     private ServiceRegistration<?> registration;
 
     FeatureServiceCustomizer(ConfigPusher c) {
         configPusher = c;
     }
 
     private ServiceRegistration<?> registration;
 
     FeatureServiceCustomizer(ConfigPusher c) {
         configPusher = c;
     }
 
-
     @Override
     public FeaturesService addingService(ServiceReference<FeaturesService> reference) {
         BundleContext bc = reference.getBundle().getBundleContext();
     @Override
     public FeaturesService addingService(ServiceReference<FeaturesService> reference) {
         BundleContext bc = reference.getBundle().getBundleContext();
@@ -50,7 +48,7 @@ public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<Featur
                 }
             });
         }
                 }
             });
         }
-        configFeaturesListener = new ConfigFeaturesListener(configPusher,featureService);
+        ConfigFeaturesListener configFeaturesListener = new ConfigFeaturesListener(configPusher, featureService);
         registration = bc.registerService(FeaturesListener.class.getCanonicalName(), configFeaturesListener, null);
         return featureService;
     }
         registration = bc.registerService(FeaturesListener.class.getCanonicalName(), configFeaturesListener, null);
         return featureService;
     }
@@ -59,7 +57,6 @@ public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<Featur
     public void modifiedService(ServiceReference<FeaturesService> reference,
             FeaturesService service) {
         // we don't care if the properties change
     public void modifiedService(ServiceReference<FeaturesService> reference,
             FeaturesService service) {
         // we don't care if the properties change
-
     }
 
     @Override
     }
 
     @Override
@@ -75,5 +72,4 @@ public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<Featur
             registration = null;
         }
     }
             registration = null;
         }
     }
-
 }
 }