| 1 | package edu.ucsb.cs156.courses.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.courses.jobs.TestJob; | |
| 4 | import edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobFactory; | |
| 5 | import edu.ucsb.cs156.courses.jobs.UploadGradeDataJob; | |
| 6 | import edu.ucsb.cs156.courses.jobs.UploadGradeDataJobFactory; | |
| 7 | import edu.ucsb.cs156.jobs.entities.Job; | |
| 8 | import edu.ucsb.cs156.jobs.services.JobService; | |
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.PostMapping; | |
| 16 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 17 | import org.springframework.web.bind.annotation.RequestParam; | |
| 18 | import org.springframework.web.bind.annotation.RestController; | |
| 19 | ||
| 20 | /** | |
| 21 | * Launch endpoints for this app's concrete jobs. The generic admin endpoints (list jobs, get | |
| 22 | * paginated jobs, get logs, delete jobs) come from the lib-jobs library's own controller. | |
| 23 | */ | |
| 24 | @Tag(name = "Jobs") | |
| 25 | @RequestMapping("/api/jobs") | |
| 26 | @RestController | |
| 27 | @Slf4j | |
| 28 | public class JobsController extends ApiController { | |
| 29 | ||
| 30 | @Autowired private JobService jobService; | |
| 31 | ||
| 32 | @Autowired UpdateCourseDataJobFactory updateCourseDataJobFactory; | |
| 33 | ||
| 34 | @Autowired UploadGradeDataJobFactory updateGradeDataJobFactory; | |
| 35 | ||
| 36 | @Operation(summary = "Launch Job to Update Course Data") | |
| 37 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 38 | @PostMapping("/launch/updateCourses") | |
| 39 | public Job launchUpdateCourseDataJob( | |
| 40 | @Parameter(name = "quarterYYYYQ", description = "quarter (YYYYQ format)") @RequestParam | |
| 41 | String quarterYYYYQ, | |
| 42 | @Parameter(name = "subjectArea") @RequestParam String subjectArea, | |
| 43 | @Parameter( | |
| 44 | name = "ifStale", | |
| 45 | description = "true if job should only update when data is stale") | |
| 46 | @RequestParam(defaultValue = "true") | |
| 47 | Boolean ifStale) { | |
| 48 | ||
| 49 | log.info( | |
| 50 | "launchUpdateCourseDataJob: quarterYYYYQ={}, subjectArea={}, ifStale={}", | |
| 51 | quarterYYYYQ, | |
| 52 | subjectArea, | |
| 53 | ifStale); | |
| 54 | var job = | |
| 55 | updateCourseDataJobFactory.createForSubjectAndQuarterAndIfStale( | |
| 56 | subjectArea, quarterYYYYQ, ifStale); | |
| 57 | ||
| 58 |
1
1. launchUpdateCourseDataJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataJob → KILLED |
return jobService.runAsJob(job); |
| 59 | } | |
| 60 | ||
| 61 | @Operation(summary = "Launch Job to Update Course Data using Quarter") | |
| 62 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 63 | @PostMapping("/launch/updateQuarterCourses") | |
| 64 | public Job launchUpdateCourseDataWithQuarterJob( | |
| 65 | @Parameter(name = "quarterYYYYQ", description = "quarter (YYYYQ format)") @RequestParam | |
| 66 | String quarterYYYYQ, | |
| 67 | @Parameter( | |
| 68 | name = "ifStale", | |
| 69 | description = "true if job should only update when data is stale") | |
| 70 | @RequestParam(defaultValue = "true") | |
| 71 | Boolean ifStale) { | |
| 72 | ||
| 73 | var job = updateCourseDataJobFactory.createForQuarter(quarterYYYYQ, ifStale); | |
| 74 | ||
| 75 |
1
1. launchUpdateCourseDataWithQuarterJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataWithQuarterJob → KILLED |
return jobService.runAsJob(job); |
| 76 | } | |
| 77 | ||
| 78 | @Operation(summary = "Launch Job to Update Course Data for range of quarters") | |
| 79 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 80 | @PostMapping("/launch/updateCoursesRangeOfQuarters") | |
| 81 | public Job launchUpdateCourseDataRangeOfQuartersJob( | |
| 82 | @Parameter(name = "start_quarterYYYYQ", description = "start quarter (YYYYQ format)") | |
| 83 | @RequestParam | |
| 84 | String start_quarterYYYYQ, | |
| 85 | @Parameter(name = "end_quarterYYYYQ", description = "end quarter (YYYYQ format)") | |
| 86 | @RequestParam | |
| 87 | String end_quarterYYYYQ, | |
| 88 | @Parameter( | |
| 89 | name = "ifStale", | |
| 90 | description = "true if job should only update when data is stale") | |
| 91 | @RequestParam(defaultValue = "true") | |
| 92 | Boolean ifStale) { | |
| 93 | ||
| 94 | var job = | |
| 95 | updateCourseDataJobFactory.createForQuarterRange( | |
| 96 | start_quarterYYYYQ, end_quarterYYYYQ, ifStale); | |
| 97 | ||
| 98 |
1
1. launchUpdateCourseDataRangeOfQuartersJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataRangeOfQuartersJob → KILLED |
return jobService.runAsJob(job); |
| 99 | } | |
| 100 | ||
| 101 | @Operation( | |
| 102 | summary = "Launch Job to Update Course Data for a range of quarters for a single subject") | |
| 103 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 104 | @PostMapping("/launch/updateCoursesRangeOfQuartersSingleSubject") | |
| 105 | public Job launchUpdateCourseDataRangeOfQuartersSingleSubjectJob( | |
| 106 | @Parameter(name = "subjectArea", description = "subject area") @RequestParam | |
| 107 | String subjectArea, | |
| 108 | @Parameter(name = "start_quarterYYYYQ", description = "start quarter (YYYYQ format)") | |
| 109 | @RequestParam | |
| 110 | String start_quarterYYYYQ, | |
| 111 | @Parameter(name = "end_quarterYYYYQ", description = "end quarter (YYYYQ format)") | |
| 112 | @RequestParam | |
| 113 | String end_quarterYYYYQ, | |
| 114 | @Parameter( | |
| 115 | name = "ifStale", | |
| 116 | description = "true if job should only update when data is stale") | |
| 117 | @RequestParam(defaultValue = "true") | |
| 118 | Boolean ifStale) { | |
| 119 | ||
| 120 | var job = | |
| 121 | updateCourseDataJobFactory.createForSubjectAndQuarterRange( | |
| 122 | subjectArea, start_quarterYYYYQ, end_quarterYYYYQ, ifStale); | |
| 123 | ||
| 124 |
1
1. launchUpdateCourseDataRangeOfQuartersSingleSubjectJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataRangeOfQuartersSingleSubjectJob → KILLED |
return jobService.runAsJob(job); |
| 125 | } | |
| 126 | ||
| 127 | @Operation(summary = "Launch Job to update grade history") | |
| 128 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 129 | @PostMapping("/launch/uploadGradeData") | |
| 130 | public Job launchUploadGradeData() { | |
| 131 | UploadGradeDataJob updateGradeDataJob = updateGradeDataJobFactory.create(); | |
| 132 |
1
1. launchUploadGradeData : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUploadGradeData → KILLED |
return jobService.runAsJob(updateGradeDataJob); |
| 133 | } | |
| 134 | ||
| 135 | @Operation(summary = "Launch Test Job (a job that sleeps, logs, and optionally fails)") | |
| 136 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 137 | @PostMapping("/launch/testjob") | |
| 138 | public Job launchTestJob( | |
| 139 | @Parameter(name = "fail") @RequestParam Boolean fail, | |
| 140 | @Parameter(name = "sleepMs") @RequestParam Integer sleepMs) { | |
| 141 | TestJob testJob = TestJob.builder().fail(fail).sleepMs(sleepMs).build(); | |
| 142 |
1
1. launchTestJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchTestJob → KILLED |
return jobService.runAsJob(testJob); |
| 143 | } | |
| 144 | } | |
Mutations | ||
| 58 |
1.1 |
|
| 75 |
1.1 |
|
| 98 |
1.1 |
|
| 124 |
1.1 |
|
| 132 |
1.1 |
|
| 142 |
1.1 |