From 27cb0e90b6369b16b19cb6ffbe7e38675bcb2d4e Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 9 Sep 2010 22:29:37 +0000 Subject: [PATCH] added a test JobProperty implementation that makes the job heavier git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34619 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/model/AbstractProject.java | 2 +- .../main/java/hudson/model/JobProperty.java | 2 +- .../hudson/model/queue/WideJobProperty.java | 102 ++++++++++++++++++ .../model/queue/WideJobProperty/config.jelly | 30 ++++++ readme.txt | 3 + 5 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/hudson/model/queue/WideJobProperty.java create mode 100644 core/src/main/resources/hudson/model/queue/WideJobProperty/config.jelly create mode 100644 readme.txt diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 72eb72b6aa..a5a23010f9 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1014,7 +1014,7 @@ public abstract class AbstractProject

,R extends A for (SubTaskContributor euc : SubTaskContributor.all()) r.addAll(euc.forProject(this)); for (JobProperty p : properties) - r.addAll(p.getMemberExecutionUnits()); + r.addAll(p.getSubTasks()); return r; } diff --git a/core/src/main/java/hudson/model/JobProperty.java b/core/src/main/java/hudson/model/JobProperty.java index 4f22e09052..05ff01f3d9 100644 --- a/core/src/main/java/hudson/model/JobProperty.java +++ b/core/src/main/java/hudson/model/JobProperty.java @@ -170,7 +170,7 @@ public abstract class JobProperty> implements Describable getMemberExecutionUnits() { + public Collection getSubTasks() { return Collections.emptyList(); } } diff --git a/core/src/main/java/hudson/model/queue/WideJobProperty.java b/core/src/main/java/hudson/model/queue/WideJobProperty.java new file mode 100644 index 0000000000..58e0e59774 --- /dev/null +++ b/core/src/main/java/hudson/model/queue/WideJobProperty.java @@ -0,0 +1,102 @@ +/* + * The MIT License + * + * Copyright (c) 2010, InfraDNA, Inc. + * + * 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 hudson.model.queue; + +import hudson.Extension; +import hudson.model.AbstractProject; +import hudson.model.JobProperty; +import hudson.model.JobPropertyDescriptor; +import hudson.model.Queue.Executable; +import hudson.model.Queue.Task; +import org.kohsuke.stapler.DataBoundConstructor; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * + * + * @author Kohsuke Kawaguchi + */ +public class WideJobProperty extends JobProperty> { + public final int weight; + + @DataBoundConstructor + public WideJobProperty(int weight) { + this.weight = weight; + } + + @Override + public List getSubTasks() { + List r = new ArrayList(); + for (int i=1; i< weight; i++) + r.add(new AbstractSubTask() { + private final AbstractSubTask outerThis = this; + public Executable createExecutable() throws IOException { + return new Executable() { + public SubTask getParent() { + return outerThis; + } + + public void run() { + // nothing. we just waste time + } + }; + } + + @Override + public Object getSameNodeConstraint() { + // must occupy the same node as the project itself + return getProject(); + } + + @Override + public long getEstimatedDuration() { + return getProject().getEstimatedDuration(); + } + + public Task getOwnerTask() { + return getProject(); + } + + public String getDisplayName() { + return "place holder for "+getProject().getDisplayName(); + } + + private AbstractProject getProject() { + return WideJobProperty.this.owner; + } + }); + return r; + } + + @Extension + public static class DescriptorImpl extends JobPropertyDescriptor { + @Override + public String getDisplayName() { + return "This project occupies multiple executors"; + } + } +} diff --git a/core/src/main/resources/hudson/model/queue/WideJobProperty/config.jelly b/core/src/main/resources/hudson/model/queue/WideJobProperty/config.jelly new file mode 100644 index 0000000000..59ec549999 --- /dev/null +++ b/core/src/main/resources/hudson/model/queue/WideJobProperty/config.jelly @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000000..99b6b860c2 --- /dev/null +++ b/readme.txt @@ -0,0 +1,3 @@ +TODO: + If a subtask is interrupted, all the executors should be aborted. + executor rendering \ No newline at end of file -- GitLab