Search in sources :

Example 16 with Table

use of io.cdap.cdap.cli.util.table.Table in project cdap by caskdata.

the class ListWorkflowSchedulesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String[] programIdParts = arguments.get(ElementType.WORKFLOW.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    final String appId = programIdParts[0];
    String workflowName = programIdParts[1];
    WorkflowId workflowId = cliConfig.getCurrentNamespace().app(appId).workflow(workflowName);
    List<ScheduleDetail> list = scheduleClient.listSchedules(workflowId);
    Table table = Table.builder().setHeader("application", "program", "program type", "name", "description", "trigger", "timeoutMillis", "properties").setRows(list, new RowMaker<ScheduleDetail>() {

        @Override
        public List<?> makeRow(ScheduleDetail object) {
            return Lists.newArrayList(appId, object.getProgram().getProgramName(), object.getProgram().getProgramType().name(), object.getName(), object.getDescription(), object.getTrigger(), object.getTimeoutMillis(), GSON.toJson(object.getProperties()));
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) WorkflowId(io.cdap.cdap.proto.id.WorkflowId)

Example 17 with Table

use of io.cdap.cdap.cli.util.table.Table in project cdap by caskdata.

the class ListRolesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String principalType = arguments.getOptional(ArgumentName.PRINCIPAL_TYPE.toString());
    String principalName = arguments.getOptional(ArgumentName.PRINCIPAL_NAME.toString());
    Set<Role> roles;
    if (!(Strings.isNullOrEmpty(principalType) && Strings.isNullOrEmpty(principalName))) {
        roles = client.listRoles(new Principal(principalName, Principal.PrincipalType.valueOf(principalType.toUpperCase())));
    } else {
        roles = client.listAllRoles();
    }
    Table table = Table.builder().setHeader("Role").setRows(Lists.newArrayList(roles), new RowMaker<Role>() {

        @Override
        public List<?> makeRow(Role role) {
            return Lists.newArrayList(role.getName());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Role(io.cdap.cdap.proto.security.Role) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) Principal(io.cdap.cdap.proto.security.Principal)

Example 18 with Table

use of io.cdap.cdap.cli.util.table.Table in project cdap by caskdata.

the class CLITestBase method testNamespacesOutput.

private void testNamespacesOutput(String command, final List<NamespaceMeta> expected) throws Exception {
    CLIMain cliMain = getCliMain();
    CLIConfig cliConfig = getCliConfig();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintStream output = new PrintStream(outputStream);
    Table table = Table.builder().setHeader("name", "description", "config").setRows(expected, new RowMaker<NamespaceMeta>() {

        @Override
        public List<?> makeRow(NamespaceMeta object) {
            return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
        }
    }).build();
    cliMain.getTableRenderer().render(cliConfig, output, table);
    final String expectedOutput = outputStream.toString();
    testCommand(command, new Function<String, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable String output) {
            Assert.assertNotNull(output);
            Assert.assertEquals(expectedOutput, output);
            return null;
        }
    });
}
Also used : PrintStream(java.io.PrintStream) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Nullable(javax.annotation.Nullable)

Example 19 with Table

use of io.cdap.cdap.cli.util.table.Table in project cdap by cdapio.

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

Example 20 with Table

use of io.cdap.cdap.cli.util.table.Table in project cdap by cdapio.

the class ListAppsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String artifactNamesStr = arguments.getOptional(ArgumentName.ARTIFACT_NAME.toString());
    String artifactVersion = arguments.getOptional(ArgumentName.ARTIFACT_VERSION.toString());
    Set<String> artifactNames = new HashSet<>();
    if (artifactNamesStr != null) {
        for (String name : Splitter.on(',').trimResults().split(artifactNamesStr)) {
            artifactNames.add(name);
        }
    }
    Table table = Table.builder().setHeader("id", "appVersion", "description", "artifactName", "artifactVersion", "artifactScope", "principal").setRows(appClient.list(cliConfig.getCurrentNamespace(), artifactNames, artifactVersion), new RowMaker<ApplicationRecord>() {

        @Override
        public List<?> makeRow(ApplicationRecord object) {
            return Lists.newArrayList(object.getName(), object.getAppVersion(), object.getDescription(), object.getArtifact().getName(), object.getArtifact().getVersion(), object.getArtifact().getScope(), object.getOwnerPrincipal());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) HashSet(java.util.HashSet) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord)

Aggregations

Table (io.cdap.cdap.cli.util.table.Table)82 RowMaker (io.cdap.cdap.cli.util.RowMaker)60 CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)12 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)10 List (java.util.List)10 PrintStream (java.io.PrintStream)8 Lists (com.google.common.collect.Lists)6 Inject (com.google.inject.Inject)6 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)6 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)6 ArgumentName (io.cdap.cdap.cli.ArgumentName)6 CLIConfig (io.cdap.cdap.cli.CLIConfig)6 DatasetModuleMeta (io.cdap.cdap.proto.DatasetModuleMeta)6 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)6 ProgramId (io.cdap.cdap.proto.id.ProgramId)6 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)6 Map (java.util.Map)6 Nullable (javax.annotation.Nullable)6 ProgramRecord (io.cdap.cdap.proto.ProgramRecord)5 DatasetId (io.cdap.cdap.proto.id.DatasetId)5