Merge "BUG 1839 - HTTP delete of non existing data"
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / mapping / ModuleInfoBundleTracker.java
index 7680f72612cd40468f3758d8030b55b6a6908afc..c5be03ca4dc1948fe776ef30b5d171ec0667ce83 100644 (file)
@@ -17,8 +17,7 @@ import java.util.List;
 
 import org.apache.commons.io.IOUtils;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
-import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
-import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
+import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
 import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.osgi.framework.Bundle;
@@ -28,50 +27,48 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Tracks bundles and attempts to retrieve YangModuleInfo.
+ * Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed into ModuleInfoRegistry
  */
 public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
 
-    private static final Logger logger = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
-    public static final String GET_MODULE_INFO_METHOD = "getModuleInfo";
+    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
 
     public static final String MODULE_INFO_PROVIDER_PATH_PREFIX = "META-INF/services/";
 
-    private final ModuleInfoBackedContext moduleInfoLoadingStrategy = ModuleInfoBackedContext.create();
 
-    public GeneratedClassLoadingStrategy getModuleInfoLoadingStrategy() {
-        return moduleInfoLoadingStrategy;
+    private final ModuleInfoRegistry moduleInfoRegistry;
+
+    public ModuleInfoBundleTracker(ModuleInfoRegistry moduleInfoRegistry) {
+        this.moduleInfoRegistry = moduleInfoRegistry;
     }
 
     @Override
     public Collection<ObjectRegistration<YangModuleInfo>> addingBundle(Bundle bundle, BundleEvent event) {
         URL resource = bundle.getEntry(MODULE_INFO_PROVIDER_PATH_PREFIX + YangModelBindingProvider.class.getName());
-
+        LOGGER.debug("Got addingBundle({}) with YangModelBindingProvider resource {}", bundle, resource);
         if(resource==null) {
             return null;
         }
-
         List<ObjectRegistration<YangModuleInfo>> registrations = new LinkedList<>();
 
         try (InputStream inputStream = resource.openStream()) {
             List<String> lines = IOUtils.readLines(inputStream);
             for (String moduleInfoName : lines) {
+                LOGGER.trace("Retrieve ModuleInfo({}, {})", moduleInfoName, bundle);
                 YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle);
-                registrations.add(moduleInfoLoadingStrategy.registerModuleInfo(moduleInfo));
+                registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
             }
 
-
         } catch (Exception e) {
-            logger.error("Error while reading {}", resource, e);
+            LOGGER.error("Error while reading {}", resource, e);
             throw new RuntimeException(e);
         }
-
+        LOGGER.trace("Got following registrations {}", registrations);
         return registrations;
     }
 
     @Override
     public void modifiedBundle(Bundle bundle, BundleEvent event, Collection<ObjectRegistration<YangModuleInfo>> object) {
-        // NOOP
     }
 
     @Override
@@ -105,7 +102,7 @@ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Co
             errorMessage = logMessage("Could not instantiate {} in bundle {}, reason {}", moduleInfoClass, bundle, e);
             throw new IllegalStateException(errorMessage, e);
         } catch (IllegalAccessException e) {
-            errorMessage = logMessage("Illegal access during instatiation of class {} in bundle {}, reason {}",
+            errorMessage = logMessage("Illegal access during instantiation of class {} in bundle {}, reason {}",
                     moduleInfoClass, bundle, e);
             throw new IllegalStateException(errorMessage, e);
         }
@@ -114,7 +111,7 @@ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Co
         } catch (NoClassDefFoundError e) {
 
 
-            logger.error("Error while executing getModuleInfo on {}", instance, e);
+            LOGGER.error("Error while executing getModuleInfo on {}", instance, e);
             throw e;
         }
     }
@@ -123,13 +120,13 @@ public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Co
         try {
             return bundle.loadClass(moduleInfoClass);
         } catch (ClassNotFoundException e) {
-            String errorMessage = logMessage("Could not find class {} in bunde {}, reason {}", moduleInfoClass, bundle, e);
+            String errorMessage = logMessage("Could not find class {} in bundle {}, reason {}", moduleInfoClass, bundle, e);
             throw new IllegalStateException(errorMessage);
         }
     }
 
     public static String logMessage(String slfMessage, Object... params) {
-        logger.info(slfMessage, params);
+        LOGGER.info(slfMessage, params);
         String formatMessage = slfMessage.replaceAll("\\{\\}", "%s");
         return format(formatMessage, params);
     }