Search in sources :

Example 31 with RowMaker

use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.

the class GetWorkflowTokenCommand method getWorkflowToken.

private Table getWorkflowToken(ProgramRunId runId, WorkflowToken.Scope workflowTokenScope, String key) throws UnauthenticatedException, IOException, NotFoundException, UnauthorizedException {
    WorkflowTokenDetail workflowToken = workflowClient.getWorkflowToken(runId, workflowTokenScope, key);
    List<Map.Entry<String, List<WorkflowTokenDetail.NodeValueDetail>>> tokenKeys = new ArrayList<>();
    tokenKeys.addAll(workflowToken.getTokenData().entrySet());
    return Table.builder().setHeader("token key", "token value").setRows(tokenKeys, new RowMaker<Map.Entry<String, List<WorkflowTokenDetail.NodeValueDetail>>>() {

        @Override
        public List<?> makeRow(Map.Entry<String, List<WorkflowTokenDetail.NodeValueDetail>> object) {
            return Lists.newArrayList(object.getKey(), GSON.toJson(object.getValue()));
        }
    }).build();
}
Also used : RowMaker(co.cask.cdap.cli.util.RowMaker) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowTokenDetail(co.cask.cdap.proto.WorkflowTokenDetail) Map(java.util.Map)

Example 32 with RowMaker

use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.

the class ListDatasetModulesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    List<DatasetModuleMeta> modules = client.list(cliConfig.getCurrentNamespace());
    Table table = Table.builder().setHeader("name", "className").setRows(modules, new RowMaker<DatasetModuleMeta>() {

        @Override
        public List<?> makeRow(DatasetModuleMeta object) {
            return Lists.newArrayList(object.getName(), object.getClassName());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) RowMaker(co.cask.cdap.cli.util.RowMaker)

Example 33 with RowMaker

use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.

the class CLIMainTest method testNamespacesOutput.

private static void testNamespacesOutput(CLI cli, String command, final List<NamespaceMeta> expected) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintStream output = new PrintStream(outputStream);
    Table table = Table.builder().setHeader("name", "description", "config").setRows(expected, new RowMaker<NamespaceMeta>() {

        @Override
        public List<?> makeRow(NamespaceMeta object) {
            return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
        }
    }).build();
    cliMain.getTableRenderer().render(cliConfig, output, table);
    final String expectedOutput = outputStream.toString();
    testCommand(cli, command, new Function<String, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable String output) {
            Assert.assertNotNull(output);
            Assert.assertEquals(expectedOutput, output);
            return null;
        }
    });
}
Also used : PrintStream(java.io.PrintStream) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Nullable(javax.annotation.Nullable)

Example 34 with RowMaker

use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.

the class DescribeStreamViewCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    StreamId streamId = cliConfig.getCurrentNamespace().stream(arguments.get(ArgumentName.STREAM.toString()));
    ViewDetail detail = client.get(streamId.view(arguments.get(ArgumentName.VIEW.toString())));
    Table table = Table.builder().setHeader("id", "format", "table", "schema", "settings").setRows(Collections.singletonList(detail), new RowMaker<ViewDetail>() {

        @Override
        public List<?> makeRow(ViewDetail object) {
            return Lists.newArrayList(object.getId(), object.getFormat().getName(), object.getTableName(), GSON.toJson(object.getFormat().getSchema()), GSON.toJson(object.getFormat().getSettings()));
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) ViewDetail(co.cask.cdap.proto.ViewDetail)

Example 35 with RowMaker

use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.

the class DescribeAppCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    ApplicationId appId = parseApplicationId(arguments);
    List<ProgramRecord> programsList = applicationClient.listPrograms(appId);
    Table table = Table.builder().setHeader("type", "id", "description").setRows(programsList, new RowMaker<ProgramRecord>() {

        @Override
        public List<?> makeRow(ProgramRecord object) {
            return Lists.newArrayList(object.getType().getPrettyName(), object.getName(), object.getDescription());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) ProgramRecord(co.cask.cdap.proto.ProgramRecord) RowMaker(co.cask.cdap.cli.util.RowMaker) ApplicationId(co.cask.cdap.proto.id.ApplicationId)

Aggregations

RowMaker (co.cask.cdap.cli.util.RowMaker)39 Table (co.cask.cdap.cli.util.table.Table)38 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)4 ArtifactId (co.cask.cdap.proto.id.ArtifactId)4 StreamId (co.cask.cdap.proto.id.StreamId)4 DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)3 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)3 ProgramRecord (co.cask.cdap.proto.ProgramRecord)3 ArtifactScope (co.cask.cdap.api.artifact.ArtifactScope)2 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)2 BatchProgramResult (co.cask.cdap.proto.BatchProgramResult)2 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)2 ApplicationId (co.cask.cdap.proto.id.ApplicationId)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 Principal (co.cask.cdap.proto.security.Principal)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)1 FormatSpecification (co.cask.cdap.api.data.format.FormatSpecification)1