diff options
| -rw-r--r-- | opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/util/DevSecurityOverrideFilter.java (renamed from opendc-web/opendc-web-server/src/main/kotlin/org/opendc/web/server/util/DevSecurityOverrideFilter.kt) | 47 | ||||
| -rw-r--r-- | opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/util/runner/QuarkusJobManager.java | 83 | ||||
| -rw-r--r-- | opendc-web/opendc-web-server/src/main/kotlin/org/opendc/web/server/util/runner/QuarkusJobManager.kt | 68 |
3 files changed, 113 insertions, 85 deletions
diff --git a/opendc-web/opendc-web-server/src/main/kotlin/org/opendc/web/server/util/DevSecurityOverrideFilter.kt b/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/util/DevSecurityOverrideFilter.java index 0bdf959a..de4478cb 100644 --- a/opendc-web/opendc-web-server/src/main/kotlin/org/opendc/web/server/util/DevSecurityOverrideFilter.kt +++ b/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/util/DevSecurityOverrideFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 AtLarge Research + * Copyright (c) 2021 AtLarge Research * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,15 +20,15 @@ * SOFTWARE. */ -package org.opendc.web.server.util +package org.opendc.web.server.util; -import io.quarkus.arc.properties.IfBuildProperty -import java.security.Principal -import javax.ws.rs.container.ContainerRequestContext -import javax.ws.rs.container.ContainerRequestFilter -import javax.ws.rs.container.PreMatching -import javax.ws.rs.core.SecurityContext -import javax.ws.rs.ext.Provider +import io.quarkus.arc.properties.IfBuildProperty; +import java.security.Principal; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.container.PreMatching; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.ext.Provider; /** * Helper class to disable security for the OpenDC web API when in development mode. @@ -36,16 +36,29 @@ import javax.ws.rs.ext.Provider @Provider @PreMatching @IfBuildProperty(name = "opendc.security.enabled", stringValue = "false") -class DevSecurityOverrideFilter : ContainerRequestFilter { - override fun filter(requestContext: ContainerRequestContext) { - requestContext.securityContext = object : SecurityContext { - override fun getUserPrincipal(): Principal = Principal { "anon" } +public class DevSecurityOverrideFilter implements ContainerRequestFilter { + @Override + public void filter(ContainerRequestContext requestContext) { + requestContext.setSecurityContext(new SecurityContext() { + @Override + public Principal getUserPrincipal() { + return () -> "anon"; + } - override fun isSecure(): Boolean = false + @Override + public boolean isUserInRole(String role) { + return true; + } - override fun isUserInRole(role: String): Boolean = true + @Override + public boolean isSecure() { + return false; + } - override fun getAuthenticationScheme(): String = "basic" - } + @Override + public String getAuthenticationScheme() { + return "basic"; + } + }); } } diff --git a/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/util/runner/QuarkusJobManager.java b/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/util/runner/QuarkusJobManager.java new file mode 100644 index 00000000..ed1f7bf1 --- /dev/null +++ b/opendc-web/opendc-web-server/src/main/java/org/opendc/web/server/util/runner/QuarkusJobManager.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.web.server.util.runner; + +import java.util.Map; +import javax.enterprise.context.ApplicationScoped; +import javax.transaction.Transactional; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.opendc.web.proto.JobState; +import org.opendc.web.proto.runner.Job; +import org.opendc.web.runner.JobManager; +import org.opendc.web.server.service.JobService; + +/** + * Implementation of {@link JobManager} that interfaces directly with {@link JobService} without overhead of the REST API. + */ +@ApplicationScoped +public class QuarkusJobManager implements JobManager { + private final JobService jobService; + + public QuarkusJobManager(JobService jobService) { + this.jobService = jobService; + } + + @Transactional + @Nullable + @Override + public Job findNext() { + var pending = jobService.queryPending(); + if (pending.isEmpty()) { + return null; + } + + return pending.get(0); + } + + @Override + public boolean claim(long id) { + try { + jobService.updateState(id, JobState.CLAIMED, 0, null); + return true; + } catch (IllegalStateException e) { + return false; + } + } + + @Override + public boolean heartbeat(long id, int runtime) { + Job res = jobService.updateState(id, JobState.RUNNING, runtime, null); + return res != null && !res.getState().equals(JobState.FAILED); + } + + @Override + public void fail(long id, int runtime) { + jobService.updateState(id, JobState.FAILED, runtime, null); + } + + @Override + public void finish(long id, int runtime, @NotNull Map<String, ?> results) { + jobService.updateState(id, JobState.FINISHED, runtime, results); + } +} diff --git a/opendc-web/opendc-web-server/src/main/kotlin/org/opendc/web/server/util/runner/QuarkusJobManager.kt b/opendc-web/opendc-web-server/src/main/kotlin/org/opendc/web/server/util/runner/QuarkusJobManager.kt deleted file mode 100644 index 742a510c..00000000 --- a/opendc-web/opendc-web-server/src/main/kotlin/org/opendc/web/server/util/runner/QuarkusJobManager.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2022 AtLarge Research - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package org.opendc.web.server.util.runner - -import org.opendc.web.proto.JobState -import org.opendc.web.proto.runner.Job -import org.opendc.web.runner.JobManager -import org.opendc.web.server.service.JobService -import javax.enterprise.context.ApplicationScoped -import javax.inject.Inject -import javax.transaction.Transactional - -/** - * Implementation of [JobManager] that interfaces directly with [JobService] without overhead of the REST API. - */ -@ApplicationScoped -class QuarkusJobManager @Inject constructor(private val service: JobService) : JobManager { - @Transactional - override fun findNext(): Job? { - return service.queryPending().firstOrNull() - } - - @Transactional - override fun claim(id: Long): Boolean { - return try { - service.updateState(id, JobState.CLAIMED, 0, null) - true - } catch (e: IllegalStateException) { - false - } - } - - @Transactional - override fun heartbeat(id: Long, runtime: Int): Boolean { - val res = service.updateState(id, JobState.RUNNING, runtime, null) - return res?.state != JobState.FAILED - } - - @Transactional - override fun fail(id: Long, runtime: Int) { - service.updateState(id, JobState.FAILED, runtime, null) - } - - @Transactional - override fun finish(id: Long, runtime: Int, results: Map<String, Any>) { - service.updateState(id, JobState.FINISHED, runtime, results) - } -} |
