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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations