hadoop-yetus commented on a change in pull request #1178: YARN-9680 Code 
cleanup in ResourcePluginManager init methods
URL: https://github.com/apache/hadoop/pull/1178#discussion_r311979089
 
 

 ##########
 File path: 
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/ResourcePluginManager.java
 ##########
 @@ -70,80 +71,94 @@ public synchronized void initialize(Context context)
     Configuration conf = context.getConf();
     Map<String, ResourcePlugin> pluginMap = new HashMap<>();
 
+    getPlugins(context, pluginMap);
+    initializePluggableDevicePlugins(context, conf, pluginMap);
+
+    configuredPlugins = Collections.unmodifiableMap(pluginMap);
+  }
+
+  private void getPlugins(Context context,
+      Map<String, ResourcePlugin> pluginMap) throws YarnException {
+    Configuration conf = context.getConf();
     String[] plugins = conf.getStrings(YarnConfiguration.NM_RESOURCE_PLUGINS);
+
     if (plugins == null || plugins.length == 0) {
       LOG.info("No Resource plugins found from configuration!");
+      return;
     }
     LOG.info("Found Resource plugins from configuration: "
         + Arrays.toString(plugins));
+    
+    for (String resourceName : plugins) {
+      resourceName = resourceName.trim();
+      if (!SUPPORTED_RESOURCE_PLUGINS.contains(resourceName)) {
+        String msg =
+            "Trying to initialize resource plugin with name=" + resourceName
+                + ", it is not supported, list of supported plugins:"
+                + StringUtils.join(",", SUPPORTED_RESOURCE_PLUGINS);
+        LOG.error(msg);
+        throw new YarnException(msg);
+      }
 
-    if (plugins != null) {
-      // Initialize each plugins
-      for (String resourceName : plugins) {
-        resourceName = resourceName.trim();
-        if (!SUPPORTED_RESOURCE_PLUGINS.contains(resourceName)) {
-          String msg =
-              "Trying to initialize resource plugin with name=" + resourceName
-                  + ", it is not supported, list of supported plugins:"
-                  + StringUtils.join(",", SUPPORTED_RESOURCE_PLUGINS);
-          LOG.error(msg);
-          throw new YarnException(msg);
-        }
-
-        if (pluginMap.containsKey(resourceName)) {
-          LOG.warn("Ignoring duplicate Resource plugin definition: " +
-              resourceName);
-          continue;
-        }
-
-        ResourcePlugin plugin = null;
-        if (resourceName.equals(GPU_URI)) {
-          final GpuDiscoverer gpuDiscoverer = new GpuDiscoverer();
-          final GpuNodeResourceUpdateHandler updateHandler =
-              new GpuNodeResourceUpdateHandler(gpuDiscoverer);
-          plugin = new GpuResourcePlugin(updateHandler, gpuDiscoverer);
-        } else if (resourceName.equals(FPGA_URI)) {
-          plugin = new FpgaResourcePlugin();
-        }
+      if (pluginMap.containsKey(resourceName)) {
+        LOG.warn("Ignoring duplicate Resource plugin definition: " +
+            resourceName);
+        continue;
+      }
 
-        if (plugin == null) {
-          throw new YarnException(
-              "This shouldn't happen, plugin=" + resourceName
-                  + " should be loaded and initialized");
-        }
-        plugin.initialize(context);
-        LOG.info("Initialized plugin {}", plugin);
-        pluginMap.put(resourceName, plugin);
+      ResourcePlugin plugin = null;
+      if (resourceName.equals(GPU_URI)) {
+        final GpuDiscoverer gpuDiscoverer = new GpuDiscoverer();
+        final GpuNodeResourceUpdateHandler updateHandler =
+            new GpuNodeResourceUpdateHandler(gpuDiscoverer);
+        plugin = new GpuResourcePlugin(updateHandler, gpuDiscoverer);
+      } else if (resourceName.equals(FPGA_URI)) {
+        plugin = new FpgaResourcePlugin();
       }
+      if (plugin == null) {
+        throw new YarnException(
+            "This shouldn't happen, plugin=" + resourceName
+                + " should be loaded and initialized");
+      }
+      plugin.initialize(context);
+      LOG.info("Initialized plugin {}", plugin);
+      pluginMap.put(resourceName, plugin);
     }
+  }
+    
+  public void initializePluggableDevicePlugins(Context context,
 
 Review comment:
   whitespace:end of line
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to