Search in sources :

Example 1 with BlockableResume

use of org.jenkinsci.plugins.workflow.flow.BlockableResume in project workflow-job-plugin by jenkinsci.

the class WorkflowRun method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    if (completed != null) {
        throw new IllegalStateException("double onLoad of " + this);
    }
    FlowExecution fetchedExecution = execution;
    if (fetchedExecution != null) {
        try {
            if (getParent().isResumeBlocked() && execution instanceof BlockableResume) {
                ((BlockableResume) execution).setResumeBlocked(true);
            }
            fetchedExecution.onLoad(new Owner(this));
        } catch (Exception x) {
            LOGGER.log(Level.WARNING, null, x);
            // probably too broken to use
            execution = null;
        }
    }
    fetchedExecution = execution;
    if (fetchedExecution != null) {
        fetchedExecution.addListener(new GraphL());
        executionPromise.set(fetchedExecution);
        if (!fetchedExecution.isComplete()) {
            // we've been restarted while we were running. let's get the execution going again.
            FlowExecutionListener.fireResumed(fetchedExecution);
            try {
                OutputStream logger = new FileOutputStream(getLogFile(), true);
                listener = new StreamBuildListener(logger, Charset.defaultCharset());
                listener.getLogger().println("Resuming build at " + new Date() + " after Jenkins restart");
            } catch (IOException x) {
                LOGGER.log(Level.WARNING, null, x);
                listener = new StreamBuildListener(new NullStream());
            }
            completed = new AtomicBoolean();
            Timer.get().submit(new // JENKINS-31614
            Runnable() {

                @Override
                public void run() {
                    Queue.getInstance().schedule(new AfterRestartTask(WorkflowRun.this), 0);
                }
            });
        }
    }
    // only for diagnostics
    checkouts(null);
    synchronized (LOADING_RUNS) {
        // or could just make the value type be WeakReference<WorkflowRun>
        LOADING_RUNS.remove(key());
        LOADING_RUNS.notifyAll();
    }
}
Also used : FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) NullStream(hudson.util.NullStream) LineTransformationOutputStream(hudson.console.LineTransformationOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) StreamBuildListener(hudson.model.StreamBuildListener) AbortException(hudson.AbortException) IOException(java.io.IOException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) Date(java.util.Date) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) FileOutputStream(java.io.FileOutputStream) BlockableResume(org.jenkinsci.plugins.workflow.flow.BlockableResume)

Example 2 with BlockableResume

use of org.jenkinsci.plugins.workflow.flow.BlockableResume in project workflow-job-plugin by jenkinsci.

the class WorkflowRun method run.

/**
 * Actually executes the workflow.
 */
@Override
public void run() {
    if (!firstTime) {
        throw sleep();
    }
    try {
        onStartBuilding();
        OutputStream logger = new FileOutputStream(getLogFile());
        listener = new StreamBuildListener(logger, Charset.defaultCharset());
        listener.started(getCauses());
        Authentication auth = Jenkins.getAuthentication();
        if (!auth.equals(ACL.SYSTEM)) {
            String name = auth.getName();
            if (!auth.equals(Jenkins.ANONYMOUS)) {
                name = ModelHyperlinkNote.encodeTo(User.get(name));
            }
            listener.getLogger().println(hudson.model.Messages.Run_running_as_(name));
        }
        RunListener.fireStarted(this, listener);
        updateSymlinks(listener);
        FlowDefinition definition = getParent().getDefinition();
        if (definition == null) {
            throw new AbortException("No flow definition, cannot run");
        }
        Owner owner = new Owner(this);
        FlowExecution newExecution = definition.create(owner, listener, getAllActions());
        boolean loggedHintOverride = false;
        if (getParent().isResumeBlocked()) {
            if (newExecution instanceof BlockableResume) {
                ((BlockableResume) newExecution).setResumeBlocked(true);
                listener.getLogger().println("Resume disabled by user, switching to high-performance, low-durability mode.");
                loggedHintOverride = true;
            }
        }
        if (!loggedHintOverride) {
            // Avoid double-logging
            listener.getLogger().println("Running in Durability level: " + DurabilityHintProvider.suggestedFor(this.project));
        }
        FlowExecutionList.get().register(owner);
        newExecution.addListener(new GraphL());
        completed = new AtomicBoolean();
        logsToCopy = new ConcurrentSkipListMap<>();
        execution = newExecution;
        newExecution.start();
        executionPromise.set(newExecution);
        FlowExecutionListener.fireRunning(execution);
    } catch (Throwable x) {
        // ensures isInProgress returns false
        execution = null;
        finish(Result.FAILURE, x);
        try {
            executionPromise.setException(x);
        } catch (Error e) {
            if (e != x) {
                // cf. CpsThread.runNextChunk
                throw e;
            }
        }
        return;
    }
    throw sleep();
}
Also used : FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) LineTransformationOutputStream(hudson.console.LineTransformationOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) StreamBuildListener(hudson.model.StreamBuildListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Authentication(org.acegisecurity.Authentication) FileOutputStream(java.io.FileOutputStream) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) FlowDefinition(org.jenkinsci.plugins.workflow.flow.FlowDefinition) BlockableResume(org.jenkinsci.plugins.workflow.flow.BlockableResume) AbortException(hudson.AbortException)

Aggregations

AbortException (hudson.AbortException)2 LineTransformationOutputStream (hudson.console.LineTransformationOutputStream)2 StreamBuildListener (hudson.model.StreamBuildListener)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 BlockableResume (org.jenkinsci.plugins.workflow.flow.BlockableResume)2 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)2 FlowExecutionOwner (org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner)2 NullStream (hudson.util.NullStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Authentication (org.acegisecurity.Authentication)1 FlowDefinition (org.jenkinsci.plugins.workflow.flow.FlowDefinition)1 FlowInterruptedException (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException)1