use of io.cdap.cdap.internal.app.runtime.schedule.SchedulerException in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method batchRunTimes.
/**
* Fetches scheduled run times for a set of programs.
*
* @param namespace namespace of the programs
* @param programs the list of programs to fetch scheduled run times
* @param previous {@code true} to get the previous scheduled times; {@code false} to get the next scheduled times
* @return a list of {@link BatchProgramSchedule} containing the result
* @throws SchedulerException if failed to fetch schedules
*/
private List<BatchProgramSchedule> batchRunTimes(String namespace, Collection<? extends BatchProgram> programs, boolean previous) throws Exception {
List<ProgramId> programIds = programs.stream().map(p -> new ProgramId(namespace, p.getAppId(), p.getProgramType(), p.getProgramId())).collect(Collectors.toList());
Set<ApplicationId> appIds = programIds.stream().map(ProgramId::getParent).collect(Collectors.toSet());
Map<ApplicationId, ApplicationSpecification> appSpecs = store.getApplications(appIds);
List<BatchProgramSchedule> result = new ArrayList<>();
for (ProgramId programId : programIds) {
ApplicationSpecification spec = appSpecs.get(programId.getParent());
if (spec == null) {
result.add(new BatchProgramSchedule(programId, HttpResponseStatus.NOT_FOUND.code(), new NotFoundException(programId.getParent()).getMessage(), null));
continue;
}
try {
Store.ensureProgramExists(programId, spec);
result.add(new BatchProgramSchedule(programId, HttpResponseStatus.OK.code(), null, getScheduledRunTimes(programId, previous)));
} catch (NotFoundException e) {
result.add(new BatchProgramSchedule(programId, HttpResponseStatus.NOT_FOUND.code(), e.getMessage(), null));
} catch (BadRequestException e) {
result.add(new BatchProgramSchedule(programId, HttpResponseStatus.BAD_REQUEST.code(), e.getMessage(), null));
}
}
return result;
}
Aggregations