Skip to content

Commit

Permalink
refactor(web): Migrate web proto to Java
Browse files Browse the repository at this point in the history
This commit migrates the web protocol to Java and removes the dependency
on Jandex Gradle.
  • Loading branch information
fabianishere committed Oct 29, 2023
1 parent 5d8e351 commit f0c12a1
Show file tree
Hide file tree
Showing 43 changed files with 354 additions and 449 deletions.
1 change: 0 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ dependencies {
implementation(libs.jmh.gradle)
implementation(libs.dokka.gradle)

implementation(libs.jandex.gradle)
implementation(libs.quarkus.gradle.application)
implementation(libs.quarkus.gradle.extension)
}
5 changes: 0 additions & 5 deletions buildSrc/src/main/kotlin/quarkus-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import org.gradle.api.artifacts.type.ArtifactTypeDefinition
import org.gradle.api.attributes.Category
import org.gradle.api.attributes.VerificationType
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.withType

plugins {
id("java-conventions")
Expand All @@ -48,15 +45,13 @@ configurations.create("coverageDataElementsForQuarkus") {

extendsFrom(configurations["implementation"], configurations["runtimeOnly"])

@Suppress("UnstableApiUsage")
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category::class.java, Category.VERIFICATION))
attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType::class.java, VerificationType.JACOCO_RESULTS))
}

