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);
}
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;
}
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();
}
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);
}
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);
}
Aggregations