From a424aa5e81c31f8cc6ba8846f0a6af29623588d4 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 3 Aug 2022 11:11:58 +0200 Subject: refactor(web/runner): Support pluggable job manager This change introduces a new interface `JobManager` that is responsible for communicating with the backend about the available jobs and updating their status when the runner is simulating a job. This manager can be injected into the `OpenDCRunner` class and allows users to provide different sources for the jobs, not only the current REST API. --- .../main/kotlin/org/opendc/web/api/rest/runner/JobResource.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'opendc-web/opendc-web-api/src/main') diff --git a/opendc-web/opendc-web-api/src/main/kotlin/org/opendc/web/api/rest/runner/JobResource.kt b/opendc-web/opendc-web-api/src/main/kotlin/org/opendc/web/api/rest/runner/JobResource.kt index 7e31e2c5..d9923505 100644 --- a/opendc-web/opendc-web-api/src/main/kotlin/org/opendc/web/api/rest/runner/JobResource.kt +++ b/opendc-web/opendc-web-api/src/main/kotlin/org/opendc/web/api/rest/runner/JobResource.kt @@ -60,6 +60,13 @@ class JobResource @Inject constructor(private val jobService: JobService) { @Path("{job}") @Transactional fun update(@PathParam("job") id: Long, @Valid update: Job.Update): Job { - return jobService.updateState(id, update.state, update.results) ?: throw WebApplicationException("Job not found", 404) + return try { + jobService.updateState(id, update.state, update.results) + ?: throw WebApplicationException("Job not found", 404) + } catch (e: IllegalArgumentException) { + throw WebApplicationException(e, 400) + } catch (e: IllegalStateException) { + throw WebApplicationException(e, 409) + } } } -- cgit v1.2.3