Removed sonar warnings.
[controller.git] / opendaylight / config / config-persister-feature-adapter / src / main / java / org / opendaylight / controller / configpusherfeature / internal / ChildAwareFeatureWrapper.java
index 2bff9069007baa515c8f175740a79fe5e1b325a4..a9d06853a27b9dfa4aa8bf4a6e04984e9d130b3f 100644 (file)
@@ -7,11 +7,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 javax.xml.bind.JAXBException;
-
+import java.util.Set;
 import org.apache.felix.utils.version.VersionRange;
 import org.apache.felix.utils.version.VersionTable;
 import org.apache.karaf.features.Dependency;
@@ -21,8 +21,6 @@ import org.osgi.framework.Version;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-
 /*
  * Wrap a Feature for the purposes of extracting the FeatureConfigSnapshotHolders from
  * its underlying ConfigFileInfo's and those of its children recursively
@@ -30,7 +28,7 @@ import com.google.common.base.Preconditions;
  * Delegates the the contained feature and provides additional methods.
  */
 public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements Feature {
-    private static final Logger LOGGER = LoggerFactory.getLogger(ChildAwareFeatureWrapper.class);
+    private static final Logger LOG = LoggerFactory.getLogger(ChildAwareFeatureWrapper.class);
     private FeaturesService featuresService= null;
 
     protected ChildAwareFeatureWrapper(Feature f) {
@@ -55,31 +53,33 @@ 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<ChildAwareFeatureWrapper>();
+        Set<ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
         if(dependencies != null) {
             for(Dependency dependency: dependencies) {
                 Feature fi = extractFeatureFromDependency(dependency);
-                if(fi != null){
-                    ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi,featuresService);
-                    childFeatures.add(wrappedFeature);
+                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);
+                        childFeatures.add(wrappedFeature);
+                    }
                 }
             }
         }
         return childFeatures;
     }
 
-    public LinkedHashSet<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
-        LinkedHashSet <FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<FeatureConfigSnapshotHolder>();
+    @Override
+    public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
+        Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
         for(ChildAwareFeatureWrapper c: getChildFeatures()) {
             for(FeatureConfigSnapshotHolder h: c.getFeatureConfigSnapshotHolders()) {
-                FeatureConfigSnapshotHolder f;
-                try {
-                    f = new FeatureConfigSnapshotHolder(h,this);
-                    snapShotHolders.add(f);
-                } catch (JAXBException e) {
-                    LOGGER.debug("{} is not a config subsystem config file",h.getFileInfo().getFinalname());
+                final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(h.getFileInfo());
+                if(featureConfigSnapshotHolder.isPresent()) {
+                    snapShotHolders.add(featureConfigSnapshotHolder.get());
                 }
             }
         }
@@ -97,8 +97,8 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
                 Version v = VersionTable.getVersion(f.getVersion());
                 if (range.contains(v) &&
                     (fi == null || VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0)) {
-                        fi = f;
-                        break;
+                    fi = f;
+                    break;
                 }
             }
         }