(→AHPSCRIPTS-69)
|
(→AHPSCRIPTS-85)
|
Line 111: | |||
} | } | ||
}</pre> | }</pre> | ||
+ | = Short Circuit Job Iteration if Previous Iterations Fail = | ||
+ | ==== AHPSCRIPTS-91 ==== | ||
+ | <pre>import com.urbancode.anthill3.domain.jobconfig.JobConfig; | ||
+ | import com.urbancode.anthill3.domain.jobtrace.JobTrace; | ||
+ | import com.urbancode.anthill3.domain.jobtrace.buildlife.BuildLifeJobTrace; | ||
+ | import com.urbancode.anthill3.domain.jobtrace.buildlife.BuildLifeJobTraceFactory; | ||
+ | import com.urbancode.anthill3.domain.jobtrace.operations.OperationsJobTrace; | ||
+ | import com.urbancode.anthill3.domain.jobtrace.operations.OperationsJobTraceFactory; | ||
+ | import com.urbancode.anthill3.domain.persistent.PersistenceException; | ||
+ | import com.urbancode.anthill3.domain.persistent.PersistenceRuntimeException; | ||
+ | import com.urbancode.anthill3.domain.workflow.Workflow; | ||
+ | import com.urbancode.anthill3.domain.workflow.WorkflowCase; | ||
+ | import com.urbancode.anthill3.domain.workflow.WorkflowDefinition; | ||
+ | import com.urbancode.anthill3.runtime.scripting.helpers.WorkflowLookup; | ||
+ | import com.urbancode.anthill3.services.jobs.JobStatusEnum; | ||
+ | import com.urbancode.commons.dag.Vertex; | ||
+ | import com.urbancode.logic.Criteria; | ||
+ | return new Criteria() { | ||
+ | final JobStatusEnum[] statuses = new JobStatusEnum[] { | ||
+ | JobStatusEnum.SUCCESS, JobStatusEnum.NOT_NEEDED, JobStatusEnum.QUEUED, JobStatusEnum.RUNNING, JobStatusEnum.WAITING_ON_AGENTS | ||
+ | }; | ||
+ | final boolean checkAncestors = true; | ||
+ | |||
+ | public boolean matches(Object obj) { | ||
+ | JobStatus jobStatus = JobStatus.allAncestorsIn(statuses); | ||
+ | boolean match = jobStatus.matches(obj); | ||
+ | |||
+ | if (match) { | ||
+ | // check the previous iteration jobs | ||
+ | JobConfig jobConfig = (JobConfig) obj; | ||
+ | JobTrace[] jobTraces = getJobTracesForJobConfig(WorkflowLookup.getCurrentCase(), jobConfig); | ||
+ | for (int j=0; j<jobTraces.length; j++) { | ||
+ | if (!jobStatus.matches(jobTraces[j])) { | ||
+ | match = false; | ||
+ | setResultMessage(jobStatus.getResultMessage()); | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else { | ||
+ | setResultMessage(jobStatus.getResultMessage()); | ||
+ | } | ||
+ | return match; | ||
+ | } | ||
+ | |||
+ | JobTrace[] getJobTracesForJobConfig(WorkflowCase wcase, JobConfig jobConfig) { | ||
+ | try { | ||
+ | HashSet jobTraceSet = new HashSet(); | ||
+ | if (wcase.getProject().isLifeCycleBased()) { | ||
+ | // do not use the method on workflow case, you may get locally cached jobs that are not up to date | ||
+ | BuildLifeJobTrace[] jobTraces = BuildLifeJobTraceFactory.getInstance().restoreAllForWorkflowCase(wcase); | ||
+ | for (int i = 0; i < jobTraces.length; i++) { | ||
+ | if (jobConfig.equals(jobTraces[i].getJobConfig())) { | ||
+ | jobTraceSet.add(jobTraces[i]); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | else { | ||
+ | OperationsJobTrace[] jobTraces = OperationsJobTraceFactory.getInstance().restoreAllForWorkflowCase(wcase); | ||
+ | for (int i = 0; i < jobTraces.length; i++) { | ||
+ | if (jobConfig.equals(jobTraces[i].getJobConfig())) { | ||
+ | jobTraceSet.add(jobTraces[i]); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | JobTrace[] result = new JobTrace[jobTraceSet.size()]; | ||
+ | jobTraceSet.toArray(result); | ||
+ | return result; | ||
+ | } | ||
+ | catch (PersistenceException e) { | ||
+ | throw new PersistenceRuntimeException(e.getMessage(), e); | ||
+ | } | ||
+ | } | ||
+ | }</pre> |