Skip to content

Commit

Permalink
Fix spotless linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sacheendra committed Sep 12, 2024
1 parent ae25b88 commit ab8b2ea
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public interface ComputeScheduler {
public fun select(iter: MutableIterator<Task>): 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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,9 +31,8 @@ import java.util.random.RandomGenerator
public class MemorizingScheduler(
private val filters: List<HostFilter>,
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<HostView>() })
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class ReplayScheduler(private val vmPlacements: Map<String, String>) : 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")
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit ab8b2ea

Please sign in to comment.