Search in sources :

Example 31 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project kafka by apache.

the class AgentTest method testAgentFinishesTasks.

@Test
public void testAgentFinishesTasks() throws Exception {
    long startTimeMs = 2000;
    MockTime time = new MockTime(0, startTimeMs, 0);
    MockScheduler scheduler = new MockScheduler(time);
    Agent agent = createAgent(scheduler);
    AgentClient client = new AgentClient.Builder().maxTries(10).target("localhost", agent.port()).build();
    new ExpectedTasks().waitFor(client);
    final NoOpTaskSpec fooSpec = new NoOpTaskSpec(startTimeMs, 2);
    long fooSpecStartTimeMs = startTimeMs;
    client.createWorker(new CreateWorkerRequest(0, "foo", fooSpec));
    new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning("foo", fooSpec, startTimeMs, new TextNode("active"))).build()).waitFor(client);
    time.sleep(1);
    long barSpecWorkerId = 1;
    long barSpecStartTimeMs = startTimeMs + 1;
    final NoOpTaskSpec barSpec = new NoOpTaskSpec(startTimeMs, 900000);
    client.createWorker(new CreateWorkerRequest(barSpecWorkerId, "bar", barSpec));
    new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerRunning("foo", fooSpec, fooSpecStartTimeMs, new TextNode("active"))).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning("bar", barSpec, barSpecStartTimeMs, new TextNode("active"))).build()).waitFor(client);
    time.sleep(1);
    // foo task expired
    new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, fooSpecStartTimeMs, fooSpecStartTimeMs + 2, new TextNode("done"), "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerRunning("bar", barSpec, barSpecStartTimeMs, new TextNode("active"))).build()).waitFor(client);
    time.sleep(5);
    client.stopWorker(new StopWorkerRequest(barSpecWorkerId));
    new ExpectedTasks().addTask(new ExpectedTaskBuilder("foo").workerState(new WorkerDone("foo", fooSpec, fooSpecStartTimeMs, fooSpecStartTimeMs + 2, new TextNode("done"), "")).build()).addTask(new ExpectedTaskBuilder("bar").workerState(new WorkerDone("bar", barSpec, barSpecStartTimeMs, startTimeMs + 7, new TextNode("done"), "")).build()).waitFor(client);
    agent.beginShutdown();
    agent.waitForShutdown();
}
Also used : MockScheduler(org.apache.kafka.common.utils.MockScheduler) WorkerDone(org.apache.kafka.trogdor.rest.WorkerDone) WorkerRunning(org.apache.kafka.trogdor.rest.WorkerRunning) TextNode(com.fasterxml.jackson.databind.node.TextNode) ExpectedTaskBuilder(org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder) NoOpTaskSpec(org.apache.kafka.trogdor.task.NoOpTaskSpec) ExpectedTasks(org.apache.kafka.trogdor.common.ExpectedTasks) StopWorkerRequest(org.apache.kafka.trogdor.rest.StopWorkerRequest) CreateWorkerRequest(org.apache.kafka.trogdor.rest.CreateWorkerRequest) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test)

Example 32 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project kafka by apache.

the class DegradedNetworkFaultWorker method start.

@Override
public void start(Platform platform, WorkerStatusTracker status, KafkaFutureImpl<String> haltFuture) throws Exception {
    log.info("Activating DegradedNetworkFaultWorker {}.", id);
    this.status = status;
    this.status.update(new TextNode("enabling traffic control " + id));
    Node curNode = platform.curNode();
    DegradedNetworkFaultSpec.NodeDegradeSpec nodeSpec = nodeSpecs.get(curNode.name());
    if (nodeSpec != null) {
        for (String device : devicesForSpec(nodeSpec)) {
            if (nodeSpec.latencyMs() < 0 || nodeSpec.rateLimitKbit() < 0) {
                throw new RuntimeException("Expected non-negative values for latencyMs and rateLimitKbit, but got " + nodeSpec);
            } else {
                enableTrafficControl(platform, device, nodeSpec.latencyMs(), nodeSpec.rateLimitKbit());
            }
        }
    }
    this.status.update(new TextNode("enabled traffic control " + id));
}
Also used : Node(org.apache.kafka.trogdor.common.Node) TextNode(com.fasterxml.jackson.databind.node.TextNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 33 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project kafka by apache.

the class KiboshFaultWorker method start.

@Override
public void start(Platform platform, WorkerStatusTracker status, KafkaFutureImpl<String> errorFuture) throws Exception {
    log.info("Activating {} {}: {}.", spec.getClass().getSimpleName(), id, spec);
    this.status = status;
    this.status.update(new TextNode("Adding fault " + id));
    Kibosh.INSTANCE.addFault(mountPath, spec);
    this.status.update(new TextNode("Added fault " + id));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 34 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project kafka by apache.

the class KiboshFaultWorker method stop.

@Override
public void stop(Platform platform) throws Exception {
    log.info("Deactivating {} {}: {}.", spec.getClass().getSimpleName(), id, spec);
    this.status.update(new TextNode("Removing fault " + id));
    Kibosh.INSTANCE.removeFault(mountPath, spec);
    this.status.update(new TextNode("Removed fault " + id));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 35 with TextNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project kafka by apache.

the class ExternalCommandWorker method start.

@Override
public void start(Platform platform, WorkerStatusTracker status, KafkaFutureImpl<String> doneFuture) throws Exception {
    if (!running.compareAndSet(false, true)) {
        throw new IllegalStateException("ConsumeBenchWorker is already running.");
    }
    log.info("{}: Activating ExternalCommandWorker with {}", id, spec);
    this.status = status;
    this.doneFuture = doneFuture;
    this.executor = Executors.newCachedThreadPool(ThreadUtils.createThreadFactory("ExternalCommandWorkerThread%d", false));
    Process process = null;
    try {
        process = startProcess();
    } catch (Throwable t) {
        log.error("{}: Unable to start process", id, t);
        executor.shutdown();
        doneFuture.complete("Unable to start process: " + t.getMessage());
        return;
    }
    Future<?> stdoutFuture = executor.submit(new StdoutMonitor(process));
    Future<?> stderrFuture = executor.submit(new StderrMonitor(process));
    executor.submit(new StdinWriter(process));
    Future<?> terminatorFuture = executor.submit(new Terminator(process));
    executor.submit(new ExitMonitor(process, stdoutFuture, stderrFuture, terminatorFuture));
    ObjectNode startMessage = new ObjectNode(JsonNodeFactory.instance);
    startMessage.set("id", new TextNode(id));
    startMessage.set("workload", spec.workload());
    stdinQueue.add(Optional.of(startMessage));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Aggregations

TextNode (com.fasterxml.jackson.databind.node.TextNode)96 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)35 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)14 IntNode (com.fasterxml.jackson.databind.node.IntNode)14 MockScheduler (org.apache.kafka.common.utils.MockScheduler)14 MockTime (org.apache.kafka.common.utils.MockTime)14 ExpectedTaskBuilder (org.apache.kafka.trogdor.common.ExpectedTasks.ExpectedTaskBuilder)14 ExpectedTasks (org.apache.kafka.trogdor.common.ExpectedTasks)13 WorkerRunning (org.apache.kafka.trogdor.rest.WorkerRunning)12 NoOpTaskSpec (org.apache.kafka.trogdor.task.NoOpTaskSpec)11 ArrayList (java.util.ArrayList)9 Scheduler (org.apache.kafka.common.utils.Scheduler)9 MiniTrogdorCluster (org.apache.kafka.trogdor.common.MiniTrogdorCluster)9 CreateTaskRequest (org.apache.kafka.trogdor.rest.CreateTaskRequest)9 TaskRunning (org.apache.kafka.trogdor.rest.TaskRunning)9 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)8