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 f437659..eec7882 100644 (file)
@@ -14,6 +14,7 @@ import java.io.File;
 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;
@@ -57,8 +58,8 @@ public class AbstractFeatureWrapper implements Feature {
      * 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())) {
index 672784a..a9d0685 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 java.util.Set;
 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
      */
-    public LinkedHashSet <? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
+    public Set<? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
         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(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 {
-                        ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi,featuresService);
+                        ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi, featuresService);
                         childFeatures.add(wrappedFeature);
                     }
                 }
@@ -72,8 +73,8 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
     }
 
     @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());
index e94d615..cfdad56 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);
index f11da07..50757fb 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.Set;
 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).
      */
-    LinkedHashSet<FeatureConfigSnapshotHolder> pushedConfigs = new LinkedHashSet<>();
+    Set<FeatureConfigSnapshotHolder> pushedConfigs = new LinkedHashSet<>();
     /*
      * 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) {
 
 
-            LinkedHashSet<FeatureConfigSnapshotHolder> configSnapShots = pushConfig(feature);
+            Set<FeatureConfigSnapshotHolder> configSnapShots = pushConfig(feature);
             if (!configSnapShots.isEmpty()) {
                 pushedFeatures.putAll(feature, configSnapShots);
             }
@@ -72,8 +73,8 @@ public class FeatureConfigPusher {
         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) {
@@ -91,7 +92,7 @@ public class FeatureConfigPusher {
     }
 
     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)) {
@@ -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) {
-                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);
@@ -117,8 +113,9 @@ public class FeatureConfigPusher {
         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()) {
 
@@ -134,7 +131,7 @@ public class FeatureConfigPusher {
 
             pushedConfigs.addAll(configsToPush);
         }
-        LinkedHashSet<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
+        Set<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
         configsPushed.retainAll(configs);
         return configsPushed;
     }
index 1352117..70f7366 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())));
-        unmarshalled = ((ConfigSnapshot) um.unmarshal(xsr));
+        unmarshalled = (ConfigSnapshot) um.unmarshal(xsr);
     }
     /*
      * (non-Javadoc)
index c941e89..5ce58ef 100644 (file)
@@ -23,14 +23,12 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
 public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>, AutoCloseable {
     private ConfigPusher configPusher = null;
-    private ConfigFeaturesListener configFeaturesListener = null;
     private ServiceRegistration<?> registration;
 
     FeatureServiceCustomizer(ConfigPusher c) {
         configPusher = c;
     }
 
-
     @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;
     }
@@ -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
-
     }
 
     @Override
@@ -75,5 +72,4 @@ public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<Featur
             registration = null;
         }
     }
-
 }