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;
}
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());
}
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));
}
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()));
}
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;
}
Aggregations