Search in sources :

Example 1 with ExecutionTask

use of com.linkedin.kafka.cruisecontrol.executor.ExecutionTask in project cruise-control by linkedin.

the class KafkaCruiseControlServlet method getState.

private boolean getState(HttpServletRequest request, HttpServletResponse response) throws Exception {
    boolean verbose;
    boolean superVerbose;
    boolean json = wantJSON(request);
    try {
        String verboseString = request.getParameter(VERBOSE_PARAM);
        verbose = verboseString != null && Boolean.parseBoolean(verboseString);
        String superVerboseString = request.getParameter(SUPER_VERBOSE_PARM);
        superVerbose = superVerboseString != null && Boolean.parseBoolean(superVerboseString);
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        setErrorResponse(response, sw.toString(), e.getMessage(), SC_BAD_REQUEST, json);
        // Close session
        return true;
    }
    KafkaCruiseControlState state = getAndMaybeReturnProgress(request, response, _asyncKafkaCruiseControl::state);
    if (state == null) {
        return false;
    }
    OutputStream out = response.getOutputStream();
    if (json) {
        String stateString = state.getJSONString(JSON_VERSION);
        setJSONResponseCode(response, SC_OK);
        response.setContentLength(stateString.length());
        out.write(stateString.getBytes(StandardCharsets.UTF_8));
    } else {
        String stateString = state.toString();
        setResponseCode(response, SC_OK);
        out.write(stateString.getBytes(StandardCharsets.UTF_8));
        if (verbose || superVerbose) {
            out.write(String.format("%n%nMonitored Windows [Window End_Time=Data_Completeness]:%n").getBytes(StandardCharsets.UTF_8));
            StringJoiner joiner = new StringJoiner(", ", "{", "}");
            for (Map.Entry<Long, Float> entry : state.monitorState().monitoredWindows().entrySet()) {
                joiner.add(String.format("%d=%.3f%%", entry.getKey(), entry.getValue() * 100));
            }
            out.write(joiner.toString().getBytes(StandardCharsets.UTF_8));
            out.write(String.format("%n%nGoal Readiness:%n").getBytes(StandardCharsets.UTF_8));
            for (Map.Entry<Goal, Boolean> entry : state.analyzerState().readyGoals().entrySet()) {
                Goal goal = entry.getKey();
                out.write(String.format("%50s, %s, %s%n", goal.getClass().getSimpleName(), goal.clusterModelCompletenessRequirements(), entry.getValue() ? "Ready" : "NotReady").getBytes(StandardCharsets.UTF_8));
            }
            ExecutorState executorState = state.executorState();
            if (executorState.state() == ExecutorState.State.REPLICA_MOVEMENT_TASK_IN_PROGRESS || executorState.state() == ExecutorState.State.STOPPING_EXECUTION) {
                out.write(String.format("%n%nIn progress %s:%n", PARTITION_MOVEMENTS).getBytes(StandardCharsets.UTF_8));
                for (ExecutionTask task : executorState.inProgressPartitionMovements()) {
                    out.write(String.format("%s%n", task).getBytes(StandardCharsets.UTF_8));
                }
                out.write(String.format("%n%nAborting %s:%n", PARTITION_MOVEMENTS).getBytes(StandardCharsets.UTF_8));
                for (ExecutionTask task : executorState.abortingPartitionMovements()) {
                    out.write(String.format("%s%n", task).getBytes(StandardCharsets.UTF_8));
                }
                out.write(String.format("%n%nAborted %s:%n", PARTITION_MOVEMENTS).getBytes(StandardCharsets.UTF_8));
                for (ExecutionTask task : executorState.abortedPartitionMovements()) {
                    out.write(String.format("%s%n", task).getBytes(StandardCharsets.UTF_8));
                }
                out.write(String.format("%n%nDead %s:%n", PARTITION_MOVEMENTS).getBytes(StandardCharsets.UTF_8));
                for (ExecutionTask task : executorState.deadPartitionMovements()) {
                    out.write(String.format("%s%n", task).getBytes(StandardCharsets.UTF_8));
                }
                out.write(String.format("%n%n%s %s:%n", executorState.state() == ExecutorState.State.STOPPING_EXECUTION ? "Cancelled" : "Pending", PARTITION_MOVEMENTS).getBytes(StandardCharsets.UTF_8));
                for (ExecutionTask task : executorState.pendingPartitionMovements()) {
                    out.write(String.format("%s%n", task).getBytes(StandardCharsets.UTF_8));
                }
            }
            if (superVerbose) {
                out.write(String.format("%n%nExtrapolated metric samples:%n").getBytes(StandardCharsets.UTF_8));
                Map<TopicPartition, List<SampleExtrapolation>> sampleFlaws = state.monitorState().sampleExtrapolations();
                if (sampleFlaws != null && !sampleFlaws.isEmpty()) {
                    for (Map.Entry<TopicPartition, List<SampleExtrapolation>> entry : sampleFlaws.entrySet()) {
                        out.write(String.format("%n%s: %s", entry.getKey(), entry.getValue()).getBytes(StandardCharsets.UTF_8));
                    }
                } else {
                    out.write("None".getBytes(StandardCharsets.UTF_8));
                }
                out.write(String.format("%n%nLinear Regression Model State:%n%s", state.monitorState().detailTrainingProgress()).getBytes(StandardCharsets.UTF_8));
            }
        }
    }
    response.getOutputStream().flush();
    return true;
}
Also used : KafkaCruiseControlState(com.linkedin.kafka.cruisecontrol.KafkaCruiseControlState) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) ExecutionTask(com.linkedin.kafka.cruisecontrol.executor.ExecutionTask) TimeoutException(java.util.concurrent.TimeoutException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) KafkaAssignerEvenRackAwareGoal(com.linkedin.kafka.cruisecontrol.analyzer.kafkaassigner.KafkaAssignerEvenRackAwareGoal) Goal(com.linkedin.kafka.cruisecontrol.analyzer.goals.Goal) KafkaAssignerDiskUsageDistributionGoal(com.linkedin.kafka.cruisecontrol.analyzer.kafkaassigner.KafkaAssignerDiskUsageDistributionGoal) StringWriter(java.io.StringWriter) ExecutorState(com.linkedin.kafka.cruisecontrol.executor.ExecutorState) TopicPartition(org.apache.kafka.common.TopicPartition) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) StringJoiner(java.util.StringJoiner) PrintWriter(java.io.PrintWriter)

Aggregations

KafkaCruiseControlState (com.linkedin.kafka.cruisecontrol.KafkaCruiseControlState)1 Goal (com.linkedin.kafka.cruisecontrol.analyzer.goals.Goal)1 KafkaAssignerDiskUsageDistributionGoal (com.linkedin.kafka.cruisecontrol.analyzer.kafkaassigner.KafkaAssignerDiskUsageDistributionGoal)1 KafkaAssignerEvenRackAwareGoal (com.linkedin.kafka.cruisecontrol.analyzer.kafkaassigner.KafkaAssignerEvenRackAwareGoal)1 ExecutionTask (com.linkedin.kafka.cruisecontrol.executor.ExecutionTask)1 ExecutorState (com.linkedin.kafka.cruisecontrol.executor.ExecutorState)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 StringJoiner (java.util.StringJoiner)1 TreeMap (java.util.TreeMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1