use of org.apache.samza.sql.client.interfaces.ExecutionStatus in project samza by apache.
the class CliCommandHandler method commandLs.
private void commandLs(CliCommand command) {
List<Integer> execIds = new ArrayList<>();
String parameters = command.getParameters();
if (CliUtil.isNullOrEmpty(parameters)) {
execIds.addAll(executions.keySet());
} else {
execIds.addAll(splitExecutionIds(parameters));
}
if (execIds.size() == 0) {
return;
}
execIds.sort(Integer::compareTo);
final int terminalWidth = terminal.getWidth();
final int idWidth = 3;
final int statusWidth = 20;
final int cmdWidth = terminalWidth - idWidth - statusWidth - 4;
AttributedStyle oddLineStyle = AttributedStyle.DEFAULT.BOLD.foreground(AttributedStyle.BLUE);
AttributedStyle evenLineStyle = AttributedStyle.DEFAULT.BOLD.foreground(AttributedStyle.CYAN);
for (int i = 0; i < execIds.size(); ++i) {
Integer id = execIds.get(i);
String cmd = executions.get(id);
if (cmd == null)
continue;
String status = "UNKNOWN";
try {
ExecutionStatus execStatus = executor.queryExecutionStatus(id);
status = execStatus.name();
} catch (ExecutorException e) {
LOG.error("Error in commandLs: ", e);
}
int cmdStartIdx = 0;
int cmdLength = cmd.length();
StringBuilder line;
while (cmdStartIdx < cmdLength) {
line = new StringBuilder(terminalWidth);
if (cmdStartIdx == 0) {
line.append(CliConstants.SPACE);
line.append(id);
CliUtil.appendTo(line, 1 + idWidth + 1, CliConstants.SPACE);
line.append(status);
}
CliUtil.appendTo(line, 1 + idWidth + 1 + statusWidth + 1, CliConstants.SPACE);
int numToWrite = Math.min(cmdWidth, cmdLength - cmdStartIdx);
if (numToWrite > 0) {
line.append(cmd, cmdStartIdx, cmdStartIdx + numToWrite);
cmdStartIdx += numToWrite;
}
if (i % 2 == 0) {
AttributedStringBuilder attrBuilder = new AttributedStringBuilder().style(evenLineStyle);
attrBuilder.append(line.toString());
writer.println(attrBuilder.toAnsi());
} else {
AttributedStringBuilder attrBuilder = new AttributedStringBuilder().style(oddLineStyle);
attrBuilder.append(line.toString());
writer.println(attrBuilder.toAnsi());
}
}
}
writer.flush();
}
use of org.apache.samza.sql.client.interfaces.ExecutionStatus in project samza by apache.
the class CliCommandHandler method commandRm.
private void commandRm(CliCommand command) {
String parameters = command.getParameters();
List<Integer> execIds = new ArrayList<>();
execIds.addAll(splitExecutionIds(parameters));
for (Integer id : execIds) {
try {
ExecutionStatus status = executor.queryExecutionStatus(id);
if (status == ExecutionStatus.Running) {
writer.println(String.format("Execution %d is still running. Stop it first.", id));
continue;
}
executor.removeExecution(exeContext, id);
executions.remove(id);
} catch (ExecutorException e) {
writer.println("Error: " + e);
LOG.error("Error in commandRm: ", e);
}
}
writer.flush();
}
Aggregations