tillrohrmann commented on a change in pull request #8154: [Flink-12167] Reset
context classloader in run and getOptimizedPlan methods
URL: https://github.com/apache/flink/pull/8154#discussion_r287414640
##########
File path:
flink-clients/src/main/java/org/apache/flink/client/program/ClusterClient.java
##########
@@ -197,26 +197,33 @@ public LeaderConnectionInfo getClusterConnectionInfo()
throws LeaderRetrievalExc
//
------------------------------------------------------------------------
public static String getOptimizedPlanAsJson(Optimizer compiler,
PackagedProgram prog, int parallelism)
- throws CompilerException, ProgramInvocationException {
+ throws CompilerException, ProgramInvocationException {
PlanJSONDumpGenerator jsonGen = new PlanJSONDumpGenerator();
return jsonGen.getOptimizerPlanAsJSON((OptimizedPlan)
getOptimizedPlan(compiler, prog, parallelism));
}
public static FlinkPlan getOptimizedPlan(Optimizer compiler,
PackagedProgram prog, int parallelism)
- throws CompilerException, ProgramInvocationException {
-
Thread.currentThread().setContextClassLoader(prog.getUserCodeClassLoader());
- if (prog.isUsingProgramEntryPoint()) {
- return getOptimizedPlan(compiler,
prog.getPlanWithJars(), parallelism);
- } else if (prog.isUsingInteractiveMode()) {
- // temporary hack to support the optimizer plan preview
- OptimizerPlanEnvironment env = new
OptimizerPlanEnvironment(compiler);
- if (parallelism > 0) {
- env.setParallelism(parallelism);
- }
+ throws CompilerException, ProgramInvocationException {
+ ClassLoader contextCl =
Thread.currentThread().getContextClassLoader();
+ try {
+
Thread.currentThread().setContextClassLoader(prog.getUserCodeClassLoader());
+ if (prog.isUsingProgramEntryPoint()) {
+ return getOptimizedPlan(compiler,
prog.getPlanWithJars(), parallelism);
+ } else if (prog.isUsingInteractiveMode()) {
+ // temporary hack to support the optimizer plan
preview
+ OptimizerPlanEnvironment env = new
OptimizerPlanEnvironment(compiler);
+ if (parallelism > 0) {
+ env.setParallelism(parallelism);
+ }
- return env.getOptimizedPlan(prog);
- } else {
- throw new RuntimeException("Couldn't determine program
mode.");
+ return env.getOptimizedPlan(prog);
+ } else {
+ throw new RuntimeException("Couldn't determine
program mode.");
+ }
+ } finally {
+ if (contextCl != null) {
Review comment:
I think we don't need the null check here.
----------------------------------------------------------------
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