public JobInstances(Collection<? extends JobInstance> jobInstances) { for (JobInstance instance : jobInstances) { add(instance); } }
public JobInstances currentJobsOfStage(String pipelineName, StageConfig stageConfig) { JobInstances jobs = new JobInstances(); for (JobConfig jobConfig : stageConfig.allBuildPlans()) { JobConfigIdentifier jobConfigIdentifier = new JobConfigIdentifier(pipelineName, CaseInsensitiveString.str(stageConfig.name()), CaseInsensitiveString.str(jobConfig.name())); List<JobInstance> found = jobStatusCache.currentJobs(jobConfigIdentifier); if (found.isEmpty()) { jobs.add(new NullJobInstance(CaseInsensitiveString.str(jobConfig.name()))); } else { jobs.addAll(found); } } jobs.sortByName(); return jobs; }
public JobInstances filterByResult(JobResult... results) { JobInstances filtered = new JobInstances(); for (JobInstance instance : this) { if (Arrays.asList(results).contains(instance.getResult())) { filtered.add(instance); } } return filtered; }
public JobInstances filterByState(JobState state) { JobInstances filtered = new JobInstances(); for (JobInstance instance : this) { if (state == instance.getState()) { filtered.add(instance); } } return filtered; }
private JobInstances mixedBuilds() { JobInstances instances = new JobInstances(); JobInstance assigned = JobInstanceMother.assigned("test"); instances.add(assigned); JobInstance oldest = passed("oldest"); oldest.completed(new Date()); instances.add(oldest); JobInstance newest = failed("newest"); newest.completed(new Date()); instances.add(newest); instances.add(JobInstance.NULL); JobInstance scheduled = scheduled("redHerring"); instances.add(scheduled); return instances; }
@Test public void jobShouldBeCancelledWhenNoActiveBuildAndHaveAtLeastOneCancelledJob() { JobInstances builds = new JobInstances(); builds.add(completed("passports", JobResult.Passed)); builds.add(completed("passports-failed", JobResult.Failed)); builds.add(completed("visas", JobResult.Cancelled)); builds.add(completed("flights", JobResult.Cancelled)); assertThat(builds.stageState(), is(Cancelled)); }
@Test public void shouldReturnStatusBuildingWhenAnyBuildsAreBuilding() { JobInstances builds = new JobInstances(); builds.add(completed("passports", JobResult.Passed)); builds.add(completed("visas", JobResult.Cancelled)); builds.add(scheduled("flights")); assertThat(builds.stageState(), is(Building)); }
@Test public void shouldReturnStatusFailingWhenAnyPlansHaveFailedAndNotAllAreCompleted() { JobInstances builds = new JobInstances(); builds.add(completed("passports", JobResult.Failed)); builds.add(completed("visas", JobResult.Passed)); builds.add(scheduled("flights")); assertThat(builds.stageState(), is(Failing)); }
public void reallyCreateJobInstance(JobConfig config, JobInstances jobs, String uuid, String jobName, boolean runOnAllAgents, boolean runMultipleInstance, SchedulingContext context, final Clock clock) { JobInstance instance = new JobInstance(jobName, clock); instance.setPlan(createJobPlan(config, context)); instance.setAgentUuid(uuid); instance.setRunOnAllAgents(runOnAllAgents); instance.setRunMultipleInstance(runMultipleInstance); jobs.add(instance); }
private Stage createStageInstance(Date old, JobInstances jobs) { int jobId = 100; for (JobInstance job : jobs) { passJob(new Date(), ++jobId, jobId * 10, job); } JobInstance java = jobInstance(old, "java", 12, 22); jobs.add(java); return stage(9, jobs.toArray(new JobInstance[0])); }
public static NullStage createNullStage(StageConfig stageConfig) { JobInstances nullBuilds = new JobInstances(); for (JobConfig plan : stageConfig.allBuildPlans()) { nullBuilds.add(new NullJobInstance(CaseInsensitiveString.str(plan.name()))); } NullStage nullStage = new NullStage(CaseInsensitiveString.str(stageConfig.name()), nullBuilds); nullStage.setPipelineId(10l); return nullStage; }
public static Stage stageWithNBuildsHavingEndState(JobState endState, JobResult result, String stageName, List<String> buildNames) { JobInstances builds = new JobInstances(); for (String buildName : buildNames) { builds.add(JobInstanceMother.buildEndingWithState(endState, result, buildName)); } Stage stage = new Stage(stageName, builds, DEFAULT_APPROVED_BY, null, null, new TimeProvider()); stage.calculateResult(); stage.setCompletedByTransitionId(stage.getJobInstances().last().getTransitions().latestTransitionId()); return stage; }
@Test public void shouldCreateAStageInstanceThroughInstanceFactory() { PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("cruise"), new MaterialConfigs(), new StageConfig(new CaseInsensitiveString("first"), new JobConfigs(new JobConfig("job1"), new JobConfig("job2")))); Stage actualStage = instanceFactory.createStageInstance(pipelineConfig, new CaseInsensitiveString("first"), new DefaultSchedulingContext(), "md5", clock); JobInstances jobInstances = new JobInstances(); jobInstances.add(new JobInstance("job1", clock)); jobInstances.add(new JobInstance("job2", clock)); Stage expectedStage = new Stage("first", jobInstances, "Unknown", null, Approval.SUCCESS, clock); assertThat(actualStage, is(expectedStage)); }