Search in sources :

Example 26 with RowMaker

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

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 27 with RowMaker

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

the class DescribeDatasetModuleCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetModuleId moduleId = cliConfig.getCurrentNamespace().datasetModule(arguments.get(ArgumentName.DATASET_MODULE.toString()));
    DatasetModuleMeta datasetModuleMeta = datasetModuleClient.get(moduleId);
    Table table = Table.builder().setHeader("name", "className", "jarLocationPath", "types", "usesModules", "usedByModules").setRows(ImmutableList.of(datasetModuleMeta), new RowMaker<DatasetModuleMeta>() {

        @Override
        public List<?> makeRow(DatasetModuleMeta object) {
            return Lists.newArrayList(object.getName(), object.getClassName(), object.getJarLocationPath(), Joiner.on(", ").join(object.getTypes()), Joiner.on(", ").join(object.getUsesModules()), Joiner.on(", ").join(object.getUsedByModules()));
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : DatasetModuleId(io.cdap.cdap.proto.id.DatasetModuleId) Table(io.cdap.cdap.cli.util.table.Table) DatasetModuleMeta(io.cdap.cdap.proto.DatasetModuleMeta) RowMaker(io.cdap.cdap.cli.util.RowMaker)

Example 28 with RowMaker

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

the class DescribeDatasetTypeCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetTypeId type = cliConfig.getCurrentNamespace().datasetType(arguments.get(ArgumentName.DATASET_TYPE.toString()));
    DatasetTypeMeta datasetTypeMeta = datasetTypeClient.get(type);
    Table table = Table.builder().setHeader("name", "modules").setRows(ImmutableList.of(datasetTypeMeta), new RowMaker<DatasetTypeMeta>() {

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

Example 29 with RowMaker

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

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)

Example 30 with RowMaker

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

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(io.cdap.cdap.cli.util.table.Table) ProgramRecord(io.cdap.cdap.proto.ProgramRecord) RowMaker(io.cdap.cdap.cli.util.RowMaker) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Aggregations

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