diff options
| author | mjkwiatkowski <mati.rewa@gmail.com> | 2026-06-15 23:54:52 +0200 |
|---|---|---|
| committer | mjkwiatkowski <mati.rewa@gmail.com> | 2026-06-15 23:54:52 +0200 |
| commit | fa3ec84a38ca24157d5fb52a9715d9dad9a3e8c6 (patch) | |
| tree | f8da16e1e176b3153ad46cbb6830898181ec7680 | |
| parent | 0731bd58889df127ef87aba2590d505d79e6646f (diff) | |
feat: migrated the SmarScheduler and the KafkaMonitor
3 files changed, 156 insertions, 9 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/SmartScheduler.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/SmartScheduler.kt new file mode 100644 index 00000000..baadd806 --- /dev/null +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/scheduler/SmartScheduler.kt @@ -0,0 +1,72 @@ +/* + * 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 + * 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.compute.simulator.scheduler + +import org.opendc.common.utils.HTTPClient +import org.opendc.compute.simulator.service.HostView +import org.opendc.compute.simulator.service.ServiceTask + +public class SmartScheduler : ComputeScheduler { + private val client = HTTPClient.getInstance() + // the point is that a smart scheduler listens for suggestions from the + // digital twin + // and here is where you change your actions based on the result from the DT + // predictive analytics is going to be much easier to do. + // you will completely overcome the overhead of having to tap-into + // the digital twin mid-through the simulation/in between two hosts being scheduled + // i.e., the normal simulation will NOT have to wait. + // predictive analytics will overcome the problem of the scheduling time overhead + + override fun addHost(host: HostView) { + TODO("Not yet implemented") + } + + override fun removeHost(host: HostView) { + TODO("Not yet implemented") + } + + override fun updateHost(host: HostView) { + TODO("Not yet implemented") + } + + override fun setHostEmpty(hostView: HostView) { + TODO("Not yet implemented") + } + + override fun select(iter: MutableIterator<SchedulingRequest>): SchedulingResult { + TODO("Not yet implemented") + // Here be the API calls using HTTP between the other OpenDC + // You need to specify how much time do you have to make the prediction between receiving a time and putting onto a host + return SchedulingResult(SchedulingResultType.EMPTY) + } + + // Benefits of a digital twin: during operations you make sure what is happening in the real world. + // The use-case is making split-second automated decisions before operators can make them. + // Make a strong case for making a Digital Twin. + override fun removeTask( + task: ServiceTask, + host: HostView?, + ) { + TODO("Not yet implemented") + } +} diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/KafkaComputeMonitor.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/KafkaComputeMonitor.kt new file mode 100644 index 00000000..c8368af2 --- /dev/null +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/KafkaComputeMonitor.kt @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2026 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.compute.simulator.telemetry + +import org.opendc.common.ProtobufMetrics +import org.opendc.common.utils.Kafka +import org.opendc.compute.simulator.telemetry.table.host.HostTableReader +/** + * This class logs data from the simulator into a Kafka topic. + * The data uses the Protobuf format. + * + * @author Mateusz Kwiatkowski + * + * @see <a href=https://protobuf.dev/getting-started/javatutorial/> + * https://protobuf.dev/getting-started/javatutorial/</a> + */ +public class KafkaComputeMonitor : ComputeMonitor { + private val send = Kafka("postgres_topic").getSend() + + @Override + override fun record(reader: HostTableReader) { + try { + val packet = + ProtobufMetrics.ProtoExport.newBuilder() + .setTimestamp(reader.timestamp.toEpochMilli().toString()) + .setHostId(reader.hostInfo.name) + .setTasksactive(reader.tasksActive) + .setCpuutilization(reader.cpuUtilization) + .setEnergyusage(reader.energyUsage) + .build() + this.send(packet) + + } catch (e: Exception) { + println("${e.message}") + } + } +} diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt index d231b93b..1fe597ea 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/base/runner/ExperimentCli.kt @@ -28,27 +28,45 @@ import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.options.defaultLazy import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.file +import org.opendc.common.utils.HTTPClient import org.opendc.experiments.base.experiment.getExperiment import java.io.File +import java.io.IOException /** * Main entrypoint of the application. */ -public fun main(args: Array<String>): Unit = ExperimentCommand().main(args) +public fun main(args: Array<String>) { + if(args.size == 2) ExperimentCommand().main(args) + else ExperimentListener().main(args) +} -/** - * Represents the command for the Scenario experiments. - */ internal class ExperimentCommand : CliktCommand(name = "experiment") { - /** - * The path to the environment directory. - */ private val experimentPath by option("--experiment-path", help = "path to experiment file") .file(canBeDir = false, canBeFile = true) .defaultLazy { File("resources/experiment.json") } override fun run() { - val experiment = getExperiment(experimentPath) - runExperiment(experiment) + try { + val experiment = getExperiment(experimentPath) + HTTPClient.getInstance()?.sendExperiment(experimentPath) + runExperiment(experiment) + } catch (e: IOException) { + println("${e.message}") + } + } +} +/** + * Entry point to the digital twin. + * + * @author Mateusz Kwiatkowski + */ +internal class ExperimentListener: CliktCommand(name = "listener") { + override fun run() { + try { + runListener() + } catch (e: IOException) { + println("${e.message}") + } } } |
