Search in sources :

Example 11 with Table

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

the class ListDatasetTypesCommand method perform.

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

        @Override
        public List<?> makeRow(DatasetTypeMeta object) {
            List<String> modulesStrings = Lists.newArrayList();
            for (DatasetModuleMeta module : object.getModules()) {
                modulesStrings.add(module.getName());
            }
            return Lists.newArrayList(object.getName(), Joiner.on(", ").join(modulesStrings));
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) RowMaker(io.cdap.cdap.cli.util.RowMaker) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta)

Example 12 with Table

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

the class GetMetadataPropertiesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    MetadataEntity metadataEntity = MetadataCommandHelper.toMetadataEntity(arguments.get(ArgumentName.ENTITY.toString()));
    String scope = arguments.getOptional(ArgumentName.METADATA_SCOPE.toString());
    Map<String, String> properties = scope == null ? client.getProperties(metadataEntity) : client.getProperties(metadataEntity, MetadataScope.valueOf(scope.toUpperCase()));
    Table table = Table.builder().setHeader("key", "value").setRows(Iterables.transform(properties.entrySet(), new Function<Map.Entry<String, String>, List<String>>() {

        @Nullable
        @Override
        public List<String> apply(@Nullable Map.Entry<String, String> entry) {
            return Lists.newArrayList(entry.getKey(), entry.getValue());
        }
    })).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : MetadataEntity(io.cdap.cdap.api.metadata.MetadataEntity) Table(io.cdap.cdap.cli.util.table.Table) List(java.util.List) Map(java.util.Map) Nullable(javax.annotation.Nullable)

Example 13 with Table

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

the class ListArtifactPluginsCommand 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());
    final List<PluginSummary> pluginSummaries;
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    if (scopeStr == null) {
        pluginSummaries = artifactClient.getPluginSummaries(artifactId, pluginType);
    } else {
        pluginSummaries = artifactClient.getPluginSummaries(artifactId, pluginType, ArtifactScope.valueOf(scopeStr.toUpperCase()));
    }
    Table table = Table.builder().setHeader("type", "name", "classname", "description", "artifact").setRows(pluginSummaries, new RowMaker<PluginSummary>() {

        @Override
        public List<?> makeRow(PluginSummary object) {
            return Lists.newArrayList(object.getType(), object.getName(), object.getClassName(), object.getDescription(), 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) PluginSummary(io.cdap.cdap.proto.artifact.PluginSummary)

Example 14 with Table

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

Example 15 with Table

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

Aggregations

Table (io.cdap.cdap.cli.util.table.Table)82 RowMaker (io.cdap.cdap.cli.util.RowMaker)60 CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)12 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)10 List (java.util.List)10 PrintStream (java.io.PrintStream)8 Lists (com.google.common.collect.Lists)6 Inject (com.google.inject.Inject)6 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)6 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)6 ArgumentName (io.cdap.cdap.cli.ArgumentName)6 CLIConfig (io.cdap.cdap.cli.CLIConfig)6 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)6 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)6 ProgramId (io.cdap.cdap.proto.id.ProgramId)6 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)6 Map (java.util.Map)6 Nullable (javax.annotation.Nullable)6 ProgramRecord (io.cdap.cdap.proto.ProgramRecord)5 DatasetId (io.cdap.cdap.proto.id.DatasetId)5