Package org.apache.flink.client.program

Examples of org.apache.flink.client.program.PackagedProgram


    verify(this.jobClientMock).submitJob();
  }

  @Test(expected = InvalidProgramException.class)
  public void tryLocalExecution() throws Exception {
    PackagedProgram packagedProgramMock = mock(PackagedProgram.class);

    when(packagedProgramMock.isUsingInteractiveMode()).thenReturn(true);

    doAnswer(new Answer<Void>() {
      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        ExecutionEnvironment.createLocalEnvironment();
View Full Code Here


        params.remove(0);
      }

      // create the plan
      String[] options = params.isEmpty() ? new String[0] : (String[]) params.toArray(new String[params.size()]);
      PackagedProgram program;
      OptimizedPlan optPlan;
      Client client;
     
      try {
        if (assemblerClass == null) {
          program = new PackagedProgram(jarFile, options);
        } else {
          program = new PackagedProgram(jarFile, assemblerClass, options);
        }
       
        client = new Client(nepheleConfig, program.getUserCodeClassLoader());
       
        optPlan = client.getOptimizedPlan(program, -1);
       
        if (optPlan == null) {
          throw new Exception("The optimized plan could not be produced.");
        }
      }
      catch (ProgramInvocationException e) {
        // collect the stack trace
        StringWriter sw = new StringWriter();
        PrintWriter w = new PrintWriter(sw);
       
        if (e.getCause() == null) {
          e.printStackTrace(w);
        } else {
          e.getCause().printStackTrace(w);
        }

        showErrorPage(resp, "An error occurred while invoking the program:<br/><br/>"
          + e.getMessage() + "<br/>"
          + "<br/><br/><pre>" + sw.toString() + "</pre>");
        return;
      }
      catch (CompilerException cex) {
        // collect the stack trace
        StringWriter sw = new StringWriter();
        PrintWriter w = new PrintWriter(sw);
        cex.printStackTrace(w);

        showErrorPage(resp, "An error occurred in the compiler:<br/><br/>"
          + cex.getMessage() + "<br/>"
          + (cex.getCause()!= null?"Caused by: " + cex.getCause().getMessage():"")
          + "<br/><br/><pre>" + sw.toString() + "</pre>");
        return;
      }
      catch (Throwable t) {
        // collect the stack trace
        StringWriter sw = new StringWriter();
        PrintWriter w = new PrintWriter(sw);
        t.printStackTrace(w);

        showErrorPage(resp, "An unexpected error occurred:<br/><br/>" + t.getMessage() + "<br/><br/><pre>"
          + sw.toString() + "</pre>");
        return;
      }

      // redirect according to our options
      if (show) {
        // we have a request to show the plan

        // create a UID for the job
        Long uid = null;
        do {
          uid = Math.abs(this.rand.nextLong());
        } while (this.submittedJobs.containsKey(uid));

        // dump the job to a JSON file
        String planName = uid + ".json";
        File jsonFile = new File(this.planDumpDirectory, planName);
       
        PlanJSONDumpGenerator jsonGen = new PlanJSONDumpGenerator();
        jsonGen.setEncodeForHTML(true);
        jsonGen.dumpOptimizerPlanAsJSON(optPlan, jsonFile);

        // submit the job only, if it should not be suspended
        if (!suspend) {
          try {
            client.run(program, optPlan, false);
          } catch (Throwable t) {
            LOG.error("Error submitting job to the job-manager.", t);
            showErrorPage(resp, t.getMessage());
            return;
          } finally {
            program.deleteExtractedLibraries();
          }
        } else {
          try {
            this.submittedJobs.put(uid, client.getJobGraph(program, optPlan));
          }
          catch (ProgramInvocationException piex) {
            LOG.error("Error creating JobGraph from optimized plan.", piex);
            showErrorPage(resp, piex.getMessage());
            return;
          }
          catch (Throwable t) {
            LOG.error("Error creating JobGraph from optimized plan.", t);
            showErrorPage(resp, t.getMessage());
            return;
          }
        }

        // redirect to the plan display page
        resp.sendRedirect("showPlan?id=" + uid + "&suspended=" + (suspend ? "true" : "false"));
      } else {
        // don't show any plan. directly submit the job and redirect to the
        // nephele runtime monitor
        try {
          client.run(program, -1, false);
        } catch (Exception ex) {
          LOG.error("Error submitting job to the job-manager.", ex);
          // HACK: Is necessary because Message contains whole stack trace
          String errorMessage = ex.getMessage().split("\n")[0];
          showErrorPage(resp, errorMessage);
          return;
        } finally {
          program.deleteExtractedLibraries();
        }
        resp.sendRedirect(START_PAGE_URL);
      }
    } else if (action.equals(ACTION_RUN_SUBMITTED_VALUE)) {
      // --------------- run a job that has been submitted earlier, but was -------------------
View Full Code Here

      resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // create the pact plan
    PackagedProgram pactProgram;
    try {
      pactProgram = new PackagedProgram(jarFile, new String[0]);
    }
    catch (Throwable t) {
      LOG.info("Instantiating the PactProgram for '" + jarFile.getName() + "' failed.", t);
      resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
      resp.getWriter().print(t.getMessage());
      return;
    }
   
    String jsonPlan = null;
    String programDescription = null;
   
    try {
      jsonPlan = pactProgram.getPreviewPlan();
    }
    catch (Throwable t) {
      LOG.error("Failed to create json dump of pact program.", t);
    }
   
    try {
      programDescription = pactProgram.getDescription();
    }
    catch (Throwable t) {
      LOG.error("Failed to create description of pact program.", t);
    }
     
View Full Code Here

TOP

Related Classes of org.apache.flink.client.program.PackagedProgram

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.