Class JobsController

java.lang.Object
edu.ucsb.cs156.frontiers.controllers.ApiController
edu.ucsb.cs156.frontiers.controllers.JobsController

@RequestMapping("/api/jobs") @RestController public class JobsController extends ApiController
App-level job endpoints: launching this app's concrete jobs, plus the course-scoped jobs listing and course-scoped full-log endpoint (which use this app's CourseSecurity rule). The generic admin endpoints (list all / paginated / logs / delete) come from the lib-jobs library's own controller.
  • Constructor Details

    • JobsController

      public JobsController()
  • Method Details

    • launchUpdateAllJob

      @PreAuthorize("hasRole('ROLE_ADMIN')") @PostMapping("/launch/updateAll") public edu.ucsb.cs156.jobs.entities.Job launchUpdateAllJob()
    • launchAuditAllCoursesJob

      @PreAuthorize("hasRole('ROLE_ADMIN')") @PostMapping("/launch/auditAllCourses") public edu.ucsb.cs156.jobs.entities.Job launchAuditAllCoursesJob()
    • launchPushTeamsToGithubJob

      @PreAuthorize("hasRole('ROLE_ADMIN')") @PostMapping("/launch/pushTeamsToGithub") public edu.ucsb.cs156.jobs.entities.Job launchPushTeamsToGithubJob(@RequestParam Long courseId)
    • launchPullTeamsFromGithubJob

      @PreAuthorize("hasRole('ROLE_ADMIN')") @PostMapping("/launch/pullTeamsFromGithub") public edu.ucsb.cs156.jobs.entities.Job launchPullTeamsFromGithubJob(@RequestParam Long courseId)
    • launchDeleteTeamMemberFromGithubJob

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PostMapping("/launch/deleteTeamMemberFromGithub") public edu.ucsb.cs156.jobs.entities.Job launchDeleteTeamMemberFromGithubJob(@RequestParam String memberGithubLogin, @RequestParam Integer githubTeamId, @RequestParam Long courseId)
    • launchAddTeamMemberToGithubJob

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PostMapping("/launch/addTeamMemberToGithub") public edu.ucsb.cs156.jobs.entities.Job launchAddTeamMemberToGithubJob(@RequestParam String memberGithubLogin, @RequestParam Integer githubTeamId, @RequestParam Long teamMemberId, @RequestParam Long courseId)
    • launchDeleteTeamFromGithubJob

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PostMapping("/launch/deleteTeamFromGithub") public edu.ucsb.cs156.jobs.entities.Job launchDeleteTeamFromGithubJob(@RequestParam Integer githubTeamId, @RequestParam Long courseId)
    • launchAddTeamToGithubJob

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PostMapping("/launch/addTeamToGithub") public edu.ucsb.cs156.jobs.entities.Job launchAddTeamToGithubJob(@RequestParam String teamName, @RequestParam Long courseId)
    • jobsByCourse

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @GetMapping("/course") public Iterable<edu.ucsb.cs156.jobs.entities.Job> jobsByCourse(@RequestParam Long courseId)
    • jobLogsByCourse

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @GetMapping("/course/logs") public String jobLogsByCourse(@RequestParam Long courseId, @RequestParam Long jobId)
      Returns the full log of one job that belongs to the given course.

      Why this app-owned endpoint exists: the library's own GET /api/jobs/logs/{id} returns the full log but is restricted to ROLE_ADMIN. The per-course jobs tab is used by course instructors and staff who are not necessarily admins, and the course-scoped listing above only populates Job.log with a short tail preview ( JobService.getJobLogPreview). This endpoint gives those users the same full log, guarded by the same course-permission rule as the listing.

      A job that exists but is not scoped to the given course is deliberately reported as not found (404) rather than forbidden (403), so that job ids do not leak across courses.

      Parameters:
      courseId - the id of the course the job must belong to
      jobId - the id of the job
      Returns:
      the full job log, oldest line first
    • jobLogTailByCourse

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @GetMapping("/course/logs/tail") public JobLogTail jobLogTailByCourse(@RequestParam Long courseId, @RequestParam Long jobId, @RequestParam(defaultValue="0") Long afterId)
      Returns the log lines of one job that belong to the given course that were written after the line with id afterId, together with the job's status: one poll of a "tail -f" style view. The client keeps the id of the last line it has received and passes it as afterId on its next poll, and stops polling once the status is one of a job that has finished.

      This is the course-scoped counterpart of the library's admin-only GET /api/jobs/logs/{id}/tail, for the same reason as jobLogsByCourse(Long, Long). Like that endpoint it reports a job of another course as not found.

      The status is read before the lines. If the job has already finished when its status is read, all of its lines have been written by the time they are read, so a client that stops polling on a finished status has not missed any. Reading them the other way round could miss the last lines of a job that finishes in between.

      Parameters:
      courseId - the id of the course the job must belong to
      jobId - the id of the job
      afterId - only lines with an id greater than this are returned; 0 for the whole log
      Returns:
      the status of the job and its new log lines, oldest first