Search in sources :

Example 31 with RowMaker

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();
}
Also used : RowMaker(io.cdap.cdap.cli.util.RowMaker) WorkflowTokenNodeDetail(io.cdap.cdap.proto.WorkflowTokenNodeDetail) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 32 with RowMaker

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);
}
Also used : Role(io.cdap.cdap.proto.security.Role) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) Principal(io.cdap.cdap.proto.security.Principal)

Example 33 with RowMaker

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);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) WorkflowId(io.cdap.cdap.proto.id.WorkflowId)

Example 34 with RowMaker

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);
    }
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) MetricQueryResult(io.cdap.cdap.proto.MetricQueryResult)

Example 35 with RowMaker

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);
}
Also used : BatchProgramStatus(io.cdap.cdap.proto.BatchProgramStatus) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker)

Aggregations

RowMaker (io.cdap.cdap.cli.util.RowMaker)62 Table (io.cdap.cdap.cli.util.table.Table)60 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)8 CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)6 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)6 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)6 ProgramRecord (io.cdap.cdap.proto.ProgramRecord)6 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)4 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)4 BatchProgramResult (io.cdap.cdap.proto.BatchProgramResult)4 DatasetTypeMeta (io.cdap.cdap.proto.DatasetTypeMeta)4 ProgramId (io.cdap.cdap.proto.id.ProgramId)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Map (java.util.Map)3 ArtifactInfo (io.cdap.cdap.api.artifact.ArtifactInfo)2 ServiceHttpEndpoint (io.cdap.cdap.api.service.http.ServiceHttpEndpoint)2 ExploreExecutionResult (io.cdap.cdap.explore.client.ExploreExecutionResult)2 HandleNotFoundException (io.cdap.cdap.explore.service.HandleNotFoundException)2 ApplicationRecord (io.cdap.cdap.proto.ApplicationRecord)2