Search in sources :

Example 1 with ProgramRecord

use of io.cdap.cdap.proto.ProgramRecord in project cdap by caskdata.

the class BaseBatchCommand method readArgs.

/**
 * Reads arguments to get app id, program types, and list of input programs.
 */
protected Args<T> readArgs(Arguments arguments) throws ApplicationNotFoundException, UnauthenticatedException, IOException, UnauthorizedException {
    String appName = arguments.get(ArgumentName.APP.getName());
    ApplicationId appId = cliConfig.getCurrentNamespace().app(appName);
    Set<ProgramType> programTypes = getDefaultProgramTypes();
    if (arguments.hasArgument(ArgumentName.PROGRAM_TYPES.getName())) {
        programTypes.clear();
        String programTypesStr = arguments.get(ArgumentName.PROGRAM_TYPES.getName());
        for (String programTypeStr : Splitter.on(',').trimResults().split(programTypesStr)) {
            ProgramType programType = ProgramType.valueOf(programTypeStr.toUpperCase());
            programTypes.add(programType);
        }
    }
    List<T> programs = new ArrayList<>();
    Map<ProgramType, List<ProgramRecord>> appPrograms = appClient.listProgramsByType(appId);
    for (ProgramType programType : programTypes) {
        List<ProgramRecord> programRecords = appPrograms.get(programType);
        if (programRecords != null) {
            for (ProgramRecord programRecord : programRecords) {
                programs.add(createProgram(programRecord));
            }
        }
    }
    return new Args<>(appId, programTypes, programs);
}
Also used : ProgramRecord(io.cdap.cdap.proto.ProgramRecord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ProgramType(io.cdap.cdap.proto.ProgramType) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 2 with ProgramRecord

use of io.cdap.cdap.proto.ProgramRecord in project cdap by caskdata.

the class ProgramLifecycleService method list.

/**
 * Lists all programs with the specified program type in a namespace. If perimeter security and authorization are
 * enabled, only returns the programs that the current user has access to.
 *
 * @param namespaceId the namespace to list datasets for
 * @return the programs in the provided namespace
 */
public List<ProgramRecord> list(NamespaceId namespaceId, ProgramType type) throws Exception {
    Collection<ApplicationSpecification> appSpecs = store.getAllApplications(namespaceId);
    List<ProgramRecord> programRecords = new ArrayList<>();
    for (ApplicationSpecification appSpec : appSpecs) {
        switch(type) {
            case MAPREDUCE:
                createProgramRecords(namespaceId, appSpec.getName(), type, appSpec.getMapReduce().values(), programRecords);
                break;
            case SPARK:
                createProgramRecords(namespaceId, appSpec.getName(), type, appSpec.getSpark().values(), programRecords);
                break;
            case SERVICE:
                createProgramRecords(namespaceId, appSpec.getName(), type, appSpec.getServices().values(), programRecords);
                break;
            case WORKER:
                createProgramRecords(namespaceId, appSpec.getName(), type, appSpec.getWorkers().values(), programRecords);
                break;
            case WORKFLOW:
                createProgramRecords(namespaceId, appSpec.getName(), type, appSpec.getWorkflows().values(), programRecords);
                break;
            default:
                throw new Exception("Unknown program type: " + type.name());
        }
    }
    return programRecords;
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramRecord(io.cdap.cdap.proto.ProgramRecord) ArrayList(java.util.ArrayList) TooManyRequestsException(io.cdap.cdap.common.TooManyRequestsException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) BadRequestException(io.cdap.cdap.common.BadRequestException) ConflictException(io.cdap.cdap.common.ConflictException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with ProgramRecord

use of io.cdap.cdap.proto.ProgramRecord in project cdap by caskdata.

the class ApplicationClient method listAllPrograms.

/**
 * Lists all programs.
 *
 * @return list of {@link ProgramRecord}s
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public Map<ProgramType, List<ProgramRecord>> listAllPrograms(NamespaceId namespace) throws IOException, UnauthenticatedException, UnauthorizedException {
    ImmutableMap.Builder<ProgramType, List<ProgramRecord>> allPrograms = ImmutableMap.builder();
    for (ProgramType programType : ProgramType.values()) {
        if (programType.isListable()) {
            List<ProgramRecord> programRecords = Lists.newArrayList();
            programRecords.addAll(listAllPrograms(namespace, programType));
            allPrograms.put(programType, programRecords);
        }
    }
    return allPrograms.build();
}
Also used : ProgramRecord(io.cdap.cdap.proto.ProgramRecord) List(java.util.List) ProgramType(io.cdap.cdap.proto.ProgramType) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with ProgramRecord

use of io.cdap.cdap.proto.ProgramRecord in project cdap by caskdata.

the class ListProgramsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    List<ProgramRecord> programs = appClient.listAllPrograms(cliConfig.getCurrentNamespace(), programType);
    Table table = Table.builder().setHeader("app", "id", "description").setRows(programs, new RowMaker<ProgramRecord>() {

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

Example 5 with ProgramRecord

use of io.cdap.cdap.proto.ProgramRecord 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(io.cdap.cdap.cli.util.table.Table) ProgramRecord(io.cdap.cdap.proto.ProgramRecord) RowMaker(io.cdap.cdap.cli.util.RowMaker) List(java.util.List) ProgramType(io.cdap.cdap.proto.ProgramType)

Aggregations

ProgramRecord (io.cdap.cdap.proto.ProgramRecord)10 RowMaker (io.cdap.cdap.cli.util.RowMaker)3 Table (io.cdap.cdap.cli.util.table.Table)3 ProgramType (io.cdap.cdap.proto.ProgramType)3 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)3 List (java.util.List)3 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)2 ProgramId (io.cdap.cdap.proto.id.ProgramId)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AllProgramsApp (io.cdap.cdap.AllProgramsApp)1 BadRequestException (io.cdap.cdap.common.BadRequestException)1 ConflictException (io.cdap.cdap.common.ConflictException)1 NotFoundException (io.cdap.cdap.common.NotFoundException)1 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)1 ProgramNotFoundException (io.cdap.cdap.common.ProgramNotFoundException)1 TooManyRequestsException (io.cdap.cdap.common.TooManyRequestsException)1 ApplicationDetail (io.cdap.cdap.proto.ApplicationDetail)1 ApplicationRecord (io.cdap.cdap.proto.ApplicationRecord)1