Search in sources :

Example 36 with Table

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

the class DescribeDatasetInstanceCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetId instance = cliConfig.getCurrentNamespace().dataset(arguments.get(ArgumentName.DATASET.toString()));
    DatasetMeta meta = datasetClient.get(instance);
    Table table = Table.builder().setHeader("hive table", "spec", "type", "principal").setRows(ImmutableList.of(meta), new RowMaker<DatasetMeta>() {

        @Override
        public List<?> makeRow(DatasetMeta object) {
            return Lists.newArrayList(object.getHiveTableName(), GSON.toJson(object.getSpec()), GSON.toJson(object.getType()), object.getOwnerPrincipal());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) DatasetMeta(co.cask.cdap.proto.DatasetMeta) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 37 with Table

use of co.cask.cdap.cli.util.table.Table 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 38 with Table

use of co.cask.cdap.cli.util.table.Table 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 39 with Table

use of co.cask.cdap.cli.util.table.Table 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 40 with Table

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

the class GetDatasetLineageCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    long currentTime = System.currentTimeMillis();
    DatasetId dataset = cliConfig.getCurrentNamespace().dataset(arguments.get(ArgumentName.DATASET.toString()));
    long start = getTimestamp(arguments.getOptional("start", "min"), currentTime);
    long end = getTimestamp(arguments.getOptional("end", "max"), currentTime);
    Integer levels = arguments.getIntOptional("levels", null);
    LineageRecord lineage = client.getLineage(dataset, start, end, levels);
    Table table = Table.builder().setHeader("start", "end", "relations", "programs", "data").setRows(Collections.<List<String>>singletonList(Lists.newArrayList(Long.toString(lineage.getStart()), Long.toString(lineage.getEnd()), GSON.toJson(lineage.getRelations()), GSON.toJson(lineage.getPrograms()), GSON.toJson(lineage.getData())))).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) LineageRecord(co.cask.cdap.proto.metadata.lineage.LineageRecord) List(java.util.List) DatasetId(co.cask.cdap.proto.id.DatasetId)

Aggregations

Table (co.cask.cdap.cli.util.table.Table)48 RowMaker (co.cask.cdap.cli.util.RowMaker)38 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)7 List (java.util.List)7 ArtifactId (co.cask.cdap.proto.id.ArtifactId)5 StreamId (co.cask.cdap.proto.id.StreamId)5 Nullable (javax.annotation.Nullable)5 ArtifactScope (co.cask.cdap.api.artifact.ArtifactScope)3 DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)3 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)3 ProgramRecord (co.cask.cdap.proto.ProgramRecord)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 EntityId (co.cask.cdap.proto.id.EntityId)3 ProgramId (co.cask.cdap.proto.id.ProgramId)3 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)3 Map (java.util.Map)3 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)2 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)2 BatchProgramResult (co.cask.cdap.proto.BatchProgramResult)2