Search in sources :

Example 6 with ProgramRecord

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

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 7 with ProgramRecord

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

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 8 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 9 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)

Example 10 with ProgramRecord

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

the class DescribeAppCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    ApplicationId appId = parseApplicationId(arguments);
    List<ProgramRecord> programsList = applicationClient.listPrograms(appId);
    Table table = Table.builder().setHeader("type", "id", "description").setRows(programsList, new RowMaker<ProgramRecord>() {

        @Override
        public List<?> makeRow(ProgramRecord object) {
            return Lists.newArrayList(object.getType().getPrettyName(), 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) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Aggregations

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