Search in sources :

Example 1 with RowMaker

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

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

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

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

use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.

the class GetProgramRunsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
    String appId = programIdParts[0];
    long currentTime = System.currentTimeMillis();
    long startTime = getTimestamp(arguments.getOptional(ArgumentName.START_TIME.toString(), "min"), currentTime);
    long endTime = getTimestamp(arguments.getOptional(ArgumentName.END_TIME.toString(), "max"), currentTime);
    int limit = arguments.getIntOptional(ArgumentName.LIMIT.toString(), Integer.MAX_VALUE);
    List<RunRecord> records;
    if (elementType.getProgramType() != null) {
        if (programIdParts.length < 2) {
            throw new CommandInputError(this);
        }
        String programName = programIdParts[1];
        ProgramId programId = cliConfig.getCurrentNamespace().app(appId).program(elementType.getProgramType(), programName);
        if (arguments.hasArgument(ArgumentName.RUN_STATUS.toString())) {
            records = programClient.getProgramRuns(programId, arguments.get(ArgumentName.RUN_STATUS.toString()), startTime, endTime, limit);
        } else {
            records = programClient.getAllProgramRuns(programId, startTime, endTime, limit);
        }
    } else {
        throw new IllegalArgumentException("Unrecognized program element type for history: " + elementType);
    }
    Table table = Table.builder().setHeader("pid", "end status", "init time", "start time", "stop time").setRows(records, new RowMaker<RunRecord>() {

        @Override
        public List<?> makeRow(RunRecord object) {
            return Lists.newArrayList(object.getPid(), object.getStatus(), object.getStartTs(), object.getRunTs() == null ? "" : object.getRunTs(), object.getStopTs() == null ? "" : object.getStopTs());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) RunRecord(io.cdap.cdap.proto.RunRecord) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Aggregations

RowMaker (io.cdap.cdap.cli.util.RowMaker)31 Table (io.cdap.cdap.cli.util.table.Table)30 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)4 CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)3 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)3 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)3 ProgramRecord (io.cdap.cdap.proto.ProgramRecord)3 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)2 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)2 BatchProgramResult (io.cdap.cdap.proto.BatchProgramResult)2 DatasetTypeMeta (io.cdap.cdap.proto.DatasetTypeMeta)2 ProgramId (io.cdap.cdap.proto.id.ProgramId)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ArtifactInfo (io.cdap.cdap.api.artifact.ArtifactInfo)1 ServiceHttpEndpoint (io.cdap.cdap.api.service.http.ServiceHttpEndpoint)1 ExploreExecutionResult (io.cdap.cdap.explore.client.ExploreExecutionResult)1 HandleNotFoundException (io.cdap.cdap.explore.service.HandleNotFoundException)1 ApplicationRecord (io.cdap.cdap.proto.ApplicationRecord)1