use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class RunningFlowActions method createFor.
@Override
public Collection<? extends Action> createFor(FlowExecutionOwner.Executable executable) {
FlowExecutionOwner owner = executable.asFlowExecutionOwner();
if (owner != null) {
FlowExecution exec = owner.getOrNull();
if (exec instanceof CpsFlowExecution && !exec.isComplete()) {
CpsFlowExecution e = (CpsFlowExecution) exec;
List<Action> actions = new ArrayList<>();
actions.add(new CpsThreadDumpAction(e));
// TODO cf. comment in CpsFlowExecution#pause
if (!(executable instanceof AccessControlled) || ((AccessControlled) executable).hasPermission(Item.CANCEL)) {
actions.add(new PauseUnpauseAction(e));
}
return actions;
}
}
return Collections.emptySet();
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecutionTest method getCurrentExecutions.
@Test
public void getCurrentExecutions() {
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'a step'; semaphore 'one'; retry(2) {semaphore 'two'; node {semaphore 'three'}; semaphore 'four'}; semaphore 'five'; " + "parallel a: {node {semaphore 'six'}}, b: {semaphore 'seven'}; semaphore 'eight'", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("one/1", b);
FlowExecution e = b.getExecution();
assertStepExecutions(e, "semaphore");
SemaphoreStep.success("one/1", null);
SemaphoreStep.waitForStart("two/1", b);
assertStepExecutions(e, "retry {}", "semaphore");
SemaphoreStep.success("two/1", null);
SemaphoreStep.waitForStart("three/1", b);
assertStepExecutions(e, "retry {}", "node {}", "semaphore");
}
});
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getLastBuild();
CpsFlowExecution e = (CpsFlowExecution) b.getExecution();
assertTrue(e.isSandbox());
SemaphoreStep.success("three/1", null);
SemaphoreStep.waitForStart("four/1", b);
assertStepExecutions(e, "retry {}", "semaphore");
SemaphoreStep.failure("four/1", new AbortException("try again"));
SemaphoreStep.waitForStart("two/2", b);
assertStepExecutions(e, "retry {}", "semaphore");
SemaphoreStep.success("two/2", null);
SemaphoreStep.waitForStart("three/2", b);
assertStepExecutions(e, "retry {}", "node {}", "semaphore");
SemaphoreStep.success("three/2", null);
SemaphoreStep.waitForStart("four/2", b);
assertStepExecutions(e, "retry {}", "semaphore");
SemaphoreStep.success("four/2", null);
SemaphoreStep.waitForStart("five/1", b);
assertStepExecutions(e, "semaphore");
SemaphoreStep.success("five/1", null);
SemaphoreStep.waitForStart("six/1", b);
SemaphoreStep.waitForStart("seven/1", b);
assertStepExecutions(e, "parallel {}", "node {}", "semaphore", "semaphore");
SemaphoreStep.success("six/1", null);
SemaphoreStep.success("seven/1", null);
SemaphoreStep.waitForStart("eight/1", b);
assertStepExecutions(e, "semaphore");
SemaphoreStep.success("eight/1", null);
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
assertStepExecutions(e);
}
});
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testFullyDurableSurvivesDirtyRestart.
/**
* Sanity check that fully durable pipelines can survive hard kills.
*/
@Test
public void testFullyDurableSurvivesDirtyRestart() throws Exception {
final String jobName = "survivesEverything";
final String[] logStart = new String[1];
story.addStepWithDirtyShutdown(new Statement() {
@Override
public void evaluate() throws Throwable {
Jenkins jenkins = story.j.jenkins;
WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY);
FlowExecution exec = run.getExecution();
if (exec instanceof CpsFlowExecution) {
assert ((CpsFlowExecution) exec).getStorage().isPersistedFully();
}
logStart[0] = JenkinsRule.getLog(run);
}
});
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
verifySafelyResumed(story.j, run, false, logStart[0]);
}
});
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method verifySucceededCleanly.
static void verifySucceededCleanly(Jenkins j, WorkflowRun run) throws Exception {
Assert.assertEquals(Result.SUCCESS, run.getResult());
int outputHash = run.getLog().hashCode();
FlowExecution exec = run.getExecution();
verifyCompletedCleanly(j, run);
// Confirm the flow graph is fully navigable and contains the heads with appropriate ending
DepthFirstScanner scan = new DepthFirstScanner();
List<FlowNode> allNodes = scan.allNodes(exec);
FlowNode endNode = exec.getCurrentHeads().get(0);
Assert.assertEquals(FlowEndNode.class, endNode.getClass());
assert allNodes.contains(endNode);
Assert.assertEquals(8, allNodes.size());
// Graph structure assertions
Assert.assertEquals(2, scan.filteredNodes(endNode, (Predicate) (Predicates.instanceOf(StepStartNode.class))).size());
Assert.assertEquals(2, scan.filteredNodes(endNode, (Predicate) (Predicates.instanceOf(StepEndNode.class))).size());
Assert.assertEquals(1, scan.filteredNodes(endNode, (Predicate) (Predicates.instanceOf(FlowStartNode.class))).size());
Predicate<FlowNode> sleepOrSemaphoreMatch = Predicates.or(new NodeStepNamePredicate(StepDescriptor.byFunctionName("semaphore").getId()), new NodeStepNamePredicate(StepDescriptor.byFunctionName("sleep").getId()));
Assert.assertEquals(1, scan.filteredNodes(endNode, sleepOrSemaphoreMatch).size());
Assert.assertEquals(1, scan.filteredNodes(endNode, new NodeStepNamePredicate(StepDescriptor.byFunctionName("echo").getId())).size());
for (FlowNode node : (List<FlowNode>) (scan.filteredNodes(endNode, (Predicate) (Predicates.instanceOf(StepNode.class))))) {
Assert.assertNotNull("Node: " + node.toString() + " does not have a TimingAction", node.getAction(TimingAction.class));
}
assertHasTimingAction(run.getExecution());
}
use of org.jenkinsci.plugins.workflow.flow.FlowExecution in project workflow-cps-plugin by jenkinsci.
the class FlowDurabilityTest method testFullyDurableSurvivesCleanRestart.
/**
* Sanity check that fully durable pipelines shutdown and restart cleanly
*/
@Test
public void testFullyDurableSurvivesCleanRestart() throws Exception {
final String jobName = "survivesEverything";
final String[] logStart = new String[1];
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
Jenkins jenkins = story.j.jenkins;
WorkflowRun run = createAndRunBasicJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY);
FlowExecution exec = run.getExecution();
if (exec instanceof CpsFlowExecution) {
assert ((CpsFlowExecution) exec).getStorage().isPersistedFully();
}
logStart[0] = JenkinsRule.getLog(run);
}
});
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
verifySafelyResumed(story.j, run, true, logStart[0]);
}
});
}
Aggregations