提交 fac67c18 编写于 作者: K kohsuke

updated the job scheduling logic so that maven module build and moduleSet...

updated the job scheduling logic so that maven module build and moduleSet build won't collide with each other.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1984 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b43c32ec
......@@ -122,6 +122,18 @@ public final class MavenModule extends AbstractProject<MavenModule,MavenBuild> i
return new MavenBuild(this,dir);
}
@Override
protected boolean isBuildBlocked() {
if(super.isBuildBlocked())
return true;
// if the module set's new build is planned or in progress,
// don't start a new build. Otherwise on a busy maven project
// MavenModuleSet will never get a chance to run.
MavenModuleSet p = getParent();
return p.isBuilding() || p.isInQueue();
}
@Override
public boolean isFingerprintConfigured() {
return true;
......
......@@ -91,6 +91,19 @@ public class MavenModuleSet extends AbstractProject<MavenModuleSet,MavenModuleSe
return jobs;
}
@Override
protected boolean isBuildBlocked() {
if(super.isBuildBlocked())
return true;
// updating the workspace (=our build) cannot be done
// if someone else is still touching the workspace.
for (MavenModule m : modules.values()) {
if(m.isBuilding())
return true;
}
return false;
}
/**
* Gets the workspace of this job.
*/
......
......@@ -185,6 +185,14 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return Hudson.getInstance().getQueue().contains(this);
}
/**
* Returns true if a build of this project is in progress.
*/
public boolean isBuilding() {
R b = getLastBuild();
return b!=null && b.isBuilding();
}
public JDK getJDK() {
return Hudson.getInstance().getJDK(jdk);
}
......@@ -235,6 +243,18 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return b.getBuiltOn();
}
/**
* Returns true if this project's build execution should be blocked
* for temporary reasons. This method is used by {@link Queue}.
*
* <p>
* A project must be blocked if its own previous build is in progress,
* but derived classes can also check other conditions.
*/
protected boolean isBuildBlocked() {
return isBuilding();
}
public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException {
if(scm==null)
return true; // no SCM
......
......@@ -12,7 +12,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
......@@ -218,6 +217,9 @@ public class Queue {
*/
public AbstractProject pop() throws InterruptedException {
final Executor exec = Executor.currentExecutor();
// used in the finally block to check if we are returning from this method normally
// or abnormally via an exception
boolean successfulReturn = false;
try {
......@@ -239,6 +241,14 @@ public class Queue {
Iterator<AbstractProject> itr = buildables.iterator();
while(itr.hasNext()) {
AbstractProject p = itr.next();
// one last check to make sure this build is not blocked.
if(p.isBuildBlocked()) {
itr.remove();
blockedProjects.add(p);
continue;
}
JobOffer runner = choose(p);
if(runner==null)
// if we couldn't find the executor that fits,
......@@ -327,7 +337,7 @@ public class Queue {
return null;
}
// otherwise let's see if the last node that this project was built is available
// otherwise let's see if the last node where this project was built is available
// it has up-to-date workspace, so that's usually preferable.
// (but we can't use an exclusive node)
n = p.getLastBuiltOn();
......@@ -390,9 +400,8 @@ public class Queue {
private synchronized void maintain() {
Iterator<AbstractProject> itr = blockedProjects.iterator();
while(itr.hasNext()) {
AbstractProject<?,?> p = itr.next();
AbstractBuild lastBuild = p.getLastBuild();
if (lastBuild == null || !lastBuild.isBuilding()) {
AbstractProject p = itr.next();
if(!p.isBuildBlocked()) {
// ready to be executed
itr.remove();
buildables.add(p);
......@@ -405,16 +414,16 @@ public class Queue {
if(!top.timestamp.before(new GregorianCalendar()))
return; // finished moving all ready items from queue
AbstractBuild lastBuild = top.project.getLastBuild();
if(lastBuild==null || !lastBuild.isBuilding()) {
AbstractProject p = top.project;
if(!p.isBuildBlocked()) {
// ready to be executed immediately
queue.remove(top);
buildables.add(top.project);
buildables.add(p);
} else {
// this can't be built know because another build is in progress
// this can't be built now because another build is in progress
// set this project aside.
queue.remove(top);
blockedProjects.add(top.project);
blockedProjects.add(p);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册