use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.
the class GetWorkflowCurrentRunCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\.");
ApplicationId appId = cliConfig.getCurrentNamespace().app(programIdParts[0]);
List<WorkflowActionNode> nodes;
if (elementType.getProgramType() != null) {
if (programIdParts.length < 2) {
throw new CommandInputError(this);
}
String workflowId = programIdParts[1];
String runId = arguments.get(ArgumentName.RUN_ID.toString());
nodes = programClient.getWorkflowCurrent(appId.workflow(workflowId), runId);
} else {
throw new IllegalArgumentException("Unrecognized program element type for current runs: " + elementType);
}
Table table = Table.builder().setHeader("node id", "program name", "program type").setRows(nodes, new RowMaker<WorkflowActionNode>() {
@Override
public List<?> makeRow(WorkflowActionNode object) {
return Lists.newArrayList(object.getNodeId(), object.getProgram().getProgramName(), object.getProgram().getProgramType());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.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", "start", "stop").setRows(records, new RowMaker<RunRecord>() {
@Override
public List<?> makeRow(RunRecord object) {
return Lists.newArrayList(object.getPid(), object.getStatus(), object.getStartTs(), object.getStatus().name().equals("RUNNING") ? "" : object.getStopTs());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.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 co.cask.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 co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.
the class ListArtifactPluginTypesCommand 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);
List<String> types;
String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
if (scopeStr == null) {
types = artifactClient.getPluginTypes(artifactId);
} else {
types = artifactClient.getPluginTypes(artifactId, ArtifactScope.valueOf(scopeStr.toUpperCase()));
}
Table table = Table.builder().setHeader("plugin type").setRows(types, new RowMaker<String>() {
@Override
public List<?> makeRow(String object) {
return Lists.newArrayList(object);
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Aggregations