Search in sources :

Example 1 with TaskThreadInfoResponse

use of org.apache.flink.runtime.messages.TaskThreadInfoResponse in project flink by apache.

the class ThreadInfoRequestCoordinatorTest method createMockTaskManagerGateway.

private static CompletableFuture<TaskExecutorThreadInfoGateway> createMockTaskManagerGateway(CompletionType completionType) {
    final CompletableFuture<TaskThreadInfoResponse> responseFuture = new CompletableFuture<>();
    switch(completionType) {
        case SUCCESSFULLY:
            ThreadInfoSample sample = JvmUtils.createThreadInfoSample(Thread.currentThread().getId(), 100).get();
            responseFuture.complete(new TaskThreadInfoResponse(Collections.singletonList(sample)));
            break;
        case EXCEPTIONALLY:
            responseFuture.completeExceptionally(new RuntimeException("Request failed."));
            break;
        case TIMEOUT:
            executorService.schedule(() -> responseFuture.completeExceptionally(new TimeoutException(REQUEST_TIMEOUT_MESSAGE)), REQUEST_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
            break;
        case NEVER_COMPLETE:
            // do nothing
            break;
        default:
            throw new RuntimeException("Unknown completion type.");
    }
    final TaskExecutorThreadInfoGateway executorGateway = (taskExecutionAttemptId, requestParams, timeout) -> responseFuture;
    return CompletableFuture.completedFuture(executorGateway);
}
Also used : Matchers.emptyArray(org.hamcrest.Matchers.emptyArray) TaskThreadInfoResponse(org.apache.flink.runtime.messages.TaskThreadInfoResponse) BeforeClass(org.junit.BeforeClass) Matchers.not(org.hamcrest.Matchers.not) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) After(org.junit.After) Duration(java.time.Duration) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) Timeout(org.junit.rules.Timeout) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) AfterClass(org.junit.AfterClass) JvmUtils(org.apache.flink.runtime.util.JvmUtils) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) List(java.util.List) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TaskExecutorThreadInfoGateway(org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway) TaskThreadInfoResponse(org.apache.flink.runtime.messages.TaskThreadInfoResponse) CompletableFuture(java.util.concurrent.CompletableFuture) ThreadInfoSample(org.apache.flink.runtime.messages.ThreadInfoSample) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with TaskThreadInfoResponse

use of org.apache.flink.runtime.messages.TaskThreadInfoResponse in project flink by apache.

the class TaskExecutor method requestThreadInfoSamples.

// ======================================================================
// RPC methods
// ======================================================================
@Override
public CompletableFuture<TaskThreadInfoResponse> requestThreadInfoSamples(final ExecutionAttemptID taskExecutionAttemptId, final ThreadInfoSamplesRequest requestParams, final Time timeout) {
    final Task task = taskSlotTable.getTask(taskExecutionAttemptId);
    if (task == null) {
        return FutureUtils.completedExceptionally(new IllegalStateException(String.format("Cannot sample task %s. " + "Task is not known to the task manager.", taskExecutionAttemptId)));
    }
    final CompletableFuture<List<ThreadInfoSample>> stackTracesFuture = threadInfoSampleService.requestThreadInfoSamples(SampleableTaskAdapter.fromTask(task), requestParams);
    return stackTracesFuture.thenApply(TaskThreadInfoResponse::new);
}
Also used : Task(org.apache.flink.runtime.taskmanager.Task) TaskThreadInfoResponse(org.apache.flink.runtime.messages.TaskThreadInfoResponse) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 TaskThreadInfoResponse (org.apache.flink.runtime.messages.TaskThreadInfoResponse)2 Duration (java.time.Duration)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)1 ThreadInfoSample (org.apache.flink.runtime.messages.ThreadInfoSample)1 TaskExecutorThreadInfoGateway (org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway)1 Task (org.apache.flink.runtime.taskmanager.Task)1 JvmUtils (org.apache.flink.runtime.util.JvmUtils)1 ImmutableList (org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList)1 ExceptionUtils (org.apache.flink.util.ExceptionUtils)1