Search in sources :

Example 6 with FlowDurabilityHint

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

the class ReplayFlowFactoryAction method create.

@Override
public CpsFlowExecution create(FlowDefinition def, FlowExecutionOwner owner, List<? extends Action> actions) throws IOException {
    String script = replacementMainScript;
    // minimize build.xml size
    replacementMainScript = null;
    Queue.Executable exec = owner.getExecutable();
    FlowDurabilityHint hint = (exec instanceof Run) ? DurabilityHintProvider.suggestedFor(((Run) exec).getParent()) : GlobalDefaultFlowDurabilityLevel.getDefaultDurabilityHint();
    return new CpsFlowExecution(script, sandbox, owner, hint);
}
Also used : Run(hudson.model.Run) Queue(hudson.model.Queue) FlowDurabilityHint(org.jenkinsci.plugins.workflow.flow.FlowDurabilityHint) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)

Example 7 with FlowDurabilityHint

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

the class CpsFlowExecution method createStorage.

private TimingFlowNodeStorage createStorage() throws IOException {
    FlowNodeStorage wrappedStorage;
    FlowDurabilityHint hint = getDurabilityHint();
    wrappedStorage = (hint.isPersistWithEveryStep()) ? new SimpleXStreamFlowNodeStorage(this, getStorageDir()) : new BulkFlowNodeStorage(this, getStorageDir());
    return new TimingFlowNodeStorage(wrappedStorage);
}
Also used : BulkFlowNodeStorage(org.jenkinsci.plugins.workflow.support.storage.BulkFlowNodeStorage) SimpleXStreamFlowNodeStorage(org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage) FlowDurabilityHint(org.jenkinsci.plugins.workflow.flow.FlowDurabilityHint) BulkFlowNodeStorage(org.jenkinsci.plugins.workflow.support.storage.BulkFlowNodeStorage) FlowNodeStorage(org.jenkinsci.plugins.workflow.support.storage.FlowNodeStorage) SimpleXStreamFlowNodeStorage(org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage)

Example 8 with FlowDurabilityHint

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

the class FlowDurabilityTest method testCompleteAndLoadBuilds.

/**
 * Confirm that for ALL implementations, a run can complete and be loaded if you restart after completion.
 */
@Test
public void testCompleteAndLoadBuilds() throws Exception {
    final FlowDurabilityHint[] durabilityHints = FlowDurabilityHint.values();
    final WorkflowJob[] jobs = new WorkflowJob[durabilityHints.length];
    final String[] logOutput = new String[durabilityHints.length];
    // Create and run jobs for each of the durability hints
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            int i = 1;
            for (FlowDurabilityHint hint : durabilityHints) {
                try {
                    WorkflowRun run = createAndRunBasicJob(story.j.jenkins, "basicJob-" + hint.toString(), hint, i);
                    jobs[i - 1] = run.getParent();
                    SemaphoreStep.success("halt/" + i++, Result.SUCCESS);
                    story.j.waitForCompletion(run);
                    story.j.assertBuildStatus(Result.SUCCESS, run);
                    logOutput[i - 2] = JenkinsRule.getLog(run);
                    assertHasTimingAction(run.getExecution());
                } catch (AssertionError ae) {
                    System.out.println("Error with durability level: " + hint);
                    throw ae;
                }
            }
        }
    });
    // Restart and confirm we can still load them.
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            for (int i = 0; i < durabilityHints.length; i++) {
                WorkflowJob j = jobs[i];
                try {
                    WorkflowRun run = j.getLastBuild();
                    verifySucceededCleanly(story.j.jenkins, run);
                    Assert.assertEquals(durabilityHints[i], run.getExecution().getDurabilityHint());
                    Assert.assertEquals(logOutput[i], JenkinsRule.getLog(run));
                    assertHasTimingAction(run.getExecution());
                } catch (AssertionError ae) {
                    System.out.println("Error with durability level: " + durabilityHints[i]);
                    throw ae;
                }
            }
        }
    });
}
Also used : Statement(org.junit.runners.model.Statement) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FlowDurabilityHint(org.jenkinsci.plugins.workflow.flow.FlowDurabilityHint) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Aggregations

FlowDurabilityHint (org.jenkinsci.plugins.workflow.flow.FlowDurabilityHint)8 Queue (hudson.model.Queue)3 Run (hudson.model.Run)3 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)3 Action (hudson.model.Action)2 File (java.io.File)2 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)2 Test (org.junit.Test)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 AbortException (hudson.AbortException)1 FilePath (hudson.FilePath)1 XmlFile (hudson.XmlFile)1 Computer (hudson.model.Computer)1 Node (hudson.model.Node)1 TopLevelItem (hudson.model.TopLevelItem)1 WorkspaceList (hudson.slaves.WorkspaceList)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 Random (java.util.Random)1