Search in sources :

Example 11 with RowMaker

use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.

the class ListPrivilegesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String principalType = arguments.get(ArgumentName.PRINCIPAL_TYPE.toString());
    String principalName = arguments.get(ArgumentName.PRINCIPAL_NAME.toString());
    Table table = Table.builder().setHeader("Entity", "Action").setRows(Lists.newArrayList(client.listPrivileges(new Principal(principalName, Principal.PrincipalType.valueOf(principalType.toUpperCase())))), new RowMaker<Privilege>() {

        @Override
        public List<?> makeRow(Privilege privilege) {
            return Lists.newArrayList(privilege.getEntity().toString(), privilege.getAction().name());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) Privilege(co.cask.cdap.proto.security.Privilege) Principal(co.cask.cdap.proto.security.Principal)

Example 12 with RowMaker

use of co.cask.cdap.cli.util.RowMaker 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(co.cask.cdap.proto.security.Role) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) Principal(co.cask.cdap.proto.security.Principal)

Example 13 with RowMaker

use of co.cask.cdap.cli.util.RowMaker 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(co.cask.cdap.cli.exception.CommandInputError) Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail) WorkflowId(co.cask.cdap.proto.id.WorkflowId)

Example 14 with RowMaker

use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.

the class ListAllProgramsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    Map<ProgramType, List<ProgramRecord>> allPrograms = appClient.listAllPrograms(cliConfig.getCurrentNamespace());
    List<ProgramRecord> allProgramsList = Lists.newArrayList();
    for (List<ProgramRecord> subList : allPrograms.values()) {
        allProgramsList.addAll(subList);
    }
    Table table = Table.builder().setHeader("type", "app", "id", "description").setRows(allProgramsList, new RowMaker<ProgramRecord>() {

        @Override
        public List<?> makeRow(ProgramRecord object) {
            return Lists.newArrayList(object.getType().getCategoryName(), object.getApp(), object.getName(), object.getDescription());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) ProgramRecord(co.cask.cdap.proto.ProgramRecord) RowMaker(co.cask.cdap.cli.util.RowMaker) List(java.util.List) ProgramType(co.cask.cdap.proto.ProgramType)

Example 15 with RowMaker

use of co.cask.cdap.cli.util.RowMaker in project cdap by caskdata.

the class ListDatasetInstancesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    List<DatasetSpecificationSummary> datasetMetas = datasetClient.list(cliConfig.getCurrentNamespace());
    Table table = Table.builder().setHeader("name", "type", "description").setRows(datasetMetas, new RowMaker<DatasetSpecificationSummary>() {

        @Override
        public List<?> makeRow(DatasetSpecificationSummary object) {
            return Lists.newArrayList(object.getName(), object.getType(), object.getDescription());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) RowMaker(co.cask.cdap.cli.util.RowMaker) DatasetSpecificationSummary(co.cask.cdap.proto.DatasetSpecificationSummary)

Aggregations

RowMaker (co.cask.cdap.cli.util.RowMaker)39 Table (co.cask.cdap.cli.util.table.Table)38 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)4 ArtifactId (co.cask.cdap.proto.id.ArtifactId)4 StreamId (co.cask.cdap.proto.id.StreamId)4 DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)3 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)3 ProgramRecord (co.cask.cdap.proto.ProgramRecord)3 ArtifactScope (co.cask.cdap.api.artifact.ArtifactScope)2 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)2 BatchProgramResult (co.cask.cdap.proto.BatchProgramResult)2 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)2 ApplicationId (co.cask.cdap.proto.id.ApplicationId)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 Principal (co.cask.cdap.proto.security.Principal)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)1 FormatSpecification (co.cask.cdap.api.data.format.FormatSpecification)1