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_r258431938
##########
File path:
flink-container/src/main/java/org/apache/flink/container/entrypoint/ClassPathJobGraphRetriever.java
##########
@@ -83,10 +98,38 @@ public JobGraph retrieveJobGraph(Configuration
configuration) throws FlinkExcept
private PackagedProgram createPackagedProgram() throws FlinkException {
try {
- final Class<?> mainClass =
getClass().getClassLoader().loadClass(jobClassName);
+ final Class<?> mainClass =
getClass().getClassLoader().loadClass(findEntryClass());
return new PackagedProgram(mainClass, programArguments);
- } catch (ClassNotFoundException | ProgramInvocationException e)
{
+ } catch (ClassNotFoundException | IOException |
ProgramInvocationException e) {
throw new FlinkException("Could not load the provided
entrypoint class.", e);
}
}
+
+ private String findEntryClass() throws IOException {
+ if (startsWithFromJarPrefix(jobClassName)) {
+ File jarFile = getJarFile(jobClassName);
+ LOG.info("Parsing manifest of '{}' to find job entry
class", jarFile.getAbsolutePath());
+
+ // We find the entry class manually here instead of
providing the JAR to PackagedProgram, because
+ // we want the exact same behavior in all cases, i.e.
when providing a JAR or a job class name.
+ //
+ // Using PackagedProgram with a JAR as argument would
have slightly different behavior than the code
+ // path using the class directly (which is the behavior
we want to keep for now).
+ Optional<String> entryClass =
JarManifestParser.findEntryClass(jarFile);
+ entryClass.ifPresent(name -> LOG.info("Found {} as job
entry class in manifest", name));
+
+ return entryClass.orElseThrow(() -> new
IllegalArgumentException(
+ "Missing manifest entry for entry class in JAR
file " + jarFile.getAbsolutePath()));
+ }
+
+ return jobClassName;
+ }
+
+ private static boolean startsWithFromJarPrefix(String jobClassName) {
+ return jobClassName.toLowerCase().startsWith(PREFIX_FROM_JAR);
+ }
+
+ private static File getJarFile(String jobClassName) {
+ return new
File(jobClassName.substring(PREFIX_FROM_JAR.length()));
Review comment:
have you tried this with paths like `from-jar:///my/path`?
----------------------------------------------------------------
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