Skip to content

Commit

Permalink
feat(kubernetes): Support sending LostJobs messages
Browse files Browse the repository at this point in the history
Extend `FailedJobNotifier` to support this new message type. This is
going to be used to notify Orchestrator about ORT runs for which
schedules were lost.

Signed-off-by: Oliver Heger <oliver.heger@bosch.io>
  • Loading branch information
oheger-bosch committed Dec 13, 2024
1 parent dc1da1b commit b63d6d9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kubernetes/jobmonitor/src/main/kotlin/FailedJobNotifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import io.kubernetes.client.openapi.models.V1Job

import org.eclipse.apoapsis.ortserver.kubernetes.jobmonitor.JobHandler.Companion.ortRunId
import org.eclipse.apoapsis.ortserver.kubernetes.jobmonitor.JobHandler.Companion.traceId
import org.eclipse.apoapsis.ortserver.model.ActiveOrtRun
import org.eclipse.apoapsis.ortserver.model.orchestrator.LostSchedule
import org.eclipse.apoapsis.ortserver.model.orchestrator.OrchestratorMessage
import org.eclipse.apoapsis.ortserver.model.orchestrator.WorkerError
import org.eclipse.apoapsis.ortserver.transport.Endpoint
Expand Down Expand Up @@ -69,6 +71,17 @@ internal class FailedJobNotifier(
sendToOrchestrator(message)
}

/**
* Send a notification about an ORT run without active schedules for the given [ortRun]. This is used to notify
* the Orchestrator that it has to reschedule jobs for the affected run.
*/
fun sendLostScheduleNotification(ortRun: ActiveOrtRun) {
val header = MessageHeader(ortRun.traceId.orEmpty(), ortRun.runId)
val message = Message(header, LostSchedule(ortRun.runId))

sendToOrchestrator(message)
}

/**
* Send the given [message] to the Orchestrator via the configured [MessageSender].
*/
Expand Down
26 changes: 26 additions & 0 deletions kubernetes/jobmonitor/src/test/kotlin/FailedJobNotifierTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import io.mockk.runs
import io.mockk.slot
import io.mockk.verify

import kotlinx.datetime.Clock

import org.eclipse.apoapsis.ortserver.model.ActiveOrtRun
import org.eclipse.apoapsis.ortserver.model.orchestrator.LostSchedule
import org.eclipse.apoapsis.ortserver.model.orchestrator.OrchestratorMessage
import org.eclipse.apoapsis.ortserver.model.orchestrator.WorkerError
import org.eclipse.apoapsis.ortserver.transport.Message
Expand Down Expand Up @@ -153,4 +157,26 @@ class FailedJobNotifierTest : WordSpec({
}
}
}

"sendLostScheduleNotification" should {
"send a notification about a lost schedule" {
val ortRun = ActiveOrtRun(20241211084817L, Clock.System.now(), "someTraceId")
val sender = mockk<MessageSender<OrchestratorMessage>>()
every { sender.send(any()) } just runs

val notifier = FailedJobNotifier(sender)
notifier.sendLostScheduleNotification(ortRun)

val slot = slot<Message<OrchestratorMessage>>()
verify {
sender.send(capture(slot))
}

with(slot.captured) {
header.ortRunId shouldBe ortRun.runId
header.traceId shouldBe ortRun.traceId
payload shouldBe LostSchedule(ortRun.runId)
}
}
}
})

0 comments on commit b63d6d9

Please sign in to comment.