use of co.cask.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 co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.
the class ListProgramsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
List<ProgramRecord> programs = appClient.listAllPrograms(cliConfig.getCurrentNamespace(), programType);
Table table = Table.builder().setHeader("app", "id", "description").setRows(programs, new RowMaker<ProgramRecord>() {
@Override
public List<?> makeRow(ProgramRecord object) {
return Lists.newArrayList(object.getApp(), object.getName(), object.getDescription());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.
the class ListStreamsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
Table table = Table.builder().setHeader("name").setRows(streamClient.list(cliConfig.getCurrentNamespace()), new RowMaker<StreamDetail>() {
@Override
public List<?> makeRow(StreamDetail object) {
return Lists.newArrayList(object.getName());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.
the class GetProgramLiveInfoCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
if (programIdParts.length < 2) {
throw new CommandInputError(this);
}
String appId = programIdParts[0];
String programName = programIdParts[1];
ProgramId program = cliConfig.getCurrentNamespace().app(appId).program(elementType.getProgramType(), programName);
DistributedProgramLiveInfo liveInfo = programClient.getLiveInfo(program);
if (liveInfo == null) {
output.println("No live info found");
return;
}
Table table = Table.builder().setHeader("app", "type", "id", "runtime", "yarn app id").setRows(ImmutableList.of(liveInfo), new RowMaker<DistributedProgramLiveInfo>() {
@Override
public List<?> makeRow(DistributedProgramLiveInfo object) {
return Lists.newArrayList(object.getApp(), object.getType(), object.getName(), object.getRuntime(), object.getYarnAppId());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
if (liveInfo.getContainers() != null) {
Table containersTable = Table.builder().setHeader("containers", "instance", "host", "container", "memory", "virtual cores", "debug port").setRows(liveInfo.getContainers(), new RowMaker<Containers.ContainerInfo>() {
@Override
public List<?> makeRow(Containers.ContainerInfo object) {
return Lists.newArrayList("", object.getInstance(), object.getHost(), object.getContainer(), object.getMemory(), object.getVirtualCores(), object.getDebugPort());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, containersTable);
}
}
use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.
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);
}
Aggregations