Search in sources :

Example 41 with Table

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

the class GetStreamLineageCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    long currentTime = System.currentTimeMillis();
    StreamId stream = cliConfig.getCurrentNamespace().stream(arguments.get(ArgumentName.STREAM.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(stream, 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 : StreamId(co.cask.cdap.proto.id.StreamId) Table(co.cask.cdap.cli.util.table.Table) LineageRecord(co.cask.cdap.proto.metadata.lineage.LineageRecord) List(java.util.List)

Example 42 with Table

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

the class GetMetadataCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    String scope = arguments.getOptional(ArgumentName.METADATA_SCOPE.toString());
    Set<MetadataRecord> metadata = scope == null ? client.getMetadata(entity.toId()) : client.getMetadata(entity.toId(), MetadataScope.valueOf(scope.toUpperCase()));
    Table table = Table.builder().setHeader("entity", "tags", "properties", "scope").setRows(Iterables.transform(metadata, new Function<MetadataRecord, List<String>>() {

        @Nullable
        @Override
        public List<String> apply(MetadataRecord record) {
            return Lists.newArrayList(record.getEntityId().toString(), Joiner.on("\n").join(record.getTags()), Joiner.on("\n").withKeyValueSeparator(":").join(record.getProperties()), record.getScope().name());
        }
    })).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) Table(co.cask.cdap.cli.util.table.Table) List(java.util.List) MetadataRecord(co.cask.cdap.proto.metadata.MetadataRecord) Nullable(javax.annotation.Nullable)

Example 43 with Table

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

Example 44 with Table

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

the class ListAppVersionsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String appName = arguments.get(ArgumentName.APP.toString());
    List<String> versions = appClient.listAppVersions(cliConfig.getCurrentNamespace(), appName);
    Table table = Table.builder().setHeader("version").setRows(versions, new RowMaker<String>() {

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

Example 45 with Table

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

the class DescribeArtifactCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
    String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
    ArtifactId artifactId = cliConfig.getCurrentNamespace().artifact(artifactName, artifactVersion);
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    ArtifactInfo info;
    if (scopeStr == null) {
        info = artifactClient.getArtifactInfo(artifactId);
    } else {
        ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
        info = artifactClient.getArtifactInfo(artifactId, scope);
    }
    Table table = Table.builder().setHeader("name", "version", "scope", "app classes", "plugin classes", "properties", "parents").setRows(ImmutableList.of((List<String>) ImmutableList.of(info.getName(), info.getVersion(), info.getScope().name(), GSON.toJson(info.getClasses().getApps()), GSON.toJson(info.getClasses().getPlugins()), GSON.toJson(info.getProperties()), Joiner.on('/').join(info.getParents())))).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : ArtifactScope(co.cask.cdap.api.artifact.ArtifactScope) Table(co.cask.cdap.cli.util.table.Table) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ArtifactInfo(co.cask.cdap.api.artifact.ArtifactInfo)

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