org.apache.flink.runtime.client.JobStatusMessage Java Examples

The following examples show how to use org.apache.flink.runtime.client.JobStatusMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testListJobs() throws Exception {
	try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(new TestListJobsHandler())) {
		RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());

		try {
			CompletableFuture<Collection<JobStatusMessage>> jobDetailsFuture = restClusterClient.listJobs();
			Collection<JobStatusMessage> jobDetails = jobDetailsFuture.get();
			Iterator<JobStatusMessage> jobDetailsIterator = jobDetails.iterator();
			JobStatusMessage job1 = jobDetailsIterator.next();
			JobStatusMessage job2 = jobDetailsIterator.next();
			Assert.assertNotEquals("The job status should not be equal.", job1.getJobState(), job2.getJobState());
		} finally {
			restClusterClient.shutdown();
		}
	}
}
 
Example #2
Source File: ClusterClient.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Lists the currently running and finished jobs on the cluster.
 *
 * @return future collection of running and finished jobs
 * @throws Exception if no connection to the cluster could be established
 */
public CompletableFuture<Collection<JobStatusMessage>> listJobs() throws Exception {
	final ActorGateway jobManager = getJobManagerGateway();

	Future<Object> response = jobManager.ask(new RequestJobDetails(true, false), timeout);
	CompletableFuture<Object> responseFuture = FutureUtils.toJava(response);

	return responseFuture.thenApply((responseMessage) -> {
		if (responseMessage instanceof MultipleJobsDetails) {
			MultipleJobsDetails details = (MultipleJobsDetails) responseMessage;

			final Collection<JobDetails> jobDetails = details.getJobs();
			Collection<JobStatusMessage> flattenedDetails = new ArrayList<>(jobDetails.size());
			jobDetails.forEach(detail -> flattenedDetails.add(new JobStatusMessage(detail.getJobId(), detail.getJobName(), detail.getStatus(), detail.getStartTime())));
			return flattenedDetails;
		} else {
			throw new CompletionException(
				new IllegalStateException("Unknown JobManager response of type " + responseMessage.getClass()));
		}
	});
}
 
Example #3
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testListJobs() throws Exception {
	try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(new TestListJobsHandler())) {
		RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());

		try {
			CompletableFuture<Collection<JobStatusMessage>> jobDetailsFuture = restClusterClient.listJobs();
			Collection<JobStatusMessage> jobDetails = jobDetailsFuture.get();
			Iterator<JobStatusMessage> jobDetailsIterator = jobDetails.iterator();
			JobStatusMessage job1 = jobDetailsIterator.next();
			JobStatusMessage job2 = jobDetailsIterator.next();
			Assert.assertNotEquals("The job status should not be equal.", job1.getJobState(), job2.getJobState());
		} finally {
			restClusterClient.close();
		}
	}
}
 
Example #4
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testListJobs() throws Exception {
	try (TestRestServerEndpoint restServerEndpoint = createRestServerEndpoint(new TestListJobsHandler())) {
		RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());

		try {
			CompletableFuture<Collection<JobStatusMessage>> jobDetailsFuture = restClusterClient.listJobs();
			Collection<JobStatusMessage> jobDetails = jobDetailsFuture.get();
			Iterator<JobStatusMessage> jobDetailsIterator = jobDetails.iterator();
			JobStatusMessage job1 = jobDetailsIterator.next();
			JobStatusMessage job2 = jobDetailsIterator.next();
			Assert.assertNotEquals("The job status should not be equal.", job1.getJobState(), job2.getJobState());
		} finally {
			restClusterClient.shutdown();
		}
	}
}
 
Example #5
Source File: FlinkSavepointTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private JobID waitForJobToBeReady() throws InterruptedException, ExecutionException {
  while (true) {
    JobStatusMessage jobStatus = Iterables.getFirst(flinkCluster.listJobs().get(), null);
    if (jobStatus != null && jobStatus.getJobState().name().equals("RUNNING")) {
      return jobStatus.getJobId();
    }
    Thread.sleep(100);
  }
}
 
Example #6
Source File: MiniCluster.java    From flink with Apache License 2.0 5 votes vote down vote up
public CompletableFuture<Collection<JobStatusMessage>> listJobs() {
	return runDispatcherCommand(dispatcherGateway ->
		dispatcherGateway
			.requestMultipleJobDetails(rpcTimeout)
			.thenApply(jobs ->
				jobs.getJobs().stream()
					.map(details -> new JobStatusMessage(details.getJobId(), details.getJobName(), details.getStatus(), details.getStartTime()))
					.collect(Collectors.toList())));
}
 
Example #7
Source File: RestClusterClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Collection<JobStatusMessage>> listJobs() {
	return sendRequest(JobsOverviewHeaders.getInstance())
		.thenApply(
			(multipleJobsDetails) -> multipleJobsDetails
				.getJobs()
				.stream()
				.map(detail -> new JobStatusMessage(
					detail.getJobId(),
					detail.getJobName(),
					detail.getStatus(),
					detail.getStartTime()))
				.collect(Collectors.toList()));
}
 
Example #8
Source File: ClusterCommunicationUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #9
Source File: CliFrontend.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void printJobStatusMessages(List<JobStatusMessage> jobs) {
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
	Comparator<JobStatusMessage> startTimeComparator = (o1, o2) -> (int) (o1.getStartTime() - o2.getStartTime());
	Comparator<Map.Entry<JobStatus, List<JobStatusMessage>>> statusComparator =
		(o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey().toString(), o2.getKey().toString());

	Map<JobStatus, List<JobStatusMessage>> jobsByState = jobs.stream().collect(Collectors.groupingBy(JobStatusMessage::getJobState));
	jobsByState.entrySet().stream()
		.sorted(statusComparator)
		.map(Map.Entry::getValue).flatMap(List::stream).sorted(startTimeComparator)
		.forEachOrdered(job ->
			System.out.println(dateFormat.format(new Date(job.getStartTime()))
				+ " : " + job.getJobId() + " : " + job.getJobName()
				+ " (" + job.getJobState() + ")"));
}
 
Example #10
Source File: CliFrontendListTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static ClusterClient<String> createClusterClient() throws Exception {
	final ClusterClient<String> clusterClient = mock(ClusterClient.class);
	when(clusterClient.listJobs()).thenReturn(CompletableFuture.completedFuture(Arrays.asList(
		new JobStatusMessage(new JobID(), "job1", JobStatus.RUNNING, 1L),
		new JobStatusMessage(new JobID(), "job2", JobStatus.CREATED, 1L),
		new JobStatusMessage(new JobID(), "job3", JobStatus.FINISHED, 3L)
	)));
	return clusterClient;
}
 
Example #11
Source File: RestClusterClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Collection<JobStatusMessage>> listJobs() {
	return sendRequest(JobsOverviewHeaders.getInstance())
		.thenApply(
			(multipleJobsDetails) -> multipleJobsDetails
				.getJobs()
				.stream()
				.map(detail -> new JobStatusMessage(
					detail.getJobId(),
					detail.getJobName(),
					detail.getStatus(),
					detail.getStartTime()))
				.collect(Collectors.toList()));
}
 
Example #12
Source File: FlinkSavepointTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@After
public void afterTest() throws Exception {
  for (JobStatusMessage jobStatusMessage : flinkCluster.listJobs().get()) {
    if (jobStatusMessage.getJobState().name().equals("RUNNING")) {
      flinkCluster.cancelJob(jobStatusMessage.getJobId()).get();
    }
  }
  while (!flinkCluster.listJobs().get().stream()
      .allMatch(job -> job.getJobState().isTerminalState())) {
    Thread.sleep(50);
  }
}
 
Example #13
Source File: ProcessFailureCancelingITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private Collection<JobID> waitForRunningJobs(ClusterClient<?> clusterClient, Time timeout) throws ExecutionException, InterruptedException {
	return FutureUtils.retrySuccessfulWithDelay(
			CheckedSupplier.unchecked(clusterClient::listJobs),
			Time.milliseconds(50L),
			Deadline.fromNow(Duration.ofMillis(timeout.toMilliseconds())),
			jobs -> !jobs.isEmpty(),
			TestingUtils.defaultScheduledExecutor())
		.get()
		.stream()
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #14
Source File: FlinkSubmissionTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private void waitUntilJobIsCompleted() throws Exception {
  while (true) {
    Collection<JobStatusMessage> allJobsStates = flinkCluster.listJobs().get();
    if (allJobsStates.size() == expectedNumberOfJobs
        && allJobsStates.stream()
            .allMatch(jobStatus -> jobStatus.getJobState().name().equals("FINISHED"))) {
      return;
    }
    Thread.sleep(50);
  }
}
 
Example #15
Source File: ClusterCommunicationUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #16
Source File: MiniCluster.java    From flink with Apache License 2.0 5 votes vote down vote up
public CompletableFuture<Collection<JobStatusMessage>> listJobs() {
	return runDispatcherCommand(dispatcherGateway ->
		dispatcherGateway
			.requestMultipleJobDetails(rpcTimeout)
			.thenApply(jobs ->
				jobs.getJobs().stream()
					.map(details -> new JobStatusMessage(details.getJobId(), details.getJobName(), details.getStatus(), details.getStartTime()))
					.collect(Collectors.toList())));
}
 
Example #17
Source File: RescalingITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #18
Source File: WebFrontendITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #19
Source File: TimestampITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #20
Source File: ProcessFailureCancelingITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private Collection<JobID> waitForRunningJobs(ClusterClient<?> clusterClient, Time timeout) throws ExecutionException, InterruptedException {
	return FutureUtils.retrySuccessfulWithDelay(
			CheckedSupplier.unchecked(clusterClient::listJobs),
			Time.milliseconds(50L),
			Deadline.fromNow(Duration.ofMillis(timeout.toMilliseconds())),
			jobs -> !jobs.isEmpty(),
			TestingUtils.defaultScheduledExecutor())
		.get()
		.stream()
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #21
Source File: CliFrontendListTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static ClusterClient<String> createClusterClient() throws Exception {
	final ClusterClient<String> clusterClient = mock(ClusterClient.class);
	when(clusterClient.listJobs()).thenReturn(CompletableFuture.completedFuture(Arrays.asList(
		new JobStatusMessage(new JobID(), "job1", JobStatus.RUNNING, 1L),
		new JobStatusMessage(new JobID(), "job2", JobStatus.CREATED, 1L),
		new JobStatusMessage(new JobID(), "job3", JobStatus.FINISHED, 3L)
	)));
	return clusterClient;
}
 
Example #22
Source File: CliFrontendListTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static ClusterClient<String> createClusterClient() throws Exception {
	final ClusterClient<String> clusterClient = mock(ClusterClient.class);
	when(clusterClient.listJobs()).thenReturn(CompletableFuture.completedFuture(Arrays.asList(
		new JobStatusMessage(new JobID(), "job1", JobStatus.RUNNING, 1L),
		new JobStatusMessage(new JobID(), "job2", JobStatus.CREATED, 1L),
		new JobStatusMessage(new JobID(), "job3", JobStatus.FINISHED, 3L)
	)));
	return clusterClient;
}
 
Example #23
Source File: RescalingITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #24
Source File: TimestampITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #25
Source File: ProcessFailureCancelingITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private Collection<JobID> waitForRunningJobs(ClusterClient<?> clusterClient, Time timeout) throws ExecutionException, InterruptedException {
	return FutureUtils.retrySuccessfulWithDelay(
			CheckedSupplier.unchecked(clusterClient::listJobs),
			Time.milliseconds(50L),
			Deadline.fromNow(Duration.ofMillis(timeout.toMilliseconds())),
			jobs -> !jobs.isEmpty(),
			TestingUtils.defaultScheduledExecutor())
		.get()
		.stream()
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #26
Source File: WebFrontendITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}
 
Example #27
Source File: MiniCluster.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public CompletableFuture<Collection<JobStatusMessage>> listJobs() {
	return runDispatcherCommand(dispatcherGateway ->
		dispatcherGateway
			.requestMultipleJobDetails(rpcTimeout)
			.thenApply(jobs ->
				jobs.getJobs().stream()
					.map(details -> new JobStatusMessage(details.getJobId(), details.getJobName(), details.getStatus(), details.getStartTime()))
					.collect(Collectors.toList())));
}
 
Example #28
Source File: RestClusterClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Collection<JobStatusMessage>> listJobs() {
	return sendRequest(JobsOverviewHeaders.getInstance())
		.thenApply(
			(multipleJobsDetails) -> multipleJobsDetails
				.getJobs()
				.stream()
				.map(detail -> new JobStatusMessage(
					detail.getJobId(),
					detail.getJobName(),
					detail.getStatus(),
					detail.getStartTime()))
				.collect(Collectors.toList()));
}
 
Example #29
Source File: CliFrontend.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void printJobStatusMessages(List<JobStatusMessage> jobs) {
	SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
	Comparator<JobStatusMessage> startTimeComparator = (o1, o2) -> (int) (o1.getStartTime() - o2.getStartTime());
	Comparator<Map.Entry<JobStatus, List<JobStatusMessage>>> statusComparator =
		(o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey().toString(), o2.getKey().toString());

	Map<JobStatus, List<JobStatusMessage>> jobsByState = jobs.stream().collect(Collectors.groupingBy(JobStatusMessage::getJobState));
	jobsByState.entrySet().stream()
		.sorted(statusComparator)
		.map(Map.Entry::getValue).flatMap(List::stream).sorted(startTimeComparator)
		.forEachOrdered(job ->
			System.out.println(dateFormat.format(new Date(job.getStartTime()))
				+ " : " + job.getJobId() + " : " + job.getJobName()
				+ " (" + job.getJobState() + ")"));
}
 
Example #30
Source File: WebFrontendITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static List<JobID> getRunningJobs(ClusterClient<?> client) throws Exception {
	Collection<JobStatusMessage> statusMessages = client.listJobs().get();
	return statusMessages.stream()
		.filter(status -> !status.getJobState().isGloballyTerminalState())
		.map(JobStatusMessage::getJobId)
		.collect(Collectors.toList());
}