use of io.cdap.cdap.cli.util.RowMaker in project cdap by cdapio.
the class GetWorkflowTokenCommand method getWorkflowToken.
private Table getWorkflowToken(ProgramRunId runId, WorkflowToken.Scope workflowTokenScope, String key, String nodeName) throws UnauthenticatedException, IOException, NotFoundException, UnauthorizedException {
WorkflowTokenNodeDetail workflowToken = workflowClient.getWorkflowTokenAtNode(runId, nodeName, workflowTokenScope, key);
List<Map.Entry<String, String>> tokenKeys = new ArrayList<>();
tokenKeys.addAll(workflowToken.getTokenDataAtNode().entrySet());
return Table.builder().setHeader("token key", "token value").setRows(tokenKeys, new RowMaker<Map.Entry<String, String>>() {
@Override
public List<?> makeRow(Map.Entry<String, String> object) {
return Lists.newArrayList(object.getKey(), object.getValue());
}
}).build();
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by cdapio.
the class ListRolesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String principalType = arguments.getOptional(ArgumentName.PRINCIPAL_TYPE.toString());
String principalName = arguments.getOptional(ArgumentName.PRINCIPAL_NAME.toString());
Set<Role> roles;
if (!(Strings.isNullOrEmpty(principalType) && Strings.isNullOrEmpty(principalName))) {
roles = client.listRoles(new Principal(principalName, Principal.PrincipalType.valueOf(principalType.toUpperCase())));
} else {
roles = client.listAllRoles();
}
Table table = Table.builder().setHeader("Role").setRows(Lists.newArrayList(roles), new RowMaker<Role>() {
@Override
public List<?> makeRow(Role role) {
return Lists.newArrayList(role.getName());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by cdapio.
the class ListWorkflowSchedulesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String[] programIdParts = arguments.get(ElementType.WORKFLOW.getArgumentName().toString()).split("\\.");
if (programIdParts.length < 2) {
throw new CommandInputError(this);
}
final String appId = programIdParts[0];
String workflowName = programIdParts[1];
WorkflowId workflowId = cliConfig.getCurrentNamespace().app(appId).workflow(workflowName);
List<ScheduleDetail> list = scheduleClient.listSchedules(workflowId);
Table table = Table.builder().setHeader("application", "program", "program type", "name", "description", "trigger", "timeoutMillis", "properties").setRows(list, new RowMaker<ScheduleDetail>() {
@Override
public List<?> makeRow(ScheduleDetail object) {
return Lists.newArrayList(appId, object.getProgram().getProgramName(), object.getProgram().getProgramType().name(), object.getName(), object.getDescription(), object.getTrigger(), object.getTimeoutMillis(), GSON.toJson(object.getProperties()));
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class GetMetricCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String metric = arguments.get("metric-name");
Map<String, String> tags = ArgumentParser.parseMap(arguments.getOptional("tags", ""), "<tags>");
String start = arguments.getOptional("start", "");
String end = arguments.getOptional("end", "");
MetricQueryResult result = client.query(tags, ImmutableList.of(metric), ImmutableList.<String>of(), start.isEmpty() ? null : start, end.isEmpty() ? null : end);
output.printf("Start time: %d\n", result.getStartTime());
output.printf("End time: %d\n", result.getEndTime());
for (MetricQueryResult.TimeSeries series : result.getSeries()) {
output.println();
output.printf("Series: %s\n", series.getMetricName());
if (!series.getGrouping().isEmpty()) {
output.printf("Grouping: %s\n", Joiner.on(",").withKeyValueSeparator("=").join(series.getGrouping()));
}
Table table = Table.builder().setHeader("timestamp", "value").setRows(ImmutableList.copyOf(series.getData()), new RowMaker<MetricQueryResult.TimeValue>() {
@Override
public List<?> makeRow(MetricQueryResult.TimeValue object) {
return Lists.newArrayList(object.getTime(), object.getValue());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class StatusProgramsCommand method runBatchCommand.
@Override
protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception {
List<BatchProgramStatus> results = programClient.getStatus(args.appId.getParent(), args.programs);
Table table = Table.builder().setHeader("name", "type", "status", "error").setRows(results, new RowMaker<BatchProgramStatus>() {
@Override
public List<?> makeRow(BatchProgramStatus result) {
return Lists.newArrayList(result.getProgramId(), result.getProgramType(), result.getStatus(), result.getError());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, printStream, table);
}
Aggregations