Search in sources :

Example 6 with RowMaker

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

the class ListArtifactVersionsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
    List<ArtifactSummary> artifactSummaries;
    if (scopeStr == null) {
        artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName);
    } else {
        ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
        artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName, scope);
    }
    Table table = Table.builder().setHeader("name", "version", "scope").setRows(artifactSummaries, new RowMaker<ArtifactSummary>() {

        @Override
        public List<?> makeRow(ArtifactSummary object) {
            return Lists.newArrayList(object.getName(), object.getVersion(), object.getScope().name());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : ArtifactScope(co.cask.cdap.api.artifact.ArtifactScope) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker)

Example 7 with RowMaker

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

the class ListArtifactsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    List<ArtifactSummary> artifactSummaries;
    String artifactScope = arguments.getOptional(ArgumentName.SCOPE.toString());
    if (artifactScope == null) {
        artifactSummaries = artifactClient.list(cliConfig.getCurrentNamespace());
    } else {
        artifactSummaries = artifactClient.list(cliConfig.getCurrentNamespace(), ArtifactScope.valueOf(artifactScope.toUpperCase()));
    }
    Table table = Table.builder().setHeader("name", "version", "scope").setRows(artifactSummaries, new RowMaker<ArtifactSummary>() {

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

Example 8 with RowMaker

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

the class SearchMetadataCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String searchQuery = arguments.get(ArgumentName.SEARCH_QUERY.toString());
    String type = arguments.getOptional(ArgumentName.TARGET_TYPE.toString());
    MetadataSearchResponse metadataSearchResponse = metadataClient.searchMetadata(cliConfig.getCurrentNamespace().toId(), searchQuery, parseTargetType(type));
    Set<MetadataSearchResultRecord> searchResults = metadataSearchResponse.getResults();
    Table table = Table.builder().setHeader("Entity").setRows(Lists.newArrayList(searchResults), new RowMaker<MetadataSearchResultRecord>() {

        @Override
        public List<?> makeRow(MetadataSearchResultRecord searchResult) {
            return Lists.newArrayList(searchResult.getEntityId().toString());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) MetadataSearchResultRecord(co.cask.cdap.proto.metadata.MetadataSearchResultRecord) RowMaker(co.cask.cdap.cli.util.RowMaker) MetadataSearchResponse(co.cask.cdap.proto.metadata.MetadataSearchResponse)

Example 9 with RowMaker

use of co.cask.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(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) MetricQueryResult(co.cask.cdap.proto.MetricQueryResult)

Example 10 with RowMaker

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

the class ListStreamViewsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    StreamId streamId = cliConfig.getCurrentNamespace().stream(arguments.get(ArgumentName.STREAM.toString()));
    List<String> views = client.list(streamId);
    Table table = Table.builder().setHeader("id").setRows(views, new RowMaker<String>() {

        @Override
        public List<?> makeRow(String object) {
            return Lists.newArrayList(object);
        }
    }).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)

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