artifacts {
add("coverageDataElementsForQuarkus", layout.buildDirectory.file("jacoco-quarkus.exec")) {
@Suppress("UnstableApiUsage")
type = ArtifactTypeDefinition.BINARY_DATA_TYPE
builtBy(tasks.test)
}
Expand Down
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ dokka = "1.9.10"
hadoop = "3.3.6"
hypersistence-utils = "3.6.0"
jackson = "2.15.3"
jandex-gradle = "1.1.0"
java = "17"
jline = "3.23.0"
jmh-gradle = "0.7.1"
jakarta-validation = "3.0.2"
jakarta-ws-rs = "3.1.0"
junit-jupiter = "5.10.0"
kotlin = "1.9.10"
kotlin-logging = "3.0.5"
kotlinx-coroutines = "1.7.3"
log4j = "2.21.0"
microprofile-rest-client = "3.0.1"
microprofile-openapi = "3.1.1"
microprofile-config = "3.1"
mockk = "1.13.8"
Expand Down Expand Up @@ -100,14 +101,15 @@ jline = { module = "org.jline:jline", version.ref = "jline" }

# Other
jakarta-validation = { module = "jakarta.validation:jakarta.validation-api", version.ref = "jakarta-validation" }
jakarta-ws-rs-api = { module = "jakarta.ws.rs:jakarta.ws.rs-api", version.ref = "jakarta-ws-rs" }
hadoop-common = { module = "org.apache.hadoop:hadoop-common", version.ref = "hadoop" }
hadoop-mapreduce-client-core = { module = "org.apache.hadoop:hadoop-mapreduce-client-core", version.ref = "hadoop" }
commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" }
microprofile-rest-client-api = { module = "org.eclipse.microprofile.rest.client:microprofile-rest-client-api", version.ref = "microprofile-rest-client" }
microprofile-openapi-api = { module = "org.eclipse.microprofile.openapi:microprofile-openapi-api", version.ref = "microprofile-openapi" }
microprofile-config = { module = "org.eclipse.microprofile.config:microprofile-config-api", version.ref = "microprofile-config" }

# Other (Build)
dokka-gradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
jandex-gradle = { module = "org.kordamp.gradle:jandex-gradle-plugin", version.ref = "jandex-gradle" }
jmh-gradle = { module = "me.champeau.jmh:jmh-gradle-plugin", version.ref = "jmh-gradle" }
spotless-gradle = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
9 changes: 3 additions & 6 deletions opendc-web/opendc-web-proto/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ description = "Web communication protocol for OpenDC"

/* Build configuration */
plugins {
`kotlin-library-conventions`
id("org.kordamp.gradle.jandex") // Necessary for Quarkus to process annotations
`java-library-conventions`
}

dependencies {
implementation(libs.jackson.annotations)
implementation(libs.jakarta.validation)
implementation(libs.jakarta.ws.rs.api)
implementation(libs.microprofile.rest.client.api)
implementation(libs.microprofile.openapi.api)
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.javaParameters = true
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 AtLarge Research
* Copyright (c) 2023 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
Expand All @@ -20,12 +20,12 @@
* SOFTWARE.
*/

package org.opendc.web.proto
package org.opendc.web.proto;

/**
* State of a scenario for the simulator runner.
*/
public enum class JobState {
public enum JobState {
/**
* The job is pending to be claimed by a runner.
*/
Expand All @@ -49,5 +49,5 @@ public enum class JobState {
/**
* The job has failed.
*/
FAILED;
FAILED
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 AtLarge Research
* Copyright (c) 2023 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
Expand All @@ -20,12 +20,9 @@
* SOFTWARE.
*/

package org.opendc.web.proto
package org.opendc.web.proto;

/**
* Object describing the enabled operational phenomena for a scenario.
*/
public data class OperationalPhenomena(
val failures: Boolean,
val interference: Boolean
)
public record OperationalPhenomena(boolean failures, boolean interference) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 AtLarge Research
* Copyright (c) 2023 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
Expand All @@ -20,9 +20,9 @@
* SOFTWARE.
*/

package org.opendc.web.proto
package org.opendc.web.proto;

/**
* Container for reporting errors.
*/
public data class ProtocolError(val code: Int, val message: String)
public record ProtocolError(int code, String message) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 AtLarge Research
* Copyright (c) 2023 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
Expand All @@ -20,18 +20,15 @@
* SOFTWARE.
*/

package org.opendc.web.proto
package org.opendc.web.proto;

import jakarta.validation.constraints.Min
import jakarta.validation.constraints.Min;
import java.util.Set;

/**
* The targets of a portfolio.
*
* @param metrics The selected metrics to track during simulation.
* @param repeats The number of repetitions per scenario.
*/
public data class Targets(
val metrics: Set<String>,
@field:Min(1)
val repeats: Int = 1
)
public record Targets(Set<String> metrics, @Min(1) int repeats) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 AtLarge Research
* Copyright (c) 2023 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
Expand All @@ -20,7 +20,7 @@
* SOFTWARE.
*/

package org.opendc.web.proto
package org.opendc.web.proto;

/**
* A workload trace available for simulation.
Expand All @@ -29,8 +29,4 @@
* @param name The name of the trace.
* @param type The type of trace.
*/
public data class Trace(
val id: String,
val name: String,
val type: String
)
public record Trace(String id, String name, String type) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 AtLarge Research
* Copyright (c) 2023 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
Expand All @@ -20,25 +20,24 @@
* SOFTWARE.
*/

package org.opendc.web.proto
package org.opendc.web.proto;

import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;

/**
* The workload to simulate for a scenario.
*/
public data class Workload(val trace: Trace, val samplingFraction: Double) {
public record Workload(Trace trace, double samplingFraction) {
/**
* Specification for a workload.
*
* @param trace The unique identifier of the trace.
* @param samplingFraction The fraction of the workload to sample.
*/
public data class Spec(
val trace: String,
@DecimalMin(value = "0.001", message = "Sampling fraction must be non-zero")
@DecimalMax(value = "1", message = "Sampling fraction cannot exceed one")
val samplingFraction: Double
)
public record Spec(
String trace,
@DecimalMin(value = "0.001", message = "Sampling fraction must be non-zero")
@DecimalMax(value = "1", message = "Sampling fraction cannot exceed one")
double samplingFraction) {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 AtLarge Research
* Copyright (c) 2023 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
Expand All @@ -20,32 +20,32 @@
* SOFTWARE.
*/

package org.opendc.web.proto.runner
package org.opendc.web.proto.runner;

import org.eclipse.microprofile.openapi.annotations.media.Schema
import org.opendc.web.proto.JobState
import java.time.Instant
import java.time.Instant;
import java.util.Map;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.opendc.web.proto.JobState;

/**
* A simulation job to be simulated by a runner.
*/
@Schema(name = "Runner.Job")
public data class Job(
val id: Long,
val scenario: Scenario,
val state: JobState,
val createdAt: Instant,
val updatedAt: Instant,
val runtime: Int,
val results: Map<String, Any>? = null
) {
public record Job(
long id,
Scenario scenario,
JobState state,
Instant createdAt,
Instant updatedAt,
int runtime,
Map<String, ?> results) {
/**
* A request to update the state of a job.
*
* @property state The next state of the job.
* @property runtime The runtime of the job (in seconds).
* @property results The results of the job.
* @param state The next state of the job.
* @param runtime The runtime of the job (in seconds).
* @param results The results of the job.
*/
@Schema(name = "Runner.Job.Update")
public data class Update(val state: JobState, val runtime: Int, val results: Map<String, Any>? = null)
public record Update(JobState state, int runtime, Map<String, ?> results) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 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.proto.runner;

import jakarta.validation.Valid;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import java.util.List;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

/**
* Service for interacting with the OpenDC job server.
*/
@Path("/jobs")
@RegisterRestClient
public interface JobService {
/**
* Obtain all pending simulation jobs.
*/
@GET
List<Job> queryPending();

/**
* Get a job by identifier.
*/
@GET
@Path("{job}")
Job get(@PathParam("job") long id);

/**
* Atomically update the state of a job.
*/
@POST
@Path("{job}")
@Consumes("application/json")
Job update(@PathParam("job") long id, @Valid Job.Update update);
}
Loading

0 comments on commit f0c12a1

Please sign in to comment.