-
Notifications
You must be signed in to change notification settings - Fork 18
Start untangling orchestrator #1739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mnonnenmacher
wants to merge
10
commits into
main
Choose a base branch
from
untangle-orchestrator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
18acb53
chore(orchestrator): Fix a function name
mnonnenmacher f5b0f6d
chore(orchestrator): Remove unnecessary whitespace
mnonnenmacher be8a3cb
chore(orchestrator): Remove an unnecessary suppression
mnonnenmacher 3b2f14f
refactor(orchestrator): Inline the `scheduleNextJobs` function
mnonnenmacher 391a733
refactor(orchestrator): Rename `getCurrentOrtRun` to `getOrtRun`
mnonnenmacher 9400db2
refactor(orchestrator): Simplify defining job dependencies
mnonnenmacher 8bb979a
refactor(orchestrator): Extract scheduling logic
mnonnenmacher 5c10474
fix(orchestrator): Make the reporter depend on the analyzer
mnonnenmacher f3b26ae
refactor(orchestrator): Take `OrtRunInfo` into use
mnonnenmacher 3af763d
chore(orchestrator): Remove an unnecessary helper function
mnonnenmacher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Copyright (C) 2024 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>) | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * License-Filename: LICENSE | ||
| */ | ||
|
|
||
| package org.eclipse.apoapsis.ortserver.orchestrator | ||
|
|
||
| import org.eclipse.apoapsis.ortserver.model.JobStatus | ||
|
|
||
| /** A class to store the required information to determine which jobs can be run. */ | ||
| internal class OrtRunInfo( | ||
| /** The ORT run ID. */ | ||
| val id: Long, | ||
|
|
||
| /** Whether the config worker has failed. */ | ||
| val configWorkerFailed: Boolean, | ||
|
|
||
| /** The jobs configured to run in this ORT run. */ | ||
| val configuredJobs: Set<WorkerScheduleInfo>, | ||
|
|
||
| /** Status information for already created jobs. */ | ||
| val jobInfos: Map<WorkerScheduleInfo, WorkerJobInfo> | ||
| ) { | ||
| /** Get the next jobs that can be run. */ | ||
| fun getNextJobs(): Set<WorkerScheduleInfo> = WorkerScheduleInfo.entries.filterTo(mutableSetOf()) { canRun(it) } | ||
|
|
||
| /** Return true if the job can be run. */ | ||
| private fun canRun(info: WorkerScheduleInfo): Boolean = | ||
| isConfigured(info) && | ||
| !wasScheduled(info) && | ||
| canRunIfPreviousJobFailed(info) && | ||
| info.dependsOn.all { isCompleted(it) } && | ||
| info.runsAfterTransitively.none { isPending(it) } | ||
|
|
||
| /** Return true if no previous job has failed or if the job is configured to run after a failure. */ | ||
| private fun canRunIfPreviousJobFailed(info: WorkerScheduleInfo): Boolean = info.runAfterFailure || !isFailed() | ||
|
|
||
| /** Return true if the job has been completed. */ | ||
| private fun isCompleted(info: WorkerScheduleInfo): Boolean = jobInfos[info]?.status?.final == true | ||
|
|
||
| /** Return true if the job is configured to run. */ | ||
| private fun isConfigured(info: WorkerScheduleInfo): Boolean = info in configuredJobs | ||
|
|
||
| /** Return true if any job has failed. */ | ||
| private fun isFailed(): Boolean = configWorkerFailed || jobInfos.any { it.value.status == JobStatus.FAILED } | ||
|
|
||
| /** Return true if the job is pending execution. */ | ||
| private fun isPending(info: WorkerScheduleInfo): Boolean = | ||
| isConfigured(info) && | ||
| !isCompleted(info) && | ||
| canRunIfPreviousJobFailed(info) && | ||
| info.dependsOn.all { wasScheduled(it) || isPending(it) } | ||
|
|
||
| /** Return true if the job has been scheduled. */ | ||
| private fun wasScheduled(info: WorkerScheduleInfo): Boolean = jobInfos.containsKey(info) | ||
| } | ||
|
|
||
| /** A class to store information of a worker job required by [OrtRunInfo]. */ | ||
| internal class WorkerJobInfo( | ||
| /** The job ID. */ | ||
| val id: Long, | ||
|
|
||
| /** The job status. */ | ||
| val status: JobStatus | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I like the idea to extract the scheduling logic to a dedicated class, I have some problems with the current implementation:
OrtRunInfois meaningless in this context and rather reminds of a data model class.WorkerScheduleContextis unclear.Orchestratornow creates aWorkerScheduleContext, and with the help of this context, anOrtRunInfo. This is because the latter has its own state derived from the context (this is not really untangling). It would be better ifOrtRunInfowas stateless and only implemented the scheduling strategy. ThegetNextJobs()function could be passed aWorkerScheduleContextinfo object and obtain all required information from there.