inheritance of Program interface in Program.java in org.apache.flink.api.common

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

inheritance of Program interface in Program.java in org.apache.flink.api.common

yoon

hello first I'm sorry for my poor english.

 

I were looking at PackagedProgram.java from org.apache.flink.client.program

and in following cunstructor: PackagedProgram(File jarFile, List classpaths, String entryPointClassName, String... args)

there is some code I couldn't understand. please look blow

this.mainClass = loadMainClass(entryPointClassName, userCodeClassLoader);   

if (Program.class.isAssignableFrom(this.mainClass)) {
   Program prg = null;

   try {
      prg = InstantiationUtil.instantiate(this.mainClass.asSubclass(Program.class), Program.class);
   }

 

 

how can this.mainClass that doesn't override getPlan method that is abstract method of Program interface(program.class) and has only static main method be instantiate as Program?

 

Thank you for your reading. 

Reply | Threaded
Open this post in threaded view
|

Re: inheritance of Program interface in Program.java in org.apache.flink.api.common

Ufuk Celebi

On Thu, May 19, 2016 at 4:46 PM, 윤형덕 <[hidden email]> wrote:
>
> how can this.mainClass that doesn't override getPlan method that is abstract method of Program interface(program.class) and has only static main method be instantiate as Program?


This is only called if the class is actually a subclass of Program. That's why there is the `isAssignable` check. Otherwise, we check that there is a mainMethod (else if (hasMainMethod(mainClass)). If this is not the case, a ProgramInvocationException is thrown.
Reply | Threaded
Open this post in threaded view
|

Re: inheritance of Program interface in Program.java in org.apache.flink.api.common

yoon

then this.program of PackageProgram's object has null. [1]

in run() of CliFrontend.java, invokes executeProgramBlocking(program, client, userParallelism) [2]

and this method invokes client.runBlocking(program, parallelism) [3]

and this method invokes runBlocking(prog.getPlanWithJars(), parallelism, prog.getSavepointPath()) that is overloaded function[4]

and prog.getPlanWithJars() invokes getPlan() of PackagedProgram.java[5]

and getPlan() invokes createPlanFromProgram(this.program, this.args); [6]

and createPlanFromProgram's source is folowing

 

private static Plan createPlanFromProgram(Program program, String[] options) throws ProgramInvocationException {
    try {
      return program.getPlan(options);
    } catch (Throwable t) {
      throw new ProgramInvocationException("Error while calling the program: " + t.getMessage(), t);
    }

}

 

as we checked, this.program has null. so if we invoke program.getPlan(options), exception will happen.

but when i runned program, exception didn't occur.

i'd appreciate if you explain this.

 

[1]

else if (hasMainMethod(mainClass)) {
this.program = null;

 

[2]

if (options.getDetachedMode() || (yarnCluster != null && yarnCluster.isDetached())) {
     exitCode = executeProgramDetached(program, client, userParallelism);
} else {
     exitCode = executeProgramBlocking(program, client, userParallelism);

}

 

[3]

protected int executeProgramBlocking(PackagedProgram program, Client client, int parallelism) {
  LOG.info("Starting execution of program");

  JobSubmissionResult result;
  try {
     result = client.runBlocking(program, parallelism);
  }

 

[4]

public JobSubmissionResult runBlocking(PackagedProgram prog, int parallelism) throws ProgramInvocationException {
  Thread.currentThread().setContextClassLoader(prog.getUserCodeClassLoader());
  if (prog.isUsingProgramEntryPoint()) {
    return runBlocking(prog.getPlanWithJars(), parallelism, prog.getSavepointPath());
  }

 

[5]

public JobWithJars getPlanWithJars() throws ProgramInvocationException {
  if (isUsingProgramEntryPoint()) {
     return new JobWithJars(getPlan(), getAllLibraries(), classpaths, userCodeClassLoader);

 

[6]

private Plan getPlan() throws ProgramInvocationException {
  if (this.plan == null) {
     Thread.currentThread().setContextClassLoader(this.userCodeClassLoader);
     this.plan = createPlanFromProgram(this.program, this.args);
  }
  return this.plan;

}

 

 

-----Original Message-----
From: "Ufuk Celebi"<[hidden email]>
To: <[hidden email]>; "윤형덕"<[hidden email]>;
Cc:
Sent: 2016-05-20 (금) 19:30:01
Subject: Re: inheritance of Program interface in Program.java in org.apache.flink.api.common
 


On Thu, May 19, 2016 at 4:46 PM, 윤형덕 <[hidden email]> wrote:
>
> how can this.mainClass that doesn't override getPlan method that is abstract method of Program interface(program.class) and has only static main method be instantiate as Program?


This is only called if the class is actually a subclass of Program. That's why there is the `isAssignable` check. Otherwise, we check that there is a mainMethod (else if (hasMainMethod(mainClass)). If this is not the case, a ProgramInvocationException is thrown.