private static void checkJarFile(URL jarfile) throws ProgramInvocationException { try { JobWithJars.checkJarFile(jarfile); } catch (IOException e) { throw new ProgramInvocationException(e.getMessage()); } catch (Throwable t) { throw new ProgramInvocationException("Cannot access jar file" + (t.getMessage() == null ? "." : ": " + t.getMessage()), t); } }
@Override public void run() { try { program.invokeInteractiveModeForExecution(); } catch (ProgramInvocationException ignored) { if (ignored.getCause() == null || !(ignored.getCause() instanceof JobCancellationException)) { ignored.printStackTrace(); } } } });
private List<String> runTestPipeline(int parallelism, String savepoint, Function<DataStream<String>, DataStream<String>> pipelinerBuilder) throws Exception { if (!actions.isEmpty() && actions.getLast() instanceof CancelJob && ((CancelJob) actions.getLast()).isClusterActionTriggered()) { cancelJob(); } jobGraph = createJobGraph(parallelism, pipelinerBuilder).getStreamGraph().getJobGraph(); if (savepoint != null) { jobGraph.setSavepointRestoreSettings(SavepointRestoreSettings.forPath(savepoint)); } jobID = jobGraph.getJobID(); MiniClusterResourceFactory clusterFactory = createCluster(1, 2); MiniClusterResource cluster = clusterFactory.get(); cluster.before(); client = cluster.getClusterClient(); try { // client.setDetached(true); client.submitJob(jobGraph, BravoTestPipeline.class.getClassLoader()); } catch (ProgramInvocationException pie) { if (!pie.getMessage().contains("Job was cancelled") && !pie.getCause().getMessage().contains("Job was cancelled")) { throw pie; } } finally { cluster.after(); } return CollectingSink.OUTPUT; }
assertEquals( DetachedJobExecutionResult.DETACHED_MESSAGE + DetachedJobExecutionResult.EXECUTE_TWICE_MESSAGE, e.getCause().getMessage()); assertEquals( DetachedJobExecutionResult.DETACHED_MESSAGE + DetachedJobExecutionResult.JOB_RESULT_MESSAGE + DetachedJobExecutionResult.EAGER_FUNCTION_MESSAGE, e.getCause().getMessage()); assertEquals( DetachedJobExecutionResult.DETACHED_MESSAGE + DetachedJobExecutionResult.JOB_RESULT_MESSAGE, e.getCause().getMessage()); assertEquals( DetachedJobExecutionResult.DETACHED_MESSAGE + DetachedJobExecutionResult.JOB_RESULT_MESSAGE, e.getCause().getMessage()); assertEquals( DetachedJobExecutionResult.DETACHED_MESSAGE + DetachedJobExecutionResult.JOB_RESULT_MESSAGE + DetachedJobExecutionResult.EAGER_FUNCTION_MESSAGE, e.getCause().getMessage()); assertEquals( DetachedJobExecutionResult.DETACHED_MESSAGE + DetachedJobExecutionResult.JOB_RESULT_MESSAGE, e.getCause().getMessage());
throw new IOException("Error while submitting Flink job to cluster:"+ex.getMessage()); } finally {
@Test public void testIncorrectSerializer4() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(PARLLELISM); env.getConfig().disableSysoutLogging(); env .generateSequence(1, 10 * PARLLELISM) .map(new MapFunction<Long, ConsumesTooLittleSpanning>() { @Override public ConsumesTooLittleSpanning map(Long value) throws Exception { return new ConsumesTooLittleSpanning(); } }) .rebalance() .output(new DiscardingOutputFormat<ConsumesTooLittleSpanning>()); env.execute(); } catch (ProgramInvocationException e) { Throwable rootCause = e.getCause().getCause(); assertTrue(rootCause instanceof IOException); assertTrue(rootCause.getMessage().contains("broken serialization")); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
private static Class<?> loadMainClass(String className, ClassLoader cl) throws ProgramInvocationException { ClassLoader contextCl = null; try { contextCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(cl); return Class.forName(className, false, cl); } catch (ClassNotFoundException e) { throw new ProgramInvocationException("The program's entry point class '" + className + "' was not found in the jar file.", e); } catch (ExceptionInInitializerError e) { throw new ProgramInvocationException("The program's entry point class '" + className + "' threw an error during initialization.", e); } catch (LinkageError e) { throw new ProgramInvocationException("The program's entry point class '" + className + "' could not be loaded due to a linkage failure.", e); } catch (Throwable t) { throw new ProgramInvocationException("The program's entry point class '" + className + "' caused an exception during initialization: " + t.getMessage(), t); } finally { if (contextCl != null) { Thread.currentThread().setContextClassLoader(contextCl); } } }
if (!(e.getCause() instanceof ClassNotFoundException)) { e.printStackTrace(); fail("Program didn't throw ClassNotFoundException");
private static void callMainMethod(Class<?> entryClass, String[] args) throws ProgramInvocationException { Method mainMethod; if (!Modifier.isPublic(entryClass.getModifiers())) { throw new ProgramInvocationException("The class " + entryClass.getName() + " must be public."); mainMethod = entryClass.getMethod("main", String[].class); } catch (NoSuchMethodException e) { throw new ProgramInvocationException("The class " + entryClass.getName() + " has no main(String[]) method."); throw new ProgramInvocationException("Could not look up the main(String[]) method from the class " + entryClass.getName() + ": " + t.getMessage(), t); throw new ProgramInvocationException("The class " + entryClass.getName() + " declares a non-static main method."); throw new ProgramInvocationException("The class " + entryClass.getName() + " declares a non-public main method."); throw new ProgramInvocationException("Could not invoke the main method, arguments are not matching.", e); throw new ProgramInvocationException("Access to the main method was denied: " + e.getMessage(), e); throw (ProgramInvocationException) exceptionInMethod; } else { throw new ProgramInvocationException("The main method caused an error: " + exceptionInMethod.getMessage(), exceptionInMethod); throw new ProgramInvocationException("An error occurred while invoking the program's main method: " + t.getMessage(), t);
/** * Takes the jar described by the given file and invokes its pact assembler class to * assemble a plan. The assembler class name is either passed through a parameter, * or it is read from the manifest of the jar. The assembler is handed the given options * for its assembly. * * @param program The program to create the plan for. * @param options * The options for the assembler. * @return The plan created by the program. * @throws ProgramInvocationException * Thrown, if an error occurred in the user-provided pact assembler. */ 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); } }
jar = new JarFile(new File(jarFile.toURI())); } catch (URISyntaxException use) { throw new ProgramInvocationException("Invalid file path '" + jarFile.getPath() + "'", use); } catch (IOException ioex) { throw new ProgramInvocationException("Error while opening jar file '" + jarFile.getPath() + "'. " + ioex.getMessage(), ioex); manifest = jar.getManifest(); } catch (IOException ioex) { throw new ProgramInvocationException("The Manifest in the jar file could not be accessed '" + jarFile.getPath() + "'. " + ioex.getMessage(), ioex); throw new ProgramInvocationException("No manifest found in jar file '" + jarFile.getPath() + "'. The manifest is need to point to the program's main class."); return className; } else { throw new ProgramInvocationException("Neither a '" + MANIFEST_ATTRIBUTE_MAIN_CLASS + "', nor a '" + MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS + "' entry was found in the jar file."); jar.close(); } catch (Throwable t) { throw new ProgramInvocationException("Could not close the JAR file: " + t.getMessage(), t);
throw new ProgramInvocationException("The given program class implements the " + Program.class.getName() + " interface, but cannot be instantiated. " + "It also declares no main(String[]) method as alternative entry point", e); throw new ProgramInvocationException("Error while trying to instantiate program class.", t); this.program = null; } else { throw new ProgramInvocationException("The given program class neither has a main(String[]) method, nor does it implement the " + Program.class.getName() + " interface.");
/** * This method assumes that the context environment is prepared, or the execution * will be a local execution by default. */ public void invokeInteractiveModeForExecution() throws ProgramInvocationException{ if (isUsingInteractiveMode()) { callMainMethod(mainClass, args); } else { throw new ProgramInvocationException("Cannot invoke a plan-based program directly."); } }
return optimizerPlan; } else { throw new ProgramInvocationException("The program caused an error: ", t); String stderr = baes.toString(); throw new ProgramInvocationException( "The program plan could not be fetched - the program aborted pre-maturely." + "\n\nSystem.err: " + (stdout.length() == 0 ? "(none)" : stdout)
throw new ProgramInvocationException("Error while getting the program description" + (t.getMessage() == null ? "." : ": " + t.getMessage()), t);
/** * Executes the remote job. * * @param streamGraph * Stream Graph to execute * @param jarFiles * List of jar file URLs to ship to the cluster * @return The result of the job execution, containing elapsed time and accumulators. */ @Override protected JobExecutionResult executeRemotely(StreamGraph streamGraph, List<URL> jarFiles) throws ProgramInvocationException { URL jarUrl; try { jarUrl = flinkILoop.writeFilesToDisk().getAbsoluteFile().toURI().toURL(); } catch (MalformedURLException e) { throw new ProgramInvocationException("Could not write the user code classes to disk.", streamGraph.getJobGraph().getJobID(), e); } List<URL> allJarFiles = new ArrayList<>(jarFiles.size() + 1); allJarFiles.addAll(jarFiles); allJarFiles.add(jarUrl); return super.executeRemotely(streamGraph, allJarFiles); }
throw new ProgramInvocationException( "An I/O error occurred while creating temporary file to extract nested library '" + entry.getName() + "'.", e); throw new ProgramInvocationException("An I/O error occurred while extracting nested library '" + entry.getName() + "' to temporary file '" + tempFile.getAbsolutePath() + "'."); throw new ProgramInvocationException("Unknown I/O error while extracting contained jar files.", t);
/** * Returns the plan without the required jars when the files are already provided by the cluster. * * @return The plan without attached jar files. * @throws ProgramInvocationException */ public JobWithJars getPlanWithoutJars() throws ProgramInvocationException { if (isUsingProgramEntryPoint()) { return new JobWithJars(getPlan(), Collections.<URL>emptyList(), classpaths, userCodeClassLoader); } else { throw new ProgramInvocationException("Cannot create a " + JobWithJars.class.getSimpleName() + " for a program that is using the interactive mode.", getPlan().getJobId()); } }
@Override public JobSubmissionResult submitJob(JobGraph jobGraph, ClassLoader classLoader) throws ProgramInvocationException { final CompletableFuture<JobSubmissionResult> jobSubmissionResultFuture = submitJob(jobGraph); if (isDetached()) { try { return jobSubmissionResultFuture.get(); } catch (InterruptedException | ExecutionException e) { ExceptionUtils.checkInterrupted(e); throw new ProgramInvocationException("Could not run job in detached mode.", jobGraph.getJobID(), e); } } else { final CompletableFuture<JobResult> jobResultFuture = jobSubmissionResultFuture.thenCompose( (JobSubmissionResult ignored) -> requestJobResult(jobGraph.getJobID())); final JobResult jobResult; try { jobResult = jobResultFuture.get(); } catch (InterruptedException | ExecutionException e) { ExceptionUtils.checkInterrupted(e); throw new ProgramInvocationException("Could not run job", jobGraph.getJobID(), e); } try { return jobResult.toJobExecutionResult(classLoader); } catch (JobExecutionException e) { throw new ProgramInvocationException("Job failed", jobGraph.getJobID(), e); } catch (IOException | ClassNotFoundException e) { throw new ProgramInvocationException("Job failed", jobGraph.getJobID(), e); } } }
throw new ProgramInvocationException("The given program class implements the " + Program.class.getName() + " interface, but cannot be instantiated. " + "It also declares no main(String[]) method as alternative entry point", e); throw new ProgramInvocationException("Error while trying to instantiate program class.", t); this.program = null; } else { throw new ProgramInvocationException("The given program class neither has a main(String[]) method, nor does it implement the " + Program.class.getName() + " interface.");