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 list action.
	 *
	 * @param args Command line arguments for the list action.
	 */
Executes the list action.
@param args Command line arguments for the list action.
Executes the list action . @param args Command line arguments for the list action .
protected int list(String[] args) {
		LOG.info("Running 'list' command.");
		ListOptions options;
		try {
			options = CliFrontendParser.parseListCommand(args);
		}
		catch (CliArgsException e) {
			return handleArgException(e);
		}
		catch (Throwable t) {
			return handleError(t);
		}
		if (options.isPrintHelp()) {
			CliFrontendParser.printHelpForList();
			return 0;
		}
		boolean running = options.getRunning();
		boolean scheduled = options.getScheduled();
		if (!running && !scheduled) {
			running = true;
			scheduled = true;
		}
		try {
			CustomCommandLine<?> activeCommandLine = getActiveCustomCommandLine(options.getCommandLine());
			ClusterClient client = activeCommandLine.retrieveCluster(options.getCommandLine(), config, configurationDirectory);
			Collection<JobStatusMessage> jobDetails;
			try {
				CompletableFuture<Collection<JobStatusMessage>> jobDetailsFuture = client.listJobs();
				try {
					logAndSysout("Waiting for response...");
					jobDetails = jobDetailsFuture.get();
				}
				catch (ExecutionException ee) {
					Throwable cause = ExceptionUtils.stripExecutionException(ee);
					throw new Exception("Failed to retrieve job list.", cause);
				}
			} finally {
				client.shutdown();
			}
			LOG.info("Successfully retrieved list of jobs");
			SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
			Comparator<JobStatusMessage> startTimeComparator = (o1, o2) -> (int) (o1.getStartTime() - o2.getStartTime());
			final List<JobStatusMessage> runningJobs = new ArrayList<>();
			final List<JobStatusMessage> scheduledJobs = new ArrayList<>();
			jobDetails.forEach(details -> {
				if (details.getJobState() == JobStatus.CREATED) {
					scheduledJobs.add(details);
				} else {
					runningJobs.add(details);
				}
			});
			if (running) {
				if (runningJobs.size() == 0) {
					System.out.println("No running jobs.");
				}
				else {
					runningJobs.sort(startTimeComparator);
					System.out.println("------------------ Running/Restarting Jobs -------------------");
					for (JobStatusMessage runningJob : runningJobs) {
						System.out.println(dateFormat.format(new Date(runningJob.getStartTime()))
							+ " : " + runningJob.getJobId() + " : " + runningJob.getJobName() + " (" + runningJob.getJobState() + ")");
					}
					System.out.println("--------------------------------------------------------------");
				}
			}
			if (scheduled) {
				if (scheduledJobs.size() == 0) {
					System.out.println("No scheduled jobs.");
				}
				else {
					scheduledJobs.sort(startTimeComparator);
					System.out.println("----------------------- Scheduled Jobs -----------------------");
					for (JobStatusMessage scheduledJob : scheduledJobs) {
						System.out.println(dateFormat.format(new Date(scheduledJob.getStartTime()))
							+ " : " + scheduledJob.getJobId() + " : " + scheduledJob.getJobName());
					}
					System.out.println("--------------------------------------------------------------");
				}
			}
			return 0;
		}
		catch (Throwable t) {
			return handleError(t);
		}
	}
protected int list ( String [ ] args ) { LOG . info ( "Running 'list' command." ) ; ListOptions options ; try { options = CliFrontendParser . parseListCommand ( args ) ; } catch ( CliArgsException e ) { return handleArgException ( e ) ; } catch ( Throwable t ) { return handleError ( t ) ; } if ( options . isPrintHelp ( ) ) { CliFrontendParser . printHelpForList ( ) ; return 0 ; } boolean running = options . getRunning ( ) ; boolean scheduled = options . getScheduled ( ) ; if ( ! running && ! scheduled ) { running = true ; scheduled = true ; } try { CustomCommandLine < ? > activeCommandLine = getActiveCustomCommandLine ( options . getCommandLine ( ) ) ; ClusterClient client = activeCommandLine . retrieveCluster ( options . getCommandLine ( ) , config , configurationDirectory ) ; Collection < JobStatusMessage > jobDetails ; try { CompletableFuture < Collection < JobStatusMessage > > jobDetailsFuture = client . listJobs ( ) ; try { logAndSysout ( "Waiting for response..." ) ; jobDetails = jobDetailsFuture . get ( ) ; } catch ( ExecutionException ee ) { Throwable cause = ExceptionUtils . stripExecutionException ( ee ) ; throw new Exception ( "Failed to retrieve job list." , cause ) ; } } finally { client . shutdown ( ) ; } LOG . info ( "Successfully retrieved list of jobs" ) ; SimpleDateFormat dateFormat = new SimpleDateFormat ( "dd.MM.yyyy HH:mm:ss" ) ; Comparator < JobStatusMessage > startTimeComparator = ( o1 , o2 ) -> ( int ) ( o1 . getStartTime ( ) - o2 . getStartTime ( ) ) ; final List < JobStatusMessage > runningJobs = new ArrayList < > ( ) ; final List < JobStatusMessage > scheduledJobs = new ArrayList < > ( ) ; jobDetails . forEach ( details -> { if ( details . getJobState ( ) == JobStatus . CREATED ) { scheduledJobs . add ( details ) ; } else { runningJobs . add ( details ) ; } } ) ; if ( running ) { if ( runningJobs . size ( ) == 0 ) { System . out . println ( "No running jobs." ) ; } else { runningJobs . sort ( startTimeComparator ) ; System . out . println ( "------------------ Running/Restarting Jobs -------------------" ) ; for ( JobStatusMessage runningJob : runningJobs ) { System . out . println ( dateFormat . format ( new Date ( runningJob . getStartTime ( ) ) ) + " : " + runningJob . getJobId ( ) + " : " + runningJob . getJobName ( ) + " (" + runningJob . getJobState ( ) + ")" ) ; } System . out . println ( "--------------------------------------------------------------" ) ; } } if ( scheduled ) { if ( scheduledJobs . size ( ) == 0 ) { System . out . println ( "No scheduled jobs." ) ; } else { scheduledJobs . sort ( startTimeComparator ) ; System . out . println ( "----------------------- Scheduled Jobs -----------------------" ) ; for ( JobStatusMessage scheduledJob : scheduledJobs ) { System . out . println ( dateFormat . format ( new Date ( scheduledJob . getStartTime ( ) ) ) + " : " + scheduledJob . getJobId ( ) + " : " + scheduledJob . getJobName ( ) ) ; } System . out . println ( "--------------------------------------------------------------" ) ; } } return 0 ; } catch ( Throwable t ) { return handleError ( t ) ; } }
Executes the list action.
Executes the list action .
// evaluate help flag // print running and scheduled jobs if not option supplied