From ab8b2eaef71f3672acfe3f981d794e3a8ff7c847 Mon Sep 17 00:00:00 2001 From: Sacheendra Talluri Date: Thu, 12 Sep 2024 15:27:13 +0200 Subject: [PATCH] Fix spotless linting issues --- .../service/scheduler/ComputeScheduler.kt | 7 ++- .../service/scheduler/FilterScheduler.kt | 6 ++- .../service/scheduler/MemorizingScheduler.kt | 45 ++++++++++++++----- .../service/scheduler/ReplayScheduler.kt | 2 +- .../service/scheduler/TwoChoiceScheduler.kt | 24 +++++++++- 5 files changed, 66 insertions(+), 18 deletions(-) diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ComputeScheduler.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ComputeScheduler.kt index 55c4f8b44..f3788d38e 100644 --- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ComputeScheduler.kt +++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ComputeScheduler.kt @@ -50,8 +50,11 @@ public interface ComputeScheduler { public fun select(iter: MutableIterator): HostView? /** - * Inform the scheduler that a task has been removed from the host. + * Inform the scheduler that a [task] has been removed from the [host]. * Could be due to completion or failure. */ - public fun removeTask(task: Task, hv: HostView) + public fun removeTask( + task: Task, + host: HostView, + ) } diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/FilterScheduler.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/FilterScheduler.kt index ef9577fcd..2707b1834 100644 --- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/FilterScheduler.kt +++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/FilterScheduler.kt @@ -23,7 +23,6 @@ package org.opendc.compute.service.scheduler import org.opendc.compute.api.Task -import org.opendc.compute.service.ComputeService import org.opendc.compute.service.HostView import org.opendc.compute.service.scheduler.filters.HostFilter import org.opendc.compute.service.scheduler.weights.HostWeigher @@ -111,7 +110,10 @@ public class FilterScheduler( } } - override fun removeTask(task: Task, hv: HostView) { + override fun removeTask( + task: Task, + host: HostView, + ) { TODO("Not yet implemented") } } diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/MemorizingScheduler.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/MemorizingScheduler.kt index b1608a6a3..458d5dc21 100644 --- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/MemorizingScheduler.kt +++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/MemorizingScheduler.kt @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2024 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.service.scheduler import org.opendc.compute.api.Task @@ -9,9 +31,8 @@ import java.util.random.RandomGenerator public class MemorizingScheduler( private val filters: List, private val random: RandomGenerator = SplittableRandom(0), - private val maxTimesSkipped: Int = 7 -): ComputeScheduler { - + private val maxTimesSkipped: Int = 7, +) : ComputeScheduler { // We assume that there will be max 200 tasks per host. // The index of a host list is the number of tasks on that host. private val hostsQueue = List(200, { mutableListOf() }) @@ -34,7 +55,7 @@ public class MemorizingScheduler( if (listIdx == chosenList.size - 1) { chosenList.removeLast() if (listIdx == minAvailableHost) { - for (i in minAvailableHost+1 .. hostsQueue.lastIndex) { + for (i in minAvailableHost + 1..hostsQueue.lastIndex) { if (hostsQueue[i].size > 0) { minAvailableHost = i break @@ -69,8 +90,8 @@ public class MemorizingScheduler( // Don't skip over it. Wait till a suitable host becomes available val q = hostsQueue[minAvailableHost] for (h in q) { - val satisfied = filters.all { filter -> filter.test(h, task) } - if (satisfied) { + val sfed = filters.all { filter -> filter.test(h, task) } + if (sfed) { chosenHost = h taskFound = true break @@ -102,9 +123,9 @@ public class MemorizingScheduler( return chosenHost } - override fun removeTask(task: Task, hv: HostView) { - val priorityIdx = hv.priorityIndex - val listIdx = hv.listIndex + override fun removeTask(task: Task, host: HostView) { + val priorityIdx = host.priorityIndex + val listIdx = host.listIndex val chosenList = hostsQueue[priorityIdx] val nextList = hostsQueue[priorityIdx - 1] @@ -118,8 +139,8 @@ public class MemorizingScheduler( chosenList[listIdx] = lastItem lastItem.listIndex = listIdx } - nextList.add(hv) - hv.priorityIndex = priorityIdx - 1 - hv.listIndex = nextList.size - 1 + nextList.add(host) + host.priorityIndex = priorityIdx - 1 + host.listIndex = nextList.size - 1 } } diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ReplayScheduler.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ReplayScheduler.kt index 64c6b3186..beebc731a 100644 --- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ReplayScheduler.kt +++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/ReplayScheduler.kt @@ -64,7 +64,7 @@ public class ReplayScheduler(private val vmPlacements: Map) : Co ?: throw IllegalStateException("Cloud not find any machine and could not randomly assign") } - override fun removeTask(task: Task, hv: HostView) { + override fun removeTask(task: Task, host: HostView) { TODO("Not yet implemented") } } diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/TwoChoiceScheduler.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/TwoChoiceScheduler.kt index 5f843daf1..1c0279b23 100644 --- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/TwoChoiceScheduler.kt +++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/TwoChoiceScheduler.kt @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2024 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.service.scheduler import org.opendc.compute.api.Task @@ -56,7 +78,7 @@ public class TwoChoiceScheduler( return chosenHost } - override fun removeTask(task: Task, hv: HostView) { + override fun removeTask(task: Task, host: HostView) { // All necessary bookkeeping is already handled by ComputeService // ComputeService increments/decrements the number of instances on a host }