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;
}
Aggregations