use of hudson.model.Executor in project vsphere-cloud-plugin by jenkinsci.
the class vSphereCloudSlave method StartLimitedTestRun.
public boolean StartLimitedTestRun(Run r, TaskListener listener) {
boolean ret = false;
boolean DoUpdates = false;
if (LimitedTestRunCount > 0) {
DoUpdates = true;
if (NumberOfLimitedTestRuns < LimitedTestRunCount) {
ret = true;
}
} else {
ret = true;
}
Executor executor = r.getExecutor();
if (executor != null && DoUpdates) {
if (ret) {
NumberOfLimitedTestRuns++;
vSphereCloud.Log(this, listener, "Starting limited count build: %d of %d", NumberOfLimitedTestRuns, LimitedTestRunCount);
Computer slave = executor.getOwner();
RunToSlaveMapper.put(r, slave);
} else {
vSphereCloud.Log(this, listener, "Terminating build due to limited build count: %d of %d", NumberOfLimitedTestRuns, LimitedTestRunCount);
executor.interrupt(Result.ABORTED);
}
}
return ret;
}
use of hudson.model.Executor in project vsphere-cloud-plugin by jenkinsci.
the class vSphereCloudRunListener method onFinalized.
@Override
public void onFinalized(Run r) {
super.onFinalized(r);
if (LimitedRuns.contains(r)) {
LimitedRuns.remove(r);
Executor executor = r.getExecutor();
if (executor != null) {
Node node = executor.getOwner().getNode();
if (node instanceof vSphereCloudSlave) {
vSphereCloudSlave s = (vSphereCloudSlave) node;
s.EndLimitedTestRun(r);
}
}
}
}
use of hudson.model.Executor in project vsphere-cloud-plugin by jenkinsci.
the class vSphereCloudRunListener method onStarted.
@Override
public void onStarted(Run r, TaskListener listener) {
super.onStarted(r, listener);
if (r != null) {
Executor exec = r.getExecutor();
if (exec != null) {
Computer owner = exec.getOwner();
Node node = owner.getNode();
if ((node != null) && (node instanceof vSphereCloudSlave)) {
LimitedRuns.add(r);
vSphereCloudSlave s = (vSphereCloudSlave) node;
s.StartLimitedTestRun(r, listener);
}
}
}
}
use of hudson.model.Executor in project workflow-job-plugin by jenkinsci.
the class WorkflowRun method sleep.
private AsynchronousExecution sleep() {
final AsynchronousExecution asynchronousExecution = new AsynchronousExecution() {
@Override
public void interrupt(boolean forShutdown) {
if (forShutdown) {
return;
}
Timer.get().submit(new Runnable() {
@Override
public void run() {
if (execution == null) {
return;
}
Executor executor = getExecutor();
if (executor == null) {
LOGGER.log(Level.WARNING, "Lost executor for {0}", WorkflowRun.this);
return;
}
try {
Collection<CauseOfInterruption> causes = executor.getCausesOfInterruption();
execution.interrupt(executor.abortResult(), causes.toArray(new CauseOfInterruption[causes.size()]));
} catch (Exception x) {
LOGGER.log(Level.WARNING, null, x);
}
executor.recordCauseOfInterruption(WorkflowRun.this, listener);
printLater(StopState.TERM, "Click here to forcibly terminate running steps");
}
});
}
@Override
public boolean blocksRestart() {
return execution != null && execution.blocksRestart();
}
@Override
public boolean displayCell() {
return blocksRestart();
}
};
final AtomicReference<ScheduledFuture<?>> copyLogsTask = new AtomicReference<>();
copyLogsTask.set(copyLogsExecutorService().scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
synchronized (completed) {
if (completed.get()) {
asynchronousExecution.completed(null);
copyLogsTask.get().cancel(false);
return;
}
Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null || jenkins.isTerminating()) {
LOGGER.log(Level.FINE, "shutting down, breaking waitForCompletion on {0}", this);
// Stop writing content, in case a new set of objects gets loaded after in-VM restart and starts writing to the same file:
listener.closeQuietly();
listener = new StreamBuildListener(new NullStream());
return;
}
try (WithThreadName naming = new WithThreadName(" (" + WorkflowRun.this + ")")) {
copyLogs();
}
}
}
}, 1, 1, TimeUnit.SECONDS));
return asynchronousExecution;
}
use of hudson.model.Executor in project workflow-job-plugin by jenkinsci.
the class WorkflowRunRestartTest method hardKill.
@Issue("JENKINS-25550")
@Test
public void hardKill() throws Exception {
story.then(r -> {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("def seq = 0; retry (99) {zombie id: ++seq}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
r.waitForMessage("[1] undead", b);
Executor ex = b.getExecutor();
assertNotNull(ex);
ex.interrupt();
r.waitForMessage("[1] bwahaha FlowInterruptedException #1", b);
ex.interrupt();
r.waitForMessage("[1] bwahaha FlowInterruptedException #2", b);
b.doTerm();
r.waitForMessage("[2] undead", b);
ex.interrupt();
r.waitForMessage("[2] bwahaha FlowInterruptedException #1", b);
b.doKill();
r.waitForMessage("Hard kill!", b);
r.waitForCompletion(b);
r.assertBuildStatus(Result.ABORTED, b);
});
story.then(r -> {
WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(1);
assertFalse(b.isBuilding());
});
}
Aggregations