diff --git a/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 b/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 index 185effaa6c1..180a011b61f 100644 --- a/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 +++ b/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( YarnConfiguration.AUTOMATICALLY_DISCOVER_GPU_DEVICES)) { + currentFpgaInfo = ImmutableList.copyOf(list); return list; } else if (allowed.matches("(\\d,)*\\d")){ Set minors = Sets.newHashSet(allowed.split(",")); @@ -134,6 +135,8 @@ public class FpgaDiscoverer { .filter(dev -> minors.contains(String.valueOf(dev.getMinor()))) .collect(Collectors.toList()); + currentFpgaInfo = ImmutableList.copyOf(list); + // if the count of user configured is still larger than actual if (list.size() != minors.size()) { 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 + "\""); } - currentFpgaInfo = ImmutableList.copyOf(list); - return list; } diff --git a/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 b/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 index 92e9db20704..6f570c6f63d 100644 --- a/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 +++ b/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 devices = fpgaDiscoverer.discover(); + List 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 devices = fpgaDiscoverer.discover(); + List 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() { IntelFpgaOpenclPlugin.InnerShellExecutor shell = mock(IntelFpgaOpenclPlugin.InnerShellExecutor.class); when(shell.runDiagnose(anyString(),anyInt())).thenReturn("");