Browse Source

YARN-9595. FPGA plugin: NullPointerException in FpgaNodeResourceUpdateHandler.updateConfiguredResource(). Contributed by Peter Bacsko.

Zhankun Tang 6 years ago
parent
commit
606061aa14

+ 3 - 2
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/fpga/FpgaDiscoverer.java

@@ -124,6 +124,7 @@ public class FpgaDiscoverer {
 
 
     if (allowed == null || allowed.equalsIgnoreCase(
     if (allowed == null || allowed.equalsIgnoreCase(
         YarnConfiguration.AUTOMATICALLY_DISCOVER_GPU_DEVICES)) {
         YarnConfiguration.AUTOMATICALLY_DISCOVER_GPU_DEVICES)) {
+      currentFpgaInfo = ImmutableList.copyOf(list);
       return list;
       return list;
     } else if (allowed.matches("(\\d,)*\\d")){
     } else if (allowed.matches("(\\d,)*\\d")){
       Set<String> minors = Sets.newHashSet(allowed.split(","));
       Set<String> minors = Sets.newHashSet(allowed.split(","));
@@ -134,6 +135,8 @@ public class FpgaDiscoverer {
         .filter(dev -> minors.contains(String.valueOf(dev.getMinor())))
         .filter(dev -> minors.contains(String.valueOf(dev.getMinor())))
         .collect(Collectors.toList());
         .collect(Collectors.toList());
 
 
+      currentFpgaInfo = ImmutableList.copyOf(list);
+
       // if the count of user configured is still larger than actual
       // if the count of user configured is still larger than actual
       if (list.size() != minors.size()) {
       if (list.size() != minors.size()) {
         LOG.warn("We continue although there're mistakes in user's configuration " +
         LOG.warn("We continue although there're mistakes in user's configuration " +
@@ -145,8 +148,6 @@ public class FpgaDiscoverer {
           YarnConfiguration.NM_FPGA_ALLOWED_DEVICES + ":\"" + allowed + "\"");
           YarnConfiguration.NM_FPGA_ALLOWED_DEVICES + ":\"" + allowed + "\"");
     }
     }
 
 
-    currentFpgaInfo = ImmutableList.copyOf(list);
-
     return list;
     return list;
   }
   }
 
 

+ 33 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/fpga/TestFpgaDiscoverer.java

@@ -288,6 +288,39 @@ public class TestFpgaDiscoverer {
     }
     }
   }
   }
 
 
+  @Test
+  public void testCurrentFpgaInfoWhenAllDevicesAreAllowed()
+      throws YarnException {
+    conf.set(YarnConfiguration.NM_FPGA_AVAILABLE_DEVICES,
+        "acl0/243:0,acl1/244:1");
+
+    fpgaDiscoverer.initialize(conf);
+    List<FpgaDevice> devices = fpgaDiscoverer.discover();
+    List<FpgaDevice> currentFpgaInfo = fpgaDiscoverer.getCurrentFpgaInfo();
+
+    assertEquals("Devices", devices, currentFpgaInfo);
+  }
+
+  @Test
+  public void testCurrentFpgaInfoWhenAllowedDevicesDefined()
+      throws YarnException {
+    conf.set(YarnConfiguration.NM_FPGA_AVAILABLE_DEVICES,
+        "acl0/243:0,acl1/244:1");
+    conf.set(YarnConfiguration.NM_FPGA_ALLOWED_DEVICES, "0");
+
+    fpgaDiscoverer.initialize(conf);
+    List<FpgaDevice> devices = fpgaDiscoverer.discover();
+    List<FpgaDevice> currentFpgaInfo = fpgaDiscoverer.getCurrentFpgaInfo();
+
+    assertEquals("Devices", devices, currentFpgaInfo);
+    assertEquals("List of devices", 1, currentFpgaInfo.size());
+
+    FpgaDevice device = currentFpgaInfo.get(0);
+    assertEquals("Device id", "acl0", device.getAliasDevName());
+    assertEquals("Minor number", 0, device.getMinor());
+    assertEquals("Major", 243, device.getMajor());
+  }
+
   private IntelFpgaOpenclPlugin.InnerShellExecutor mockPuginShell() {
   private IntelFpgaOpenclPlugin.InnerShellExecutor mockPuginShell() {
     IntelFpgaOpenclPlugin.InnerShellExecutor shell = mock(IntelFpgaOpenclPlugin.InnerShellExecutor.class);
     IntelFpgaOpenclPlugin.InnerShellExecutor shell = mock(IntelFpgaOpenclPlugin.InnerShellExecutor.class);
     when(shell.runDiagnose(anyString(),anyInt())).thenReturn("");
     when(shell.runDiagnose(anyString(),anyInt())).thenReturn("");