Search in sources :

Example 6 with Executor

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;
}
Also used : Executor(hudson.model.Executor) Computer(hudson.model.Computer)

Example 7 with Executor

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);
            }
        }
    }
}
Also used : Executor(hudson.model.Executor) Node(hudson.model.Node)

Example 8 with Executor

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);
            }
        }
    }
}
Also used : Executor(hudson.model.Executor) Node(hudson.model.Node) Computer(hudson.model.Computer)

Example 9 with Executor

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;
}
Also used : AsynchronousExecution(jenkins.model.queue.AsynchronousExecution) NullStream(hudson.util.NullStream) WithThreadName(org.jenkinsci.plugins.workflow.support.concurrent.WithThreadName) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamBuildListener(hudson.model.StreamBuildListener) AbortException(hudson.AbortException) IOException(java.io.IOException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) ScheduledFuture(java.util.concurrent.ScheduledFuture) Jenkins(jenkins.model.Jenkins) Executor(hudson.model.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Collection(java.util.Collection)

Example 10 with Executor

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());
    });
}
Also used : Executor(hudson.model.Executor) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

Executor (hudson.model.Executor)18 Computer (hudson.model.Computer)8 Node (hudson.model.Node)5 Test (org.junit.Test)5 AbortException (hudson.AbortException)2 FilePath (hudson.FilePath)2 Run (hudson.model.Run)2 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)2 Issue (org.jvnet.hudson.test.Issue)2 AbstractBuild (hudson.model.AbstractBuild)1 EnvironmentSpecific (hudson.model.EnvironmentSpecific)1 Queue (hudson.model.Queue)1 StreamBuildListener (hudson.model.StreamBuildListener)1 ExecutorChunk (hudson.model.queue.MappingWorksheet.ExecutorChunk)1 Mapping (hudson.model.queue.MappingWorksheet.Mapping)1 WorkChunk (hudson.model.queue.MappingWorksheet.WorkChunk)1 Promotion (hudson.plugins.promoted_builds.Promotion)1 NodeSpecific (hudson.slaves.NodeSpecific)1