Fix feature config pusher warning 85/44185/2
authorTom Pantelis <tpanteli@brocade.com>
Wed, 17 Aug 2016 17:12:31 +0000 (13:12 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Mon, 22 Aug 2016 18:41:21 +0000 (18:41 +0000)
The feature config pusher assumes config files installed by features
that have XML extension are CSS files and tries to parse them. On failure
it prints a warning but ignores it and moves on. Up till now we've only
had CSS XML files but we now have XML files related to the
clustered-app-config. To avoid the warning I added an additional check
for "opendaylight/karaf" present in the file path. To be complete we would
open the file and inspect the first element but I didn't think that was worth
the effort since all current CSS files are put under opendaylight/karaf and
ODL is moving away from CSS.

Change-Id: I1f0dcda9efa14db330a72e455fe4756c8fbfcaab
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/AbstractFeatureWrapper.java

index 4f598aae80e2ac2678902e8367f3bce9fb7950ba..f95f2b89fd07a8e95c6b2051def6321ef6b4964d 100644 (file)
@@ -10,6 +10,7 @@ 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.util.LinkedHashSet;
 import java.util.List;
 import javax.xml.bind.JAXBException;
@@ -32,6 +33,7 @@ import org.slf4j.LoggerFactory;
 public class AbstractFeatureWrapper implements Feature {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureWrapper.class);
 
+    private static final String CONFIG_FILE_PATH_SUFFIX = "opendaylight" + File.separator + "karaf";
     protected static final String CONFIG_FILE_SUFFIX = "xml";
 
     protected Feature feature = null;
@@ -56,7 +58,7 @@ public class AbstractFeatureWrapper implements Feature {
         final LinkedHashSet <FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
         for(final ConfigFileInfo c: getConfigurationFiles()) {
             // Skip non xml files
-            if(Files.getFileExtension(c.getFinalname()).equals(CONFIG_FILE_SUFFIX)) {
+            if(isConfigXMLFile(c.getFinalname())) {
                 final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(c);
                 if(featureConfigSnapshotHolder.isPresent()) {
                     snapShotHolders.add(featureConfigSnapshotHolder.get());
@@ -66,6 +68,12 @@ public class AbstractFeatureWrapper implements Feature {
         return snapShotHolders;
     }
 
+    private static boolean isConfigXMLFile(String fullName) {
+        String path = new File(fullName).getPath();
+        return path.contains(CONFIG_FILE_PATH_SUFFIX) &&
+                Files.getFileExtension(fullName).equals(CONFIG_FILE_SUFFIX);
+    }
+
     protected Optional<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolder(final ConfigFileInfo c) {
         try {
             return Optional.of(new FeatureConfigSnapshotHolder(c, this));
@@ -86,7 +94,7 @@ public class AbstractFeatureWrapper implements Feature {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((feature == null) ? 0 : feature.hashCode());
+        result = prime * result + (feature == null ? 0 : feature.hashCode());
         return result;
     }
 
@@ -252,4 +260,4 @@ public class AbstractFeatureWrapper implements Feature {
         return feature.getRegion();
     }
 
-}
\ No newline at end of file
+}