/** * Submits the job based on the arguments. */ public static void main(final String[] args) { EnvironmentInformation.logEnvironmentInfo(LOG, "Command Line Client", args); // 1. find the configuration directory final String configurationDirectory = getConfigurationDirectoryFromEnv(); // 2. load the global configuration final Configuration configuration = GlobalConfiguration.loadConfiguration(configurationDirectory); // 3. load the custom command lines final List<CustomCommandLine<?>> customCommandLines = loadCustomCommandLines( configuration, configurationDirectory); try { final CliFrontend cli = new CliFrontend( configuration, customCommandLines); SecurityUtils.install(new SecurityConfiguration(cli.configuration)); int retCode = SecurityUtils.getInstalledContext() .runSecured(() -> cli.parseParameters(args)); System.exit(retCode); } catch (Throwable t) { final Throwable strippedThrowable = ExceptionUtils.stripException(t, UndeclaredThrowableException.class); LOG.error("Fatal error while running command line interface.", strippedThrowable); strippedThrowable.printStackTrace(); System.exit(31); } }
try { LOG.info("Building program from JAR file"); program = buildProgram(runOptions); final CustomCommandLine<?> customCommandLine = getActiveCustomCommandLine(commandLine); runProgram(customCommandLine, commandLine, runOptions, program); } finally { program.deleteExtractedLibraries();
run(params); return 0; case ACTION_LIST: list(params); return 0; case ACTION_INFO: info(params); return 0; case ACTION_CANCEL: cancel(params); return 0; case ACTION_STOP: stop(params); return 0; case ACTION_SAVEPOINT: savepoint(params); return 0; case ACTION_MODIFY: modify(params); return 0; case "-h": return handleArgException(ce); } catch (ProgramParametrizationException ppe) { return handleParametrizationException(ppe); } catch (ProgramMissingJobException pmje) { return handleMissingJobException(); } catch (Exception e) { return handleError(e);
@Test(expected = CliArgsException.class) public void testCancelWithSavepointWithoutJobId() throws Exception { // Cancel with savepoint (with target directory), but no job ID String[] parameters = { "-s", "targetDirectory" }; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.cancel(parameters); }
case CLI_FRONTEND: try { CliFrontend cli = new CliFrontend( configuration, CliFrontend.loadCustomCommandLines(configuration, configurationDirectory)); returnValue = cli.parseParameters(args); } catch (Exception e) { throw new RuntimeException("Failed to execute the following args with CliFrontend: "
@Nonnull YarnClusterDescriptor createYarnClusterDescriptor(org.apache.flink.configuration.Configuration flinkConfiguration) { final YarnClusterDescriptor yarnClusterDescriptor = new YarnClusterDescriptor( flinkConfiguration, YARN_CONFIGURATION, CliFrontend.getConfigurationDirectoryFromEnv(), yarnClient, true); yarnClusterDescriptor.setLocalJarPath(new Path(flinkUberjar.toURI())); yarnClusterDescriptor.addShipFiles(Collections.singletonList(flinkLibFolder)); return yarnClusterDescriptor; }
try { flinkConfigDir = CliFrontend.getConfigurationDirectoryFromEnv(); this.commandLines = CliFrontend.loadCustomCommandLines(flinkConfig, flinkConfigDir); this.commandLineOptions = collectCommandLineOptions(commandLines); } catch (Exception e) {
@Test(expected = CliArgsException.class) public void testUnrecognizedOption() throws Exception { // test unrecognized option String[] parameters = {"-v", "-l", "-a", "some", "program", "arguments"}; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.run(parameters); }
@Test(expected = CliArgsException.class) public void testMissingJobId() throws Exception { // test missing job id String[] parameters = {}; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.stop(parameters); }
@Test public void testShowExecutionPlan() throws Exception { replaceStdOut(); try { String[] parameters = new String[]{CliFrontendTestUtils.getTestJarPath(), "-f", "true"}; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.info(parameters); assertTrue(buffer.toString().contains("\"parallelism\": \"1\"")); } finally { restoreStdOut(); } }
@Test(expected = CliArgsException.class) public void testUnrecognizedOption() throws Exception { String[] parameters = {"-v", "-k"}; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.list(parameters); }
GlobalConfiguration.loadConfiguration(flinkConfig.getConfigDir()); List<CustomCommandLine<?>> customCommandLines = CliFrontend.loadCustomCommandLines(configuration, flinkConfig.getConfigDir()); CliFrontend flinkCli = new CliFrontend(configuration, customCommandLines); FlinkRestApi flinkRestApi = new FlinkRestApi(new RestTemplate(), flinkConfig.getMasterUrl());
@Test public void testNonExistingJarFile() throws Exception { ProgramOptions options = mock(ProgramOptions.class); when(options.getJarFilePath()).thenReturn("/some/none/existing/path"); try { frontend.buildProgram(options); fail("should throw an exception"); } catch (FileNotFoundException e) { // that's what we want } }
@Before public void setup() throws Exception { final Configuration configuration = new Configuration(); frontend = new CliFrontend( configuration, Collections.singletonList(new DefaultCLI(configuration))); }
/** * Tests disposal with a JAR file. */ @Test public void testDisposeWithJar() throws Exception { replaceStdOutAndStdErr(); final CompletableFuture<String> disposeSavepointFuture = new CompletableFuture<>(); final DisposeSavepointClusterClient clusterClient = new DisposeSavepointClusterClient( (String savepointPath) -> { disposeSavepointFuture.complete(savepointPath); return CompletableFuture.completedFuture(Acknowledge.get()); }, getConfiguration()); try { CliFrontend frontend = new MockedCliFrontend(clusterClient); // Fake JAR file File f = tmp.newFile(); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f)); out.close(); final String disposePath = "any-path"; String[] parameters = { "-d", disposePath, "-j", f.getAbsolutePath() }; frontend.savepoint(parameters); final String actualSavepointPath = disposeSavepointFuture.get(); assertEquals(disposePath, actualSavepointPath); } finally { clusterClient.shutdown(); restoreStdOutAndStdErr(); } }
@Override public void abortJob(String extId) { flinkCli.parseParameters(createStopArgs(extId)); }
@Test(expected = CliArgsException.class) public void testNoJarNoArgumentsAtAll() throws Exception { frontend.run(new String[0]); }
@Test(expected = CliArgsException.class) public void testUnrecognizedOption() throws Exception { String[] parameters = {"-v", "-l"}; Configuration configuration = getConfiguration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.cancel(parameters); }
public static void main(final String[] args) { final String configurationDirectory = CliFrontend.getConfigurationDirectoryFromEnv(); final Configuration flinkConfiguration = GlobalConfiguration.loadConfiguration(); int retCode; try { final FlinkYarnSessionCli cli = new FlinkYarnSessionCli( flinkConfiguration, configurationDirectory, "", ""); // no prefix for the YARN session SecurityUtils.install(new SecurityConfiguration(flinkConfiguration)); retCode = SecurityUtils.getInstalledContext().runSecured(() -> cli.run(args)); } catch (CliArgsException e) { retCode = handleCliArgsException(e); } catch (Throwable t) { final Throwable strippedThrowable = ExceptionUtils.stripException(t, UndeclaredThrowableException.class); retCode = handleError(strippedThrowable); } System.exit(retCode); }
@Test(expected = CliArgsException.class) public void testParallelismWithOverflow() throws Exception { // test configure parallelism with overflow integer value String[] parameters = {"-v", "-p", "475871387138", getTestJarPath()}; Configuration configuration = new Configuration(); CliFrontend testFrontend = new CliFrontend( configuration, Collections.singletonList(getCli(configuration))); testFrontend.run(parameters); }