xintongsong commented on a change in pull request #11920:
URL: https://github.com/apache/flink/pull/11920#discussion_r422458201
##########
File path:
flink-external-resources/flink-external-resource-gpu/src/main/java/org/apache/flink/externalresource/gpu/GPUDriver.java
##########
@@ -71,16 +74,16 @@
final String discoveryScriptPath =
config.getString(DISCOVERY_SCRIPT_PATH);
if (StringUtils.isNullOrWhitespaceOnly(discoveryScriptPath)) {
throw new IllegalConfigurationException(
- "Could not find config of the path of gpu
discovery script, the relevant config key is {}.",
"external-resource.<resource-name>." + DISCOVERY_SCRIPT_ARG.key());
+ String.format("GPU discovery script ('%s') is
not configured.",
ExternalResourceOptions.keyWithResourceNameAndSuffix("<resource-name>",
DISCOVERY_SCRIPT_ARG.key())));
Review comment:
I would suggest to make `ExternalResourceOptions#genericKeyWithSuffix`
public and use it, rather than passing in `<resource-name>`.
##########
File path:
flink-external-resources/flink-external-resource-gpu/src/test/java/org/apache/flink/externalresource/gpu/GPUDriverTest.java
##########
@@ -78,7 +81,12 @@ public void testGPUDriverWithTestScriptDoNotExist() throws
Exception {
@Test(expected = FlinkException.class)
public void testGPUDriverWithInexecutableScript() throws Exception {
final Configuration config = new Configuration();
- config.setString(GPUDriver.DISCOVERY_SCRIPT_PATH,
"src/test/resources/inexecutable-gpu-discovery.sh");
+ final TemporaryFolder temporaryFolder = new TemporaryFolder(new
File("."));
+ temporaryFolder.create();
Review comment:
`TemporaryFolder#create` is documented as `do not use`.
##########
File path:
flink-external-resources/flink-external-resource-gpu/src/main/java/org/apache/flink/externalresource/gpu/GPUDriver.java
##########
@@ -52,6 +53,8 @@
private static final Logger LOG =
LoggerFactory.getLogger(GPUDriver.class);
+ private static final long DISCOVERY_SCRIPT_TIMEOUT = 10000;
Review comment:
```suggestion
private static final long DISCOVERY_SCRIPT_TIMEOUT_MS = 10000;
```
##########
File path:
flink-external-resources/flink-external-resource-gpu/src/test/java/org/apache/flink/externalresource/gpu/GPUDriverTest.java
##########
@@ -78,7 +81,12 @@ public void testGPUDriverWithTestScriptDoNotExist() throws
Exception {
@Test(expected = FlinkException.class)
public void testGPUDriverWithInexecutableScript() throws Exception {
final Configuration config = new Configuration();
- config.setString(GPUDriver.DISCOVERY_SCRIPT_PATH,
"src/test/resources/inexecutable-gpu-discovery.sh");
+ final TemporaryFolder temporaryFolder = new TemporaryFolder(new
File("."));
Review comment:
I would try to avoid forcing crate the temporary folder at current path
if possible.
We can omit the constructor argument, and set
`executableFile.getAbsolutePath()` to the configuration.
##########
File path:
flink-external-resources/flink-external-resource-gpu/src/main/java/org/apache/flink/externalresource/gpu/GPUDriver.java
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.externalresource.gpu;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.externalresource.ExternalResourceDriver;
+import org.apache.flink.configuration.ConfigConstants;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.StringUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.apache.flink.configuration.ConfigOptions.key;
+
+/**
+ * Driver takes the responsibility to discover GPU resources and provide the
GPU resource information.
+ * It get the GPU information by executing user-defined discovery script.
+ */
+class GPUDriver implements ExternalResourceDriver {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(GPUDriver.class);
+
+ @VisibleForTesting
+ static final ConfigOption<String> DISCOVERY_SCRIPT_PATH =
+ key("discovery-script.path")
+ .stringType()
+ .noDefaultValue();
+
+ @VisibleForTesting
+ static final ConfigOption<String> DISCOVERY_SCRIPT_ARG =
+ key("discovery-script.args")
+ .stringType()
+ .noDefaultValue();
+
+ private final File discoveryScript;
+ private final String args;
+
+ GPUDriver(Configuration config) throws Exception {
+ final String discoveryScriptPath =
config.getString(DISCOVERY_SCRIPT_PATH);
+ if (StringUtils.isNullOrWhitespaceOnly(discoveryScriptPath)) {
+ throw new IllegalConfigurationException(
+ "Could not find config of the path of gpu
discovery script, the relevant config key is {}.",
"external-resource.<resource-name>." + DISCOVERY_SCRIPT_ARG.key());
+ }
+
+ discoveryScript = new
File(System.getenv().getOrDefault(ConfigConstants.ENV_FLINK_HOME_DIR, ".") +
+ "/" + discoveryScriptPath);
Review comment:
I think we should consider supporting both absolute and relative path
for this configuration option.
##########
File path:
flink-external-resources/flink-external-resource-gpu/src/test/java/org/apache/flink/externalresource/gpu/GPUDriverTest.java
##########
@@ -78,7 +81,12 @@ public void testGPUDriverWithTestScriptDoNotExist() throws
Exception {
@Test(expected = FlinkException.class)
public void testGPUDriverWithInexecutableScript() throws Exception {
final Configuration config = new Configuration();
- config.setString(GPUDriver.DISCOVERY_SCRIPT_PATH,
"src/test/resources/inexecutable-gpu-discovery.sh");
+ final TemporaryFolder temporaryFolder = new TemporaryFolder(new
File("."));
+ temporaryFolder.create();
+ final File inexecutatbleFile = temporaryFolder.newFile();
Review comment:
typo:
```suggestion
final File inexecutableFile = temporaryFolder.newFile();
```
----------------------------------------------------------------
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]