提交 5f3fc707 编写于 作者: K kohsuke

checkpoint. now it at least passes all the compilation.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34608 71c3de6d-444a-0410-be80-ed276b4c234a
上级 cc38c656
......@@ -29,6 +29,7 @@ import hudson.Util;
import hudson.cli.declarative.CLIMethod;
import hudson.console.AnnotatedLargeText;
import hudson.model.Descriptor.FormException;
import hudson.model.queue.WorkUnit;
import hudson.node_monitors.NodeMonitor;
import hudson.remoting.Channel;
import hudson.remoting.VirtualChannel;
......@@ -814,7 +815,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
/**
* Starts executing a fly-weight task.
*/
/*package*/ final void startFlyWeightTask(Queue.BuildableItem p) {
/*package*/ final void startFlyWeightTask(WorkUnit p) {
OneOffExecutor e = new OneOffExecutor(this, p);
e.start();
oneOffExecutors.add(e);
......
......@@ -124,7 +124,7 @@ public class Executor extends Thread implements ModelObject {
workUnit.context.synchronizeStart();
if (executable instanceof Actionable) {
for (Action action: workUnit.actions) {
for (Action action: workUnit.context.actions) {
((Actionable) executable).addAction(action);
}
}
......@@ -139,7 +139,11 @@ public class Executor extends Thread implements ModelObject {
} finally {
setName(threadName);
finishTime = System.currentTimeMillis();
workUnit.context.synchronizeEnd(executable,problems,finishTime - startTime);
try {
workUnit.context.synchronizeEnd(executable,problems,finishTime - startTime);
} catch (InterruptedException e) {
continue;
}
}
}
} catch(RuntimeException e) {
......
......@@ -34,24 +34,24 @@ import hudson.model.queue.WorkUnit;
* @see FlyweightTask
*/
public class OneOffExecutor extends Executor {
private WorkUnit item;
private WorkUnit work;
public OneOffExecutor(Computer owner, Queue.Item item) {
public OneOffExecutor(Computer owner, WorkUnit work) {
super(owner,-1);
this.item = new WorkUnit(item,item.task);
this.work = work;
}
@Override
protected boolean shouldRun() {
// TODO: consulting super.shouldRun() here means we'll lose the item if it gets scheduled
// TODO: consulting super.shouldRun() here means we'll lose the work if it gets scheduled
// when super.shouldRun() returns false.
return super.shouldRun() && item!=null;
return super.shouldRun() && work !=null;
}
@Override
protected WorkUnit grabJob() throws InterruptedException {
WorkUnit r = item;
item = null;
WorkUnit r = work;
work = null;
return r;
}
......
......@@ -35,10 +35,10 @@ import static hudson.util.Iterators.reverse;
import hudson.cli.declarative.CLIMethod;
import hudson.cli.declarative.CLIResolver;
import hudson.model.queue.AbstractQueueTask;
import hudson.model.queue.FutureImpl;
import hudson.model.queue.QueueSorter;
import hudson.model.queue.QueueTaskDispatcher;
import hudson.model.queue.WorkUnit;
import hudson.remoting.AsyncFutureImpl;
import hudson.model.Node.Mode;
import hudson.model.listeners.SaveableListener;
import hudson.model.queue.CauseOfBlockage;
......@@ -47,6 +47,7 @@ import hudson.model.queue.CauseOfBlockage.BecauseLabelIsBusy;
import hudson.model.queue.CauseOfBlockage.BecauseNodeIsOffline;
import hudson.model.queue.CauseOfBlockage.BecauseLabelIsOffline;
import hudson.model.queue.CauseOfBlockage.BecauseNodeIsBusy;
import hudson.model.queue.WorkUnitContext;
import hudson.triggers.SafeTimerTask;
import hudson.triggers.Trigger;
import hudson.util.OneShotEvent;
......@@ -778,9 +779,10 @@ public class Queue extends ResourceController implements Saveable {
if (offer.item != null) {
// if so, just build it
LOGGER.fine("Pop returning " + offer.item + " for " + exec.getName());
offer.item.future.startExecuting(exec);
pendings.remove(offer.item);
return new WorkUnit(offer.item, offer.item.task);
WorkUnitContext wuc = new WorkUnitContext(offer.item);
return wuc.createWorkUnit(offer.item.task);
}
// otherwise run a queue maintenance
}
......@@ -966,7 +968,7 @@ public class Queue extends ResourceController implements Saveable {
Computer c = n.toComputer();
if (c==null || c.isOffline()) continue;
if (lbl!=null && !lbl.contains(n)) continue;
c.startFlyWeightTask(p);
c.startFlyWeightTask(new WorkUnitContext(p).createWorkUnit(p.task));
return;
}
// if the execution get here, it means we couldn't schedule it anywhere.
......@@ -1157,34 +1159,7 @@ public class Queue extends ResourceController implements Saveable {
@Override String toString();
}
/*package*/ static final class FutureImpl extends AsyncFutureImpl<Executable> {
private final Task task;
/**
* If the computation has started, set to {@link Executor} that's running the build.
*/
private volatile Executor executor;
private FutureImpl(Task task) {
this.task = task;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
Queue q = Hudson.getInstance().getQueue();
synchronized (q) {
if(executor!=null) {
if(mayInterruptIfRunning)
executor.interrupt();
return mayInterruptIfRunning;
}
return q.cancel(task);
}
}
private void startExecuting(Executor executor) {
this.executor = executor;
}
}
/*package*/
/**
* Item in a queue.
......@@ -1203,7 +1178,7 @@ public class Queue extends ResourceController implements Saveable {
@Exported
public final Task task;
/*package almost final*/ transient FutureImpl future;
private /*almost final*/ transient FutureImpl future;
/**
* Build is blocked because another build is in progress,
......
/*
* 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.model.Executor;
import hudson.model.Hudson;
import hudson.model.Queue;
import hudson.model.Queue.Executable;
import hudson.model.Queue.Task;
import hudson.remoting.AsyncFutureImpl;
import java.util.HashSet;
import java.util.Set;
/**
* Created when {@link Queue.Item} is created so that the caller can track the progress of the task.
*
* @author Kohsuke Kawaguchi
*/
public final class FutureImpl extends AsyncFutureImpl<Executable> {
private final Task task;
/**
* If the computation has started, set to {@link Executor}s that are running the build.
*/
private final Set<Executor> executors = new HashSet<Executor>();
public FutureImpl(Task task) {
this.task = task;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
Queue q = Hudson.getInstance().getQueue();
synchronized (q) {
synchronized (this) {
if(!executors.isEmpty()) {
if(mayInterruptIfRunning)
for (Executor e : executors)
e.interrupt();
return mayInterruptIfRunning;
}
return q.cancel(task);
}
}
}
synchronized void addExecutor(Executor executor) {
this.executors.add(executor);
}
}
/*
* 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;
/**
......
/*
* 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.model.Action;
import hudson.model.Executor;
import hudson.model.Queue;
import hudson.model.Queue.ExecutionUnit;
import hudson.model.Queue.FutureImpl;
import hudson.model.Queue.Item;
import hudson.model.Queue.Task;
import java.util.List;
/**
* Represents a unit of hand-over to {@link Executor} from {@link Queue}.
*
......@@ -22,26 +40,12 @@ public final class WorkUnit {
public final ExecutionUnit work;
/**
* Which task does this work belong to?
* Shared context among {@link WorkUnit}s.
*/
public final Task task;
/**
* Associated parameters to the build.
*/
public final List<Action> actions;
/**
* Once the execution is complete, update this future object with the outcome.
*/
public final FutureImpl future;
public final WorkUnitContext context;
public WorkUnit(Item item, ExecutionUnit work) {
this.task = item.task;
this.future = item.future; // TODO: this is incorrect
this.actions = item.getActions();
WorkUnit(WorkUnitContext context, ExecutionUnit work) {
this.context = context;
this.work = work;
}
......@@ -50,6 +54,6 @@ public final class WorkUnit {
* represented by {@link Task} itself.
*/
public boolean isMainWork() {
return task==work;
return context.task==work;
}
}
/*
* 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.model.Action;
import hudson.model.Executor;
import hudson.model.Queue;
import hudson.model.Queue.ExecutionUnit;
import hudson.model.Queue.Item;
import hudson.model.Queue.Task;
import java.util.List;
/**
* Holds the information shared between {@link WorkUnit}s created from the same {@link Task}.
*
......@@ -11,12 +39,26 @@ import hudson.model.Queue.Task;
*/
public final class WorkUnitContext {
private final int workUnitSize;
public final Task task;
/**
* Once the execution is complete, update this future object with the outcome.
*/
public final FutureImpl future;
/**
* Associated parameters to the build.
*/
public final List<Action> actions;
private final Latch startLatch, endLatch;
public WorkUnitContext(Task _task) {
this.task = _task;
public WorkUnitContext(Queue.Item item) {
this.task = item.task;
this.future = (FutureImpl)item.getFuture();
this.actions = item.getActions();
// +1 for the main task
workUnitSize = task.getMemberExecutionUnits().size() + 1;
startLatch = new Latch(workUnitSize) {
......@@ -35,7 +77,16 @@ public final class WorkUnitContext {
}
/**
* {@link Executor}s call this method to synchronize on the start of the task
* Called by the executor that executes a member {@link ExecutionUnit} that belongs to this task
* to create its {@link WorkUnit}.
*/
public WorkUnit createWorkUnit(ExecutionUnit execUnit) {
future.addExecutor(Executor.currentExecutor());
return new WorkUnit(this,execUnit);
}
/**
* All the {@link Executor}s that jointly execute a {@link Task} call this method to synchronize on the start.
*/
public synchronized void synchronizeStart() throws InterruptedException {
startLatch.synchronize();
......@@ -46,12 +97,13 @@ public final class WorkUnitContext {
// the main thread will send a notification
Executor e = Executor.currentExecutor();
if (e.getCurrentWorkUnit().isMainWork()) {
WorkUnit wu = e.getCurrentWorkUnit();
if (wu.isMainWork()) {
if (problems == null) {
queueItem.future.set(executable);
future.set(executable);
e.getOwner().taskCompleted(e, task, duration);
} else {
queueItem.future.set(problems);
future.set(problems);
e.getOwner().taskCompletedWithProblems(e, task, duration, problems);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册