Search in sources :

Example 1 with FlowExecutionOwner

use of org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner in project workflow-cps-plugin by jenkinsci.

the class EnvActionImpl method getEnvironment.

@Override
public EnvVars getEnvironment() throws IOException, InterruptedException {
    TaskListener listener;
    if (owner instanceof FlowExecutionOwner.Executable) {
        FlowExecutionOwner executionOwner = ((FlowExecutionOwner.Executable) owner).asFlowExecutionOwner();
        if (executionOwner != null) {
            listener = executionOwner.getListener();
        } else {
            listener = new LogTaskListener(LOGGER, Level.INFO);
        }
    } else {
        listener = new LogTaskListener(LOGGER, Level.INFO);
    }
    EnvVars e = owner.getEnvironment(listener);
    e.putAll(env);
    return e;
}
Also used : EnvVars(hudson.EnvVars) FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) LogTaskListener(hudson.util.LogTaskListener) TaskListener(hudson.model.TaskListener) LogTaskListener(hudson.util.LogTaskListener)

Example 2 with FlowExecutionOwner

use of org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner in project workflow-cps-plugin by jenkinsci.

the class CpsFlowDefinition2Test method suspendExecutionAndComeBack.

/**
 * I should be able to have DSL call into async step and then bring it to the completion.
 */
@Test
public void suspendExecutionAndComeBack() throws Exception {
    CpsFlowDefinition flow = new CpsFlowDefinition("semaphore 'watch'\n" + "println 'Yo'");
    // get this going...
    createExecution(flow);
    exec.start();
    SemaphoreStep.waitForStart("watch/1", null);
    assertFalse("Expected the execution to be suspended but it has completed", exec.isComplete());
    FlowExecutionOwner owner = exec.getOwner();
    // poor man's simulation of Jenkins restart
    exec = roundtripXStream(exec);
    exec.onLoad(owner);
    // now resume workflow execution
    SemaphoreStep.success("watch/1", null);
    exec.waitForSuspension();
    assertTrue(exec.isComplete());
}
Also used : FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) Test(org.junit.Test)

Example 3 with FlowExecutionOwner

use of org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner in project workflow-cps-plugin by jenkinsci.

the class CpsThreadDumpTest method simple.

@Test
public void simple() throws Exception {
    p.setDefinition(new CpsFlowDefinition(StringUtils.join(asList("def foo() { bar() }", "def bar() {", "   semaphore 'x'", "}", "foo()"), "\n")));
    WorkflowRun b = p.scheduleBuild2(0).waitForStart();
    SemaphoreStep.waitForStart("x/1", b);
    CpsThreadDumpAction action = b.getAction(CpsThreadDumpAction.class);
    if (action == null) {
        FlowExecutionOwner owner = b.asFlowExecutionOwner();
        assertNotNull(owner);
        CpsFlowExecution exec = (CpsFlowExecution) owner.getOrNull();
        assertNotNull(exec);
        assertFalse(exec.isComplete());
        fail("not sure why CpsThreadDumpAction was missing here");
    }
    CpsThreadDump td = action.threadDumpSynchronous();
    td.print(System.out);
    {
        // verify that we got the right thread dump
        List<ThreadInfo> threads = td.getThreads();
        assertEquals(1, threads.size());
        ThreadInfo t = threads.get(0);
        assertEquals("Thread #0", t.getHeadline());
        assertStackTrace(t, "DSL.semaphore(waiting on x/1)", "WorkflowScript.bar(WorkflowScript:3)", "WorkflowScript.foo(WorkflowScript:1)", "WorkflowScript.run(WorkflowScript:5)");
    }
    SemaphoreStep.success("x/1", null);
    j.waitForCompletion(b);
    assertNull(b.getAction(CpsThreadDumpAction.class));
}
Also used : ThreadInfo(org.jenkinsci.plugins.workflow.cps.CpsThreadDump.ThreadInfo) FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 4 with FlowExecutionOwner

use of org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner in project workflow-cps-plugin by jenkinsci.

the class FlowDurabilityTest method verifyExecutionRemoved.

private static void verifyExecutionRemoved(WorkflowRun run) throws Exception {
    // Verify we've removed all FlowExcecutionList entries
    FlowExecutionList list = FlowExecutionList.get();
    for (FlowExecution fe : list) {
        if (fe == run.getExecution()) {
            Assert.fail("Run still has an execution in the list and should be removed!");
        }
    }
    Field f = list.getClass().getDeclaredField("runningTasks");
    f.setAccessible(true);
    CopyOnWriteList<FlowExecutionOwner> runningTasks = (CopyOnWriteList<FlowExecutionOwner>) (f.get(list));
    Assert.assertFalse(runningTasks.contains(run.asFlowExecutionOwner()));
}
Also used : FlowExecutionList(org.jenkinsci.plugins.workflow.flow.FlowExecutionList) Field(java.lang.reflect.Field) FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) CopyOnWriteList(hudson.util.CopyOnWriteList)

Example 5 with FlowExecutionOwner

use of org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner in project workflow-cps-plugin by jenkinsci.

the class ReplayAction method getExecution.

@CheckForNull
private CpsFlowExecution getExecution() {
    FlowExecutionOwner owner = ((FlowExecutionOwner.Executable) run).asFlowExecutionOwner();
    if (owner == null) {
        return null;
    }
    FlowExecution exec = owner.getOrNull();
    return exec instanceof CpsFlowExecution ? (CpsFlowExecution) exec : null;
}
Also used : FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) CheckForNull(javax.annotation.CheckForNull)

Aggregations

FlowExecutionOwner (org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner)7 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)3 ArrayList (java.util.ArrayList)2 CheckForNull (javax.annotation.CheckForNull)2 Test (org.junit.Test)2 EnvVars (hudson.EnvVars)1 Action (hudson.model.Action)1 Queue (hudson.model.Queue)1 Run (hudson.model.Run)1 TaskListener (hudson.model.TaskListener)1 AccessControlled (hudson.security.AccessControlled)1 CopyOnWriteList (hudson.util.CopyOnWriteList)1 LogTaskListener (hudson.util.LogTaskListener)1 Field (java.lang.reflect.Field)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)1 ThreadInfo (org.jenkinsci.plugins.workflow.cps.CpsThreadDump.ThreadInfo)1 FlowExecutionList (org.jenkinsci.plugins.workflow.flow.FlowExecutionList)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1