Search in sources :

Example 1 with Table

use of io.cdap.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(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker)

Example 2 with Table

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

the class DescribeArtifactPluginCommand 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 pluginType = arguments.get(ArgumentName.PLUGIN_TYPE.toString());
    String pluginName = arguments.get(ArgumentName.PLUGIN_NAME.toString());
    List<PluginInfo> pluginInfos;
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    if (scopeStr == null) {
        pluginInfos = artifactClient.getPluginInfo(artifactId, pluginType, pluginName);
    } else {
        pluginInfos = artifactClient.getPluginInfo(artifactId, pluginType, pluginName, ArtifactScope.valueOf(scopeStr.toUpperCase()));
    }
    Table table = Table.builder().setHeader("type", "name", "classname", "description", "properties", "artifact").setRows(pluginInfos, new RowMaker<PluginInfo>() {

        @Override
        public List<?> makeRow(PluginInfo object) {
            return Lists.newArrayList(object.getType(), object.getName(), object.getClassName(), object.getDescription(), GSON.toJson(object.getProperties()), object.getArtifact().toString());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) RowMaker(io.cdap.cdap.cli.util.RowMaker) PluginInfo(io.cdap.cdap.proto.artifact.PluginInfo)

Example 3 with Table

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

the class GetArtifactPropertiesCommand 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);
    }
    List<Map.Entry<String, String>> rows = new ArrayList<>(info.getProperties().size());
    rows.addAll(info.getProperties().entrySet());
    Table table = Table.builder().setHeader("key", "value").setRows(rows, new RowMaker<Map.Entry<String, String>>() {

        @Override
        public List<String> makeRow(Map.Entry<String, String> entry) {
            List<String> columns = new ArrayList<>(2);
            columns.add(entry.getKey());
            columns.add(entry.getValue());
            return columns;
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) Table(io.cdap.cdap.cli.util.table.Table) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) RowMaker(io.cdap.cdap.cli.util.RowMaker) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 4 with Table

use of io.cdap.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(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) DatasetMeta(io.cdap.cdap.proto.DatasetMeta) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Example 5 with Table

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

the class GetDatasetInstancePropertiesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetId instance = cliConfig.getCurrentNamespace().dataset(arguments.get(ArgumentName.DATASET.toString()));
    Map<String, String> properties = datasetClient.getProperties(instance);
    Table table = Table.builder().setHeader("property", "value").setRows(Iterables.transform(properties.entrySet(), new Function<Map.Entry<String, String>, List<String>>() {

        @Nullable
        @Override
        public List<String> apply(Map.Entry<String, String> entry) {
            return ImmutableList.of(entry.getKey(), entry.getValue());
        }
    })).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Nullable(javax.annotation.Nullable) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Aggregations

Table (io.cdap.cdap.cli.util.table.Table)41 RowMaker (io.cdap.cdap.cli.util.RowMaker)30 CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)6 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)5 List (java.util.List)5 PrintStream (java.io.PrintStream)4 Lists (com.google.common.collect.Lists)3 Inject (com.google.inject.Inject)3 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)3 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)3 ArgumentName (io.cdap.cdap.cli.ArgumentName)3 CLIConfig (io.cdap.cdap.cli.CLIConfig)3 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)3 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)3 ProgramRecord (io.cdap.cdap.proto.ProgramRecord)3 ProgramId (io.cdap.cdap.proto.id.ProgramId)3 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)3 Arguments (io.cdap.common.cli.Arguments)3 Map (java.util.Map)3 Nullable (javax.annotation.Nullable)3