zentol commented on a change in pull request #7717: [FLINK-11533] [container]
Add option parse JAR manifest for jobClassName
URL: https://github.com/apache/flink/pull/7717#discussion_r260826332
##########
File path:
flink-container/src/main/java/org/apache/flink/container/entrypoint/ClassPathJobGraphRetriever.java
##########
@@ -82,11 +113,58 @@ public JobGraph retrieveJobGraph(Configuration
configuration) throws FlinkExcept
}
private PackagedProgram createPackagedProgram() throws FlinkException {
+ final String entryClass = getJobClassNameOrScanClassPath();
try {
- final Class<?> mainClass =
getClass().getClassLoader().loadClass(jobClassName);
+ final Class<?> mainClass =
getClass().getClassLoader().loadClass(entryClass);
return new PackagedProgram(mainClass, programArguments);
} catch (ClassNotFoundException | ProgramInvocationException e)
{
throw new FlinkException("Could not load the provided
entrypoint class.", e);
}
}
+
+ private String getJobClassNameOrScanClassPath() throws FlinkException {
+ if (jobClassName != null) {
+ return jobClassName;
+ }
+
+ try {
+ return scanClassPathForJobJar();
+ } catch (IOException | NoSuchElementException |
IllegalArgumentException e) {
+ throw new FlinkException("Failed to find job JAR on
class path. Please provide the job class name explicitly.", e);
+ }
+ }
+
+ private String scanClassPathForJobJar() throws IOException {
+ LOG.info("Scanning class path for job JAR");
+ JarFileWithEntryClass jobJar =
JarManifestParser.findOnlyEntryClass(jarsOnClassPath.get());
+
+ LOG.info("Using {} as job jar", jobJar);
+ return jobJar.getEntryClass();
+ }
+
+ @VisibleForTesting
+ enum JarsOnClassPath implements Supplier<Iterable<File>> {
+ INSTANCE;
+
+ static final String JAVA_CLASS_PATH = "java.class.path";
+ static final String PATH_SEPARATOR = "path.separator";
+ static final String DEFAULT_PATH_SEPARATOR = ":";
+
+ @Override
+ public Iterable<File> get() {
+ String classPath = System.getProperty(JAVA_CLASS_PATH,
"");
+ String pathSeparator =
System.getProperty(PATH_SEPARATOR, DEFAULT_PATH_SEPARATOR);
+
+ return Arrays.stream(classPath.split(pathSeparator))
+ .filter(JarsOnClassPath::notNullOrEmpty)
+ .map(File::new)
+ .filter(File::isFile)
+ .collect(Collectors.toList());
+ }
+
+ private static boolean notNullOrEmpty(String string) {
+ return !Strings.isNullOrEmpty(string);
Review comment:
seems unnecessary to rely on an external function
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services