TisonKun commented on a change in pull request #9921: [FLINK-14130][client] 
Remove ClusterClient.run() methods
URL: https://github.com/apache/flink/pull/9921#discussion_r336100572
 
 

 ##########
 File path: flink-clients/src/main/java/org/apache/flink/client/ClientUtils.java
 ##########
 @@ -80,4 +93,43 @@ public static ClassLoader 
buildUserCodeClassLoader(List<URL> jars, List<URL> cla
                }
                return FlinkUserCodeClassLoaders.parentFirst(urls, parent);
        }
+
+       public static JobSubmissionResult executeProgram(
+               ClusterClient<?> client,
+               PackagedProgram program,
+               int parallelism) throws ProgramMissingJobException, 
ProgramInvocationException {
+               final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
+               try {
+                       
Thread.currentThread().setContextClassLoader(program.getUserCodeClassLoader());
+
+                       LOG.info("Starting program (detached: {})", 
client.isDetached());
+
+                       final List<URL> libraries = program.getAllLibraries();
+
+                       ContextEnvironmentFactory factory = new 
ContextEnvironmentFactory(
+                               client,
+                               libraries,
+                               program.getClasspaths(),
+                               program.getUserCodeClassLoader(),
+                               parallelism,
+                               client.isDetached(),
+                               program.getSavepointSettings());
+                       ContextEnvironment.setAsContext(factory);
+
+                       try {
+                               program.invokeInteractiveModeForExecution();
+
+                               JobExecutionResult result = 
client.getLastJobExecutionResult();
+                               if (result == null) {
+                                       throw new 
ProgramMissingJobException("The program didn't contain a Flink job.");
+                               }
+                               return result;
 
 Review comment:
   @aljoscha see this part of code. if the return value is `null` we already 
throw an exception. I'm ok to add back a redundant null checker in 
`CliFrontend#executeProgram` but since we can also provide non-null promise in 
`ClientUtils.executeProgram` I think we don't need it.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to