Skip to content

Commit 95fc38f

Browse files
Adam Antalszilard-nemeth
authored andcommitted
YARN-9375. Use Configured in GpuDiscoverer and FpgaDiscoverer (#1131)
Contributed by Adam Antal
1 parent e872ceb commit 95fc38f

File tree

2 files changed

+12
-17
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin

2 files changed

+12
-17
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.stream.Collectors;
2929

3030
import org.apache.hadoop.conf.Configuration;
31+
import org.apache.hadoop.conf.Configured;
3132
import org.apache.hadoop.fs.FileUtil;
3233
import org.apache.hadoop.util.Shell.ShellCommandExecutor;
3334
import org.apache.hadoop.yarn.conf.YarnConfiguration;
@@ -46,11 +47,10 @@
4647
import com.google.common.collect.ImmutableList;
4748
import com.google.common.collect.Sets;
4849

49-
public class FpgaDiscoverer {
50+
public class FpgaDiscoverer extends Configured {
5051
private static final Logger LOG = LoggerFactory.getLogger(
5152
FpgaDiscoverer.class);
5253

53-
private Configuration conf = null;
5454
private AbstractFpgaVendorPlugin plugin = null;
5555
private List<FpgaResourceAllocator.FpgaDevice> currentFpgaInfo = null;
5656

@@ -64,11 +64,6 @@ void setScriptRunner(Function<String, Optional<String>> scriptRunner) {
6464
this.scriptRunner = scriptRunner;
6565
}
6666

67-
@VisibleForTesting
68-
public void setConf(Configuration configuration) {
69-
this.conf = configuration;
70-
}
71-
7267
public List<FpgaDevice> getCurrentFpgaInfo() {
7368
return currentFpgaInfo;
7469
}
@@ -82,7 +77,7 @@ public boolean diagnose() {
8277
}
8378

8479
public void initialize(Configuration config) throws YarnException {
85-
this.conf = config;
80+
setConf(config);
8681
this.plugin.initPlugin(config);
8782
// Try to diagnose FPGA
8883
LOG.info("Trying to diagnose FPGA information ...");
@@ -100,11 +95,11 @@ public void initialize(Configuration config) throws YarnException {
10095
public List<FpgaDevice> discover()
10196
throws ResourceHandlerException {
10297
List<FpgaDevice> list;
103-
String allowed = this.conf.get(YarnConfiguration.NM_FPGA_ALLOWED_DEVICES);
98+
String allowed = getConf().get(YarnConfiguration.NM_FPGA_ALLOWED_DEVICES);
10499

105-
String availableDevices = conf.get(
100+
String availableDevices = getConf().get(
106101
YarnConfiguration.NM_FPGA_AVAILABLE_DEVICES);
107-
String discoveryScript = conf.get(
102+
String discoveryScript = getConf().get(
108103
YarnConfiguration.NM_FPGA_DEVICE_DISCOVERY_SCRIPT);
109104

110105
FPGADiscoveryStrategy discoveryStrategy;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/resourceplugin/gpu/GpuDiscoverer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.hadoop.classification.InterfaceAudience;
2626
import org.apache.hadoop.classification.InterfaceStability;
2727
import org.apache.hadoop.conf.Configuration;
28+
import org.apache.hadoop.conf.Configured;
2829
import org.apache.hadoop.util.Shell;
2930
import org.apache.hadoop.yarn.conf.YarnConfiguration;
3031
import org.apache.hadoop.yarn.exceptions.YarnException;
@@ -45,7 +46,7 @@
4546

4647
@InterfaceAudience.Private
4748
@InterfaceStability.Unstable
48-
public class GpuDiscoverer {
49+
public class GpuDiscoverer extends Configured {
4950
public static final Logger LOG = LoggerFactory.getLogger(
5051
GpuDiscoverer.class);
5152
@VisibleForTesting
@@ -61,7 +62,6 @@ public class GpuDiscoverer {
6162
private static final int MAX_EXEC_TIMEOUT_MS = 10 * 1000;
6263
private static final int MAX_REPEATED_ERROR_ALLOWED = 10;
6364

64-
private Configuration conf = null;
6565
private String pathOfGpuBinary = null;
6666
private Map<String, String> environment = new HashMap<>();
6767

@@ -71,7 +71,7 @@ public class GpuDiscoverer {
7171
private List<GpuDevice> gpuDevicesFromUser;
7272

7373
private void validateConfOrThrowException() throws YarnException {
74-
if (conf == null) {
74+
if (getConf() == null) {
7575
throw new YarnException("Please initialize (call initialize) before use "
7676
+ GpuDiscoverer.class.getSimpleName());
7777
}
@@ -144,7 +144,7 @@ synchronized GpuDeviceInformation getGpuDeviceInformation()
144144
}
145145

146146
private boolean IsAutoDiscoveryEnabled() {
147-
String allowedDevicesStr = conf.get(
147+
String allowedDevicesStr = getConf().get(
148148
YarnConfiguration.NM_GPU_ALLOWED_DEVICES,
149149
YarnConfiguration.AUTOMATICALLY_DISCOVER_GPU_DEVICES);
150150
return allowedDevicesStr.equals(
@@ -205,7 +205,7 @@ private List<GpuDevice> parseGpuDevicesFromAutoDiscoveredGpuInfo()
205205
*/
206206
private List<GpuDevice> parseGpuDevicesFromUserDefinedValues()
207207
throws YarnException {
208-
String devices = conf.get(
208+
String devices = getConf().get(
209209
YarnConfiguration.NM_GPU_ALLOWED_DEVICES,
210210
YarnConfiguration.AUTOMATICALLY_DISCOVER_GPU_DEVICES);
211211

@@ -249,7 +249,7 @@ private GpuDevice parseGpuDevice(String device, String[] splitByColon,
249249

250250
public synchronized void initialize(Configuration config)
251251
throws YarnException {
252-
this.conf = config;
252+
setConf(config);
253253
if (IsAutoDiscoveryEnabled()) {
254254
numOfErrorExecutionSinceLastSucceed = 0;
255255
lookUpAutoDiscoveryBinary(config);

0 commit comments

Comments
 (0)