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