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

This commit is contained in:
Zhankun Tang 2019-06-04 09:56:59 +08:00
parent 277e9a835b
commit 606061aa14
2 changed files with 36 additions and 2 deletions

View File

@ -124,6 +124,7 @@ public List<FpgaDevice> discover()
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 List<FpgaDevice> discover()
.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 List<FpgaDevice> discover()
YarnConfiguration.NM_FPGA_ALLOWED_DEVICES + ":\"" + allowed + "\""); YarnConfiguration.NM_FPGA_ALLOWED_DEVICES + ":\"" + allowed + "\"");
} }
currentFpgaInfo = ImmutableList.copyOf(list);
return list; return list;
} }

View File

@ -288,6 +288,39 @@ public void testDiscoveryWhenExternalScriptCannotBeExecuted()
} }
} }
@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("");