flink-instrumentation/workspace/flink-1.4.1-instrumented/flink-1.4.1/flink-clients/src/main/java/org/apache/flink/client/CliFrontend.java
/**
	 * Executes the CANCEL action.
	 *
	 * @param args Command line arguments for the cancel action.
	 */
Executes the CANCEL action.
@param args Command line arguments for the cancel action.
Executes the CANCEL action . @param args Command line arguments for the cancel action .
protected int cancel(String[] args) {
		LOG.info("Running 'cancel' command.");
		CancelOptions options;
		try {
			options = CliFrontendParser.parseCancelCommand(args);
		}
		catch (CliArgsException e) {
			return handleArgException(e);
		}
		catch (Throwable t) {
			return handleError(t);
		}
		if (options.isPrintHelp()) {
			CliFrontendParser.printHelpForCancel();
			return 0;
		}
		String[] cleanedArgs = options.getArgs();
		boolean withSavepoint = options.isWithSavepoint();
		String targetDirectory = options.getSavepointTargetDirectory();
		JobID jobId;
		if (cleanedArgs.length > 0) {
			String jobIdString = cleanedArgs[0];
			try {
				jobId = new JobID(StringUtils.hexStringToByte(jobIdString));
			} catch (Exception e) {
				LOG.error("Error: The value for the Job ID is not a valid ID.");
				System.out.println("Error: The value for the Job ID is not a valid ID.");
				return 1;
			}
		} else if (targetDirectory != null)  {
			String jobIdString = targetDirectory;
			try {
				jobId = new JobID(StringUtils.hexStringToByte(jobIdString));
				targetDirectory = null;
			} catch (Exception e) {
				LOG.error("Missing JobID in the command line arguments.");
				System.out.println("Error: Specify a Job ID to cancel a job.");
				return 1;
			}
		} else {
			LOG.error("Missing JobID in the command line arguments.");
			System.out.println("Error: Specify a Job ID to cancel a job.");
			return 1;
		}
		try {
			CustomCommandLine<?> activeCommandLine = getActiveCustomCommandLine(options.getCommandLine());
			ClusterClient client = activeCommandLine.retrieveCluster(options.getCommandLine(), config, configurationDirectory);
			try {
				if (withSavepoint) {
					if (targetDirectory == null) {
						logAndSysout("Cancelling job " + jobId + " with savepoint to default savepoint directory.");
					} else {
						logAndSysout("Cancelling job " + jobId + " with savepoint to " + targetDirectory + '.');
					}
					String savepointPath = client.cancelWithSavepoint(jobId, targetDirectory);
					logAndSysout("Cancelled job " + jobId + ". Savepoint stored in " + savepointPath + '.');
				} else {
					logAndSysout("Cancelling job " + jobId + '.');
					client.cancel(jobId);
					logAndSysout("Cancelled job " + jobId + '.');
				}
				return 0;
			} finally {
				client.shutdown();
			}
		}
		catch (Throwable t) {
			return handleError(t);
		}
	}
protected int cancel ( String [ ] args ) { LOG . info ( "Running 'cancel' command." ) ; CancelOptions options ; try { options = CliFrontendParser . parseCancelCommand ( args ) ; } catch ( CliArgsException e ) { return handleArgException ( e ) ; } catch ( Throwable t ) { return handleError ( t ) ; } if ( options . isPrintHelp ( ) ) { CliFrontendParser . printHelpForCancel ( ) ; return 0 ; } String [ ] cleanedArgs = options . getArgs ( ) ; boolean withSavepoint = options . isWithSavepoint ( ) ; String targetDirectory = options . getSavepointTargetDirectory ( ) ; JobID jobId ; if ( cleanedArgs . length > 0 ) { String jobIdString = cleanedArgs [ 0 ] ; try { jobId = new JobID ( StringUtils . hexStringToByte ( jobIdString ) ) ; } catch ( Exception e ) { LOG . error ( "Error: The value for the Job ID is not a valid ID." ) ; System . out . println ( "Error: The value for the Job ID is not a valid ID." ) ; return 1 ; } } else if ( targetDirectory != null ) { String jobIdString = targetDirectory ; try { jobId = new JobID ( StringUtils . hexStringToByte ( jobIdString ) ) ; targetDirectory = null ; } catch ( Exception e ) { LOG . error ( "Missing JobID in the command line arguments." ) ; System . out . println ( "Error: Specify a Job ID to cancel a job." ) ; return 1 ; } } else { LOG . error ( "Missing JobID in the command line arguments." ) ; System . out . println ( "Error: Specify a Job ID to cancel a job." ) ; return 1 ; } try { CustomCommandLine < ? > activeCommandLine = getActiveCustomCommandLine ( options . getCommandLine ( ) ) ; ClusterClient client = activeCommandLine . retrieveCluster ( options . getCommandLine ( ) , config , configurationDirectory ) ; try { if ( withSavepoint ) { if ( targetDirectory == null ) { logAndSysout ( "Cancelling job " + jobId + " with savepoint to default savepoint directory." ) ; } else { logAndSysout ( "Cancelling job " + jobId + " with savepoint to " + targetDirectory + '.' ) ; } String savepointPath = client . cancelWithSavepoint ( jobId , targetDirectory ) ; logAndSysout ( "Cancelled job " + jobId + ". Savepoint stored in " + savepointPath + '.' ) ; } else { logAndSysout ( "Cancelling job " + jobId + '.' ) ; client . cancel ( jobId ) ; logAndSysout ( "Cancelled job " + jobId + '.' ) ; } return 0 ; } finally { client . shutdown ( ) ; } } catch ( Throwable t ) { return handleError ( t ) ; } }
Executes the CANCEL action.
Executes the CANCEL action .
// evaluate help flag // Figure out jobID. This is a little overly complicated, because // we have to figure out whether the optional target directory // is set: // - cancel -s <jobID> => default target dir (JobID parsed as opt arg) // - cancel -s <targetDir> <jobID> => custom target dir (parsed correctly) // Try this for case: cancel -s <jobID> (default savepoint target dir)