| 1 | package edu.ucsb.cs156.dining.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.dining.jobs.TestJob; | |
| 4 | import edu.ucsb.cs156.jobs.entities.Job; | |
| 5 | import edu.ucsb.cs156.jobs.services.JobService; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import lombok.extern.slf4j.Slf4j; | |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | |
| 11 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 12 | import org.springframework.web.bind.annotation.PostMapping; | |
| 13 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 14 | import org.springframework.web.bind.annotation.RequestParam; | |
| 15 | import org.springframework.web.bind.annotation.RestController; | |
| 16 | ||
| 17 | /** | |
| 18 | * Launch endpoints for this app's concrete jobs. The generic admin endpoints (list jobs, get logs, | |
| 19 | * delete jobs) come from the lib-jobs library's own controller. | |
| 20 | */ | |
| 21 | @Tag(name = "Jobs") | |
| 22 | @RequestMapping("/api/jobs") | |
| 23 | @RestController | |
| 24 | @Slf4j | |
| 25 | public class JobsController { | |
| 26 | ||
| 27 | @Autowired private JobService jobService; | |
| 28 | ||
| 29 | @Operation(summary = "Launch Test Job (a job that sleeps, logs, and optionally fails)") | |
| 30 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 31 | @PostMapping("/launch/testjob") | |
| 32 | public Job launchTestJob( | |
| 33 | @Parameter(name = "fail") @RequestParam Boolean fail, | |
| 34 | @Parameter(name = "sleepMs") @RequestParam Integer sleepMs) { | |
| 35 | TestJob testJob = TestJob.builder().fail(fail).sleepMs(sleepMs).build(); | |
| 36 |
1
1. launchTestJob : replaced return value with null for edu/ucsb/cs156/dining/controllers/JobsController::launchTestJob → KILLED |
return jobService.runAsJob(testJob); |
| 37 | } | |
| 38 | } | |
Mutations | ||
| 36 |
1.1 |