use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class DescribeNamespaceCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
NamespaceId namespace = new NamespaceId(arguments.get(ArgumentName.NAMESPACE_NAME.getName()));
NamespaceMeta namespaceMeta = namespaceClient.get(namespace);
Table table = Table.builder().setHeader("name", "description", "config").setRows(Lists.newArrayList(namespaceMeta), new RowMaker<NamespaceMeta>() {
@Override
public List<?> makeRow(NamespaceMeta object) {
return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.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 io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
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);
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class ExecuteQueryCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String query = arguments.get(ArgumentName.QUERY.toString());
long timeOutMins = arguments.getLongOptional(ArgumentName.TIMEOUT.toString(), DEFAULT_TIMEOUT_MIN);
ListenableFuture<ExploreExecutionResult> future = queryClient.execute(cliConfig.getCurrentNamespace(), query);
try {
ExploreExecutionResult executionResult = future.get(timeOutMins, TimeUnit.MINUTES);
if (!executionResult.canContainResults()) {
output.println("SQL statement does not output any result.");
executionResult.close();
return;
}
final List<ColumnDesc> schema = executionResult.getResultSchema();
String[] header = new String[schema.size()];
for (int i = 0; i < header.length; i++) {
ColumnDesc column = schema.get(i);
// Hive columns start at 1
int index = column.getPosition() - 1;
header[index] = column.getName() + ": " + column.getType();
}
List<QueryResult> rows = Lists.newArrayList(executionResult);
executionResult.close();
QueryStatus.OpStatus opStatus = executionResult.getStatus().getStatus();
if (opStatus != QueryStatus.OpStatus.FINISHED) {
throw new SQLException(String.format("Query '%s' execution did not finish successfully. " + "Got final state - %s", query, opStatus));
}
Table table = Table.builder().setHeader(header).setRows(rows, new RowMaker<QueryResult>() {
@Override
public List<?> makeRow(QueryResult object) {
return object.getColumns();
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
output.printf("Fetched %d rows", rows.size()).println();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
Throwable t = Throwables.getRootCause(e);
if (t instanceof HandleNotFoundException) {
throw Throwables.propagate(t);
}
throw new SQLException(Throwables.getRootCause(e));
} catch (CancellationException e) {
throw new RuntimeException("Query has been cancelled on ListenableFuture object.");
} catch (TimeoutException e) {
output.println("Couldn't obtain results after " + timeOutMins + "mins.");
}
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by cdapio.
the class DescribeNamespaceCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
NamespaceId namespace = new NamespaceId(arguments.get(ArgumentName.NAMESPACE_NAME.getName()));
NamespaceMeta namespaceMeta = namespaceClient.get(namespace);
Table table = Table.builder().setHeader("name", "description", "config").setRows(Lists.newArrayList(namespaceMeta), new RowMaker<NamespaceMeta>() {
@Override
public List<?> makeRow(NamespaceMeta object) {
return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Aggregations