@Override public List<ProgramHistory> getRuns(Collection<ProgramId> programs, ProgramRunStatus status, long startTime, long endTime, int limit, Predicate<RunRecordMeta> filter) { return Transactionals.execute(transactional, context -> { List<ProgramHistory> result = new ArrayList<>(programs.size()); AppMetadataStore appMetadataStore = getAppMetadataStore(context); Collection<ApplicationId> appIds = programs.stream().map(ProgramId::getParent).collect(Collectors.toList()); Map<ApplicationId, ApplicationMeta> apps = appMetadataStore.getApplicationsForAppIds(appIds); for (ProgramId program : programs) { ApplicationMeta appMeta = apps.get(program.getParent()); if (appMeta == null) { result.add(new ProgramHistory(program, Collections.emptyList(), new ApplicationNotFoundException(program.getParent()))); continue; } ApplicationSpecification appSpec = appMeta.getSpec(); ProgramSpecification programSpec = getExistingAppProgramSpecification(appSpec, program); if (programSpec == null) { result.add(new ProgramHistory(program, Collections.emptyList(), new ProgramNotFoundException(program))); continue; } List<RunRecord> runs = appMetadataStore.getRuns(program, status, startTime, endTime, limit, filter).values() .stream() .map(record -> RunRecord.builder(record).build()).collect(Collectors.toList()); result.add(new ProgramHistory(program, runs, null)); } return result; }); }
@Override public List<ProgramHistory> getRuns(Collection<ProgramId> programs, ProgramRunStatus status, long startTime, long endTime, int limit, Predicate<RunRecordMeta> filter) { return Transactionals.execute(transactional, context -> { List<ProgramHistory> result = new ArrayList<>(programs.size()); AppMetadataStore appMetadataStore = getAppMetadataStore(context); Collection<ApplicationId> appIds = programs.stream().map(ProgramId::getParent).collect(Collectors.toList()); Map<ApplicationId, ApplicationMeta> apps = appMetadataStore.getApplicationsForAppIds(appIds); for (ProgramId program : programs) { ApplicationMeta appMeta = apps.get(program.getParent()); if (appMeta == null) { result.add(new ProgramHistory(program, Collections.emptyList(), new ApplicationNotFoundException(program.getParent()))); continue; } ApplicationSpecification appSpec = appMeta.getSpec(); ProgramSpecification programSpec = getExistingAppProgramSpecification(appSpec, program); if (programSpec == null) { result.add(new ProgramHistory(program, Collections.emptyList(), new ProgramNotFoundException(program))); continue; } List<RunRecord> runs = appMetadataStore.getRuns(program, status, startTime, endTime, limit, filter).values() .stream() .map(record -> RunRecord.builder(record).build()).collect(Collectors.toList()); result.add(new ProgramHistory(program, runs, null)); } return result; }); }
/** * Returns run record for a particular run of a program of an app version. */ @GET @Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}/runs/{run-id}") public void programRunRecord(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("app-version") String appVersion, @PathParam("program-type") String type, @PathParam("program-name") String programName, @PathParam("run-id") String runid) throws NotFoundException, BadRequestException { ProgramType programType = getProgramType(type); ProgramId progId = new ApplicationId(namespaceId, appName, appVersion).program(programType, programName); RunRecordMeta runRecordMeta = store.getRun(progId.run(runid)); if (runRecordMeta != null) { RunRecord runRecord = RunRecord.builder(runRecordMeta).build(); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runRecord)); return; } throw new NotFoundException(progId.run(runid)); }
/** * Get the latest runs within the specified start and end times for the specified program. * * @param programId the program to get runs for * @param programRunStatus status of runs to return * @param start earliest start time of runs to return * @param end latest start time of runs to return * @param limit the maximum number of runs to return * @return the latest runs for the program sorted by start time, with the newest run as the first run * @throws NotFoundException if the application to which this program belongs was not found or the program is not * found in the app * @throws UnauthorizedException if the principal does not have access to the program * @throws Exception if there was some other exception performing authorization checks */ public List<RunRecord> getRuns(ProgramId programId, ProgramRunStatus programRunStatus, long start, long end, int limit) throws Exception { AuthorizationUtil.ensureAccess(programId, authorizationEnforcer, authenticationContext.getPrincipal()); ProgramSpecification programSpec = getProgramSpecificationWithoutAuthz(programId); if (programSpec == null) { throw new NotFoundException(programId); } return store.getRuns(programId, programRunStatus, start, end, limit).values().stream() .map(record -> RunRecord.builder(record).build()).collect(Collectors.toList()); }
/** * Get the latest runs within the specified start and end times for the specified program. * * @param programId the program to get runs for * @param programRunStatus status of runs to return * @param start earliest start time of runs to return * @param end latest start time of runs to return * @param limit the maximum number of runs to return * @return the latest runs for the program sorted by start time, with the newest run as the first run * @throws NotFoundException if the application to which this program belongs was not found or the program is not * found in the app * @throws UnauthorizedException if the principal does not have access to the program * @throws Exception if there was some other exception performing authorization checks */ public List<RunRecord> getRuns(ProgramId programId, ProgramRunStatus programRunStatus, long start, long end, int limit) throws Exception { AuthorizationUtil.ensureAccess(programId, authorizationEnforcer, authenticationContext.getPrincipal()); ProgramSpecification programSpec = getProgramSpecificationWithoutAuthz(programId); if (programSpec == null) { throw new NotFoundException(programId); } return store.getRuns(programId, programRunStatus, start, end, limit).values().stream() .map(record -> RunRecord.builder(record).build()).collect(Collectors.toList()); }
/** * Returns run record for a particular run of a program of an app version. */ @GET @Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}/runs/{run-id}") public void programRunRecord(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("app-version") String appVersion, @PathParam("program-type") String type, @PathParam("program-name") String programName, @PathParam("run-id") String runid) throws NotFoundException, BadRequestException { ProgramType programType = getProgramType(type); ProgramId progId = new ApplicationId(namespaceId, appName, appVersion).program(programType, programName); RunRecordMeta runRecordMeta = store.getRun(progId.run(runid)); if (runRecordMeta != null) { RunRecord runRecord = RunRecord.builder(runRecordMeta).build(); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runRecord)); return; } throw new NotFoundException(progId.run(runid)); }
/** * @return Builder to create a RunRecord */ public static Builder builder() { return new Builder(); }
/** * @param runRecord existing record to copy fields from * @return Builder to create a RunRecord, initialized with values from the specified existing record */ public static Builder builder(RunRecord runRecord) { return new Builder(runRecord); }
/** * @return Builder to create a RunRecord */ public static Builder builder() { return new Builder(); }
/** * @param runRecord existing record to copy fields from * @return Builder to create a RunRecord, initialized with values from the specified existing record */ public static Builder builder(RunRecord runRecord) { return new Builder(runRecord); }