Skip to content
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

Introduce SubTask.getOwnerExecutable #7599

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/src/main/java/hudson/model/Queue.java
Original file line number Diff line number Diff line change
Expand Up @@ -2077,10 +2077,14 @@ public interface Executable extends Runnable {

/**
* An umbrella executable (such as a {@link Run}) of which this is one part.
* If {@link #getParent} has a distinct {@link SubTask#getOwnerTask},
* then it should be the case that {@code getParentExecutable().getParent() == getParent().getOwnerTask()}.
* Some invariants:
* <ul>
* <li>{@code getParent().getOwnerTask() == getParent() || getParentExecutable().getParent() == getParent().getOwnerTask()}
* <li>{@code getParent().getOwnerExecutable() == null || getParentExecutable() == getParent().getOwnerExecutable()}
* </ul>
* @return a <em>distinct</em> executable (never {@code this}, unlike the default of {@link SubTask#getOwnerTask}!); or null if this executable was already at top level
* @since 2.313, but implementations can already implement this with a lower core dependency.
* @see SubTask#getOwnerExecutable
*/
default @CheckForNull Executable getParentExecutable() {
return null;
Expand Down
34 changes: 22 additions & 12 deletions core/src/main/java/hudson/model/queue/SubTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@
import hudson.model.Executor;
import hudson.model.Label;
import hudson.model.Node;
import hudson.model.Queue.Executable;
import hudson.model.Queue.Task;
import hudson.model.Queue;
import hudson.model.ResourceActivity;
import java.io.IOException;

/**
* A component of {@link Task} that represents a computation carried out by a single {@link Executor}.
* A component of {@link Queue.Task} that represents a computation carried out by a single {@link Executor}.
*
* A {@link Task} consists of a number of {@link SubTask}.
* A {@link Queue.Task} consists of a number of {@link SubTask}.
*
* <p>
* Plugins are encouraged to extend from {@link AbstractSubTask}
Expand Down Expand Up @@ -79,23 +78,34 @@ default long getEstimatedDuration() {
}

/**
* Creates {@link Executable}, which performs the actual execution of the task.
* @return {@link Executable} to be launched or null if the executable cannot be
* Creates an object which performs the actual execution of the task.
* @return executable to be launched or null if the executable cannot be
* created (e.g. {@link AbstractProject} is disabled)
* @exception IOException {@link Executable} cannot be created
* @exception IOException executable cannot be created
*/
@CheckForNull Executable createExecutable() throws IOException;
@CheckForNull Queue.Executable createExecutable() throws IOException;

/**
* Gets the {@link Task} that this subtask belongs to.
* Gets the task that this subtask belongs to.
* @return by default, {@code this}
* @see #getOwnerExecutable
*/
default @NonNull Task getOwnerTask() {
return (Task) this;
default @NonNull Queue.Task getOwnerTask() {
return (Queue.Task) this;
}

/**
* If a subset of {@link SubTask}s of a {@link Task} needs to be collocated with other {@link SubTask}s,
* If this task is associated with an executable of {@link #getOwnerTask}, finds that.
* @return by default, {@code null}
* @see hudson.model.Queue.Executable#getParentExecutable
* @since TODO
*/
default @CheckForNull Queue.Executable getOwnerExecutable() {
return null;
}

/**
* If a subset of {@link SubTask}s of a {@link Queue.Task} needs to be collocated with other {@link SubTask}s,
* those {@link SubTask}s should return the equal object here. If null, the execution unit isn't under a
* colocation constraint.
* @return by default, null
Expand Down