Search in sources :

Example 46 with RowMaker

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);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 47 with RowMaker

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);
    }
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) Table(io.cdap.cdap.cli.util.table.Table) DistributedProgramLiveInfo(io.cdap.cdap.proto.DistributedProgramLiveInfo) RowMaker(io.cdap.cdap.cli.util.RowMaker) Containers(io.cdap.cdap.proto.Containers) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 48 with RowMaker

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);
}
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 49 with RowMaker

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.");
    }
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) SQLException(java.sql.SQLException) RowMaker(io.cdap.cdap.cli.util.RowMaker) ColumnDesc(io.cdap.cdap.proto.ColumnDesc) QueryStatus(io.cdap.cdap.proto.QueryStatus) HandleNotFoundException(io.cdap.cdap.explore.service.HandleNotFoundException) QueryResult(io.cdap.cdap.proto.QueryResult) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) TimeoutException(java.util.concurrent.TimeoutException)

Example 50 with RowMaker

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);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

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