Search in sources :

Example 6 with TaskState

use of org.apache.kafka.trogdor.rest.TaskState in project kafka by apache.

the class CoordinatorTest method testTaskRequest.

@Test
public void testTaskRequest() throws Exception {
    MockTime time = new MockTime(0, 0, 0);
    Scheduler scheduler = new MockScheduler(time);
    try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").addAgent("node02").scheduler(scheduler).build()) {
        CoordinatorClient coordinatorClient = cluster.coordinatorClient();
        NoOpTaskSpec fooSpec = new NoOpTaskSpec(1, 10);
        coordinatorClient.createTask(new CreateTaskRequest("foo", fooSpec));
        TaskState expectedState = new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build().taskState();
        TaskState resp = coordinatorClient.task(new TaskRequest("foo"));
        assertEquals(expectedState, resp);
        time.sleep(2);
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 2, new TextNode("active"))).workerState(new WorkerRunning("foo", fooSpec, 2, new TextNode("active"))).build()).waitFor(coordinatorClient).waitFor(cluster.agentClient("node02"));
        assertThrows(NotFoundException.class, () -> coordinatorClient.task(new TaskRequest("non-existent-foo")));
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) TextNode(com.fasterxml.jackson.databind.node.TextNode) DestroyTaskRequest(org.apache.kafka.trogdor.rest.DestroyTaskRequest) StopTaskRequest(org.apache.kafka.trogdor.rest.StopTaskRequest) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) TaskRequest(org.apache.kafka.trogdor.rest.TaskRequest) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) TaskPending(org.apache.kafka.trogdor.rest.TaskPending) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) MiniTrogdorCluster(org.apache.kafka.trogdor.common.MiniTrogdorCluster) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) TaskState(org.apache.kafka.trogdor.rest.TaskState) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 7 with TaskState

use of org.apache.kafka.trogdor.rest.TaskState in project kafka by apache.

the class CoordinatorTest method testAgentFailureAndTaskExpiry.

/**
 * If an agent fails in the middle of a task and comes back up when the task is considered expired,
 * we want the task to be marked as DONE and not re-sent should a second failure happen.
 */
@Test
public void testAgentFailureAndTaskExpiry() throws Exception {
    MockTime time = new MockTime(0, 0, 0);
    Scheduler scheduler = new MockScheduler(time);
    try (MiniTrogdorCluster cluster = new MiniTrogdorCluster.Builder().addCoordinator("node01").addAgent("node02").scheduler(scheduler).build()) {
        CoordinatorClient coordinatorClient = cluster.coordinatorClient();
        NoOpTaskSpec fooSpec = new NoOpTaskSpec(1, 500);
        coordinatorClient.createTask(new CreateTaskRequest("foo", fooSpec));
        TaskState expectedState = new ExpectedTaskBuilder("foo").taskState(new TaskPending(fooSpec)).build().taskState();
        TaskState resp = coordinatorClient.task(new TaskRequest("foo"));
        assertEquals(expectedState, resp);
        time.sleep(2);
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskRunning(fooSpec, 2, new TextNode("active"))).workerState(new WorkerRunning("foo", fooSpec, 2, new TextNode("active"))).build()).waitFor(coordinatorClient).waitFor(cluster.agentClient("node02"));
        cluster.restartAgent("node02");
        time.sleep(550);
        // coordinator heartbeat sees that the agent is back up, re-schedules the task but the agent expires it
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 2, 552, "worker expired", false, null)).workerState(new WorkerDone("foo", fooSpec, 552, 552, null, "worker expired")).build()).waitFor(coordinatorClient).waitFor(cluster.agentClient("node02"));
        cluster.restartAgent("node02");
        // coordinator heartbeat sees that the agent is back up but does not re-schedule the task as it is DONE
        new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").taskState(new TaskDone(fooSpec, 2, 552, "worker expired", false, null)).build()).waitFor(coordinatorClient).waitFor(cluster.agentClient("node02"));
    }
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) MockScheduler(org.apache.kafka.common.utils.MockScheduler) Scheduler(org.apache.kafka.common.utils.Scheduler) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) TaskDone(org.apache.kafka.trogdor.rest.TaskDone) TextNode(com.fasterxml.jackson.databind.node.TextNode) DestroyTaskRequest(org.apache.kafka.trogdor.rest.DestroyTaskRequest) StopTaskRequest(org.apache.kafka.trogdor.rest.StopTaskRequest) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) TaskRequest(org.apache.kafka.trogdor.rest.TaskRequest) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) TaskPending(org.apache.kafka.trogdor.rest.TaskPending) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) CreateTaskRequest(org.apache.kafka.trogdor.rest.CreateTaskRequest) MiniTrogdorCluster(org.apache.kafka.trogdor.common.MiniTrogdorCluster) TaskRunning(org.apache.kafka.trogdor.rest.TaskRunning) TaskState(org.apache.kafka.trogdor.rest.TaskState) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Aggregations

TaskState (org.apache.kafka.trogdor.rest.TaskState)7 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)5 DestroyTaskRequest (org.apache.kafka.trogdor.rest.DestroyTaskRequest)5 StopTaskRequest (org.apache.kafka.trogdor.rest.StopTaskRequest)5 TaskRequest (org.apache.kafka.trogdor.rest.TaskRequest)5 MockScheduler (org.apache.kafka.common.utils.MockScheduler)4 MockTime (org.apache.kafka.common.utils.MockTime)4 Scheduler (org.apache.kafka.common.utils.Scheduler)4 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)4 MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)4 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)4 Test (org.junit.jupiter.api.Test)4 TextNode (com.fasterxml.jackson.databind.node.TextNode)3 StringFormatter.dateString (org.apache.kafka.trogdor.common.StringFormatter.dateString)3 StringFormatter.durationString (org.apache.kafka.trogdor.common.StringFormatter.durationString)3 TaskPending (org.apache.kafka.trogdor.rest.TaskPending)3 TaskRunning (org.apache.kafka.trogdor.rest.TaskRunning)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2