Search in sources :

Example 1 with FlowStartNode

use of org.jenkinsci.plugins.workflow.graph.FlowStartNode in project workflow-cps-plugin by jenkinsci.

the class CpsFlowExecution method start.

@Override
public void start() throws IOException {
    final CpsScript s = parseScript();
    scriptClass = s.getClass();
    s.$initialize();
    final FlowHead h = new FlowHead(this);
    synchronized (this) {
        heads.put(h.getId(), h);
    }
    h.newStartNode(new FlowStartNode(this, iotaStr()));
    final CpsThreadGroup g = new CpsThreadGroup(this);
    g.register(s);
    final SettableFuture<CpsThreadGroup> f = SettableFuture.create();
    programPromise = f;
    // Ensures we've saves the WorkFlowRun at least once with initial state
    saveOwner();
    g.runner.submit(new Runnable() {

        @Override
        public void run() {
            CpsThread t = g.addThread(new Continuable(s, createInitialEnv()), h, null);
            t.resume(new Outcome(null, null));
            f.set(g);
        }

        /**
         * Environment to start executing the script in.
         * During sandbox execution, we need to call sandbox interceptor while executing asynchronous code.
         */
        private Env createInitialEnv() {
            return Envs.empty(isSandbox() ? new SandboxInvoker() : new DefaultInvoker());
        }
    });
}
Also used : FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) DefaultInvoker(com.cloudbees.groovy.cps.sandbox.DefaultInvoker) Env(com.cloudbees.groovy.cps.Env) SandboxInvoker(com.cloudbees.groovy.cps.sandbox.SandboxInvoker) Outcome(com.cloudbees.groovy.cps.Outcome) Continuable(com.cloudbees.groovy.cps.Continuable)

Example 2 with FlowStartNode

use of org.jenkinsci.plugins.workflow.graph.FlowStartNode in project workflow-cps-plugin by jenkinsci.

the class CpsFlowExecution method rebuildEmptyGraph.

/**
 * Handle failures where we can't load heads.
 */
private void rebuildEmptyGraph() {
    synchronized (this) {
        // something went catastrophically wrong and there's no live head. fake one
        if (this.startNodes == null) {
            this.startNodes = new Stack<BlockStartNode>();
        }
        this.heads.clear();
        this.startNodes.clear();
        FlowHead head = new FlowHead(this);
        heads.put(head.getId(), head);
        try {
            FlowStartNode start = new FlowStartNode(this, iotaStr());
            startNodes.push(start);
            head.newStartNode(start);
        } catch (IOException e) {
            LOGGER.log(Level.WARNING, "Failed to persist", e);
        }
        persistedClean = false;
        startNodesSerial = null;
        headsSerial = null;
    }
}
Also used : FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) BlockStartNode(org.jenkinsci.plugins.workflow.graph.BlockStartNode) IOException(java.io.IOException)

Example 3 with FlowStartNode

use of org.jenkinsci.plugins.workflow.graph.FlowStartNode in project workflow-cps-plugin by jenkinsci.

the class CpsFlowExecution method loadProgramFailed.

/**
 * Used by {@link #loadProgramAsync(File)} to propagate a failure to load the persisted execution state.
 * <p>
 * Let the workflow interrupt by throwing an exception that indicates how it failed.
 * @param promise same as {@link #programPromise} but more strongly typed
 */
private void loadProgramFailed(final Throwable problem, SettableFuture<CpsThreadGroup> promise) {
    FlowHead head;
    synchronized (this) {
        if (heads == null || heads.isEmpty()) {
            head = null;
        } else {
            head = getFirstHead();
        }
    }
    if (head == null) {
        // something went catastrophically wrong and there's no live head. fake one
        head = new FlowHead(this);
        try {
            head.newStartNode(new FlowStartNode(this, iotaStr()));
        } catch (IOException e) {
            LOGGER.log(Level.FINE, "Failed to persist", e);
        }
    }
    CpsThreadGroup g = new CpsThreadGroup(this);
    final FlowHead head_ = head;
    promise.set(g);
    runInCpsVmThread(new FutureCallback<CpsThreadGroup>() {

        @Override
        public void onSuccess(CpsThreadGroup g) {
            CpsThread t = g.addThread(new Continuable(new ThrowBlock(new ConstantBlock(problem instanceof AbortException ? problem : new IOException("Failed to load build state", problem)))), head_, null);
            t.resume(new Outcome(null, null));
        }

        @Override
        public void onFailure(Throwable t) {
            LOGGER.log(Level.WARNING, "Failed to set program failure on " + owner, t);
            croak(t);
        }
    });
}
Also used : FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) ThrowBlock(com.cloudbees.groovy.cps.impl.ThrowBlock) IOException(java.io.IOException) ConstantBlock(com.cloudbees.groovy.cps.impl.ConstantBlock) Outcome(com.cloudbees.groovy.cps.Outcome) Continuable(com.cloudbees.groovy.cps.Continuable) AbortException(hudson.AbortException)

Aggregations

FlowStartNode (org.jenkinsci.plugins.workflow.graph.FlowStartNode)3 Continuable (com.cloudbees.groovy.cps.Continuable)2 Outcome (com.cloudbees.groovy.cps.Outcome)2 IOException (java.io.IOException)2 Env (com.cloudbees.groovy.cps.Env)1 ConstantBlock (com.cloudbees.groovy.cps.impl.ConstantBlock)1 ThrowBlock (com.cloudbees.groovy.cps.impl.ThrowBlock)1 DefaultInvoker (com.cloudbees.groovy.cps.sandbox.DefaultInvoker)1 SandboxInvoker (com.cloudbees.groovy.cps.sandbox.SandboxInvoker)1 AbortException (hudson.AbortException)1 BlockStartNode (org.jenkinsci.plugins.workflow.graph.BlockStartNode)1