public void buildingBuildInstance(Stage stage) { if (!stage.getJobInstances().isEmpty()) { JobInstance jobInstance = stage.getJobInstances().get(0); jobInstance.setAgentUuid(AGENT_UUID); jobInstance.changeState(JobState.Building); jobInstanceDao.updateAssignedInfo(jobInstance); } }
public void onefailAndOnePassedBuildInstances(Stage instance) { final JobInstance first = instance.getJobInstances().get(0); final JobInstance second = instance.getJobInstances().get(1); first.completing(Failed); second.completing(Failed); first.completed(new Date()); second.completed(new Date()); jobInstanceDao.updateStateAndResult(first); jobInstanceDao.updateStateAndResult(second); }
public void buildInstanceWithDiscontinuedState(Stage instance) { final JobInstance first = instance.getJobInstances().get(0); final JobInstance second = instance.getJobInstances().get(1); first.completing(JobResult.Passed); second.changeState(JobState.Discontinued); second.setResult(JobResult.Passed); first.completed(new Date()); jobInstanceDao.updateStateAndResult(first); jobInstanceDao.updateStateAndResult(second); updateResultInTransaction(instance, StageResult.Passed); }
private void assertPipelinesScheduled() { Pipeline minglePipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(mingleConfig.name())); Stage mingleStage = minglePipeline.getFirstStage(); assertThat(mingleStage.getName(), is(STAGE_NAME)); assertThat(mingleStage.getJobInstances().size(), is(2)); JobInstance mingleJob = mingleStage.getJobInstances().first(); assertThat(mingleJob.getState(), is(JobState.Scheduled)); assertPipelineScheduled(evolveConfig); assertPipelineScheduled(goConfig); }
@Test public void shouldGetAPresenterWithLabelAndRelevantBuildPlans() throws Exception { DurationBeans durations = new DurationBeans( new DurationBean(stage.getJobInstances().getByName("job-that-will-fail").getId(), 12L)); StageJsonPresentationModel presenter = new StageJsonPresentationModel( pipeline, stage, null, new Agents(), durations, new TrackingTool()); Map json = presenter.toJson(); new JsonTester(json) .shouldContain( "{ 'stageName' : 'stage'," + " 'builds' : [" + " { 'name' : 'job-that-will-fail', 'last_build_duration' : '12' }," + " { 'name' : 'job-that-will-pass' }, " + " { 'name' : 'scheduledBuild' }" + " ]," + " 'current_label' : '" + pipeline.getLabel() + "'," + " 'id' : '1' " + "}"); assertFalse( "JSON shouldn't contain last_successful_label", json.toString().contains("last_successful_label")); }
public Stage saveBuildingStage(Stage stage) { for (JobInstance jobInstance : stage.getJobInstances()) { JobInstanceMother.setBuildingState(jobInstance); jobInstance.setAgentUuid(AGENT_UUID); jobInstanceDao.updateAssignedInfo(jobInstance); } return stage; }
public void cancelStage(Stage stage) { for (JobInstance job : stage.getJobInstances()) { job.cancel(); jobInstanceDao.updateStateAndResult(job); } stage.calculateResult(); updateResultInTransaction(stage, StageResult.Cancelled); }
public Stage saveBuildingStage(String pipelineName, String stageName) throws SQLException { Pipeline pipeline = saveTestPipeline(pipelineName, stageName); Stage stage = saveBuildingStage(pipeline.getStages().byName(stageName)); for (JobInstance job : stage.getJobInstances()) { job.setIdentifier(new JobIdentifier(pipeline, stage, job)); } return stage; }
private void assertPipelineScheduled(PipelineConfig config) { Stage evolveStage = stageDao.mostRecentWithBuilds( CaseInsensitiveString.str(config.name()), config.findBy(new CaseInsensitiveString("dev"))); assertThat(evolveStage.getName(), is("dev")); assertThat(evolveStage.getJobInstances().size(), is(1)); assertThat(evolveStage.getJobInstances().first().getState(), is(JobState.Scheduled)); }
public void failStage(Stage stage, Date completionDate) { for (JobInstance job : stage.getJobInstances()) { job.completing(Failed, completionDate); job.completed(completionDate); jobInstanceDao.updateStateAndResult(job); } stage.calculateResult(); updateResultInTransaction(stage, StageResult.Failed); }
private Pipeline passFirstStage(PipelineConfig pipelineConfig) { Stage completedMingleStage = stageDao.mostRecentWithBuilds( CaseInsensitiveString.str(pipelineConfig.name()), pipelineConfig.findBy(new CaseInsensitiveString("dev"))); dbHelper.passStage(completedMingleStage); dbHelper.passStage(completedMingleStage); assertThat(completedMingleStage.getJobInstances().first().getState(), is(JobState.Completed)); Pipeline pipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(pipelineConfig.name())); return dbHelper.passPipeline(pipeline); }
@Test public void shouldScheduleJobForAllAgentsWhenToBeRunOnAllAgents() throws Exception { configHelper.addAgent("localhost", "uuid1"); configHelper.addAgent("localhost", "uuid2"); configHelper.addAgent("localhost", "uuid3"); configHelper.addAgentToEnvironment("dev", "uuid1"); configHelper.setRunOnAllAgents( CaseInsensitiveString.str(evolveConfig.name()), STAGE_NAME, "unit", true); Material stubMaterial = new TestingMaterial(); evolveConfig.setMaterialConfigs(new MaterialConfigs(stubMaterial.config())); MaterialRevisions revisions = new MaterialRevisions(); revisions.addRevision( stubMaterial, ((TestingMaterial) stubMaterial) .modificationsSince(null, null, subprocessExecutionContext)); BuildCause buildCause = BuildCause.createWithModifications(revisions, ""); dbHelper.saveMaterials(buildCause.getMaterialRevisions()); Pipeline pipeline = instanceFactory.createPipelineInstance( evolveConfig, buildCause, new DefaultSchedulingContext( DEFAULT_APPROVED_BY, environmentConfigService.agentsForPipeline(evolveConfig.name())), md5, new TimeProvider()); pipelineService.save(pipeline); Stage instance = scheduleService.scheduleStage( pipeline, STAGE_NAME, "anyone", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler()); JobInstances scheduledJobs = instance.getJobInstances(); assertThat( scheduledJobs.toArray(), hasItemInArray( hasProperty( "name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("unit", 1))))); assertThat(scheduledJobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid2")))); assertThat( scheduledJobs.toArray(), hasItemInArray( hasProperty( "name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("unit", 2))))); assertThat(scheduledJobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid3")))); assertThat(scheduledJobs.size(), is(2)); }
private Pipeline scheduleJobInstancesAndSavePipeline(Pipeline pipeline) { assertNotInserted(pipeline.getId()); for (Stage stage : pipeline.getStages()) { for (JobInstance jobInstance : stage.getJobInstances()) { jobInstance.schedule(); } } this.savePipelineWithStagesAndMaterials(pipeline); long pipelineId = pipeline.getId(); assertIsInserted(pipelineId); return pipeline; }
@Before public void setUp() { MaterialRevisions materialRevisions = multipleModifications(); stage = StageMother.withOneScheduledBuild("stage", "job-that-will-fail", "job-that-will-pass", 1); modifications = BuildCause.createWithModifications(materialRevisions, ""); pipeline = new Pipeline("pipeline", PipelineLabel.COUNT_TEMPLATE, modifications, stage); stage.setIdentifier(new StageIdentifier(pipeline, stage)); for (JobInstance job : stage.getJobInstances()) { job.setIdentifier(new JobIdentifier(pipeline, stage, job)); } pipeline.setId(PIPELINE_ID); pipeline.updateCounter(9); }
@Test public void shouldSaveBuildStateCorrectly() throws Exception { PipelineConfig cruisePlan = configHelper.addPipeline("cruise", "dev", repository); goConfigService.forceNotifyListeners(); autoSchedulePipelines("mingle", "evolve", "cruise"); Stage cruise = stageDao.mostRecentWithBuilds( CaseInsensitiveString.str(cruisePlan.name()), cruisePlan.findBy(new CaseInsensitiveString("dev"))); System.out.println("cruise = " + cruise); JobInstance instance = cruise.getJobInstances().first(); System.out.println("instance = " + instance); assertThat(instance.getState(), is(JobState.Scheduled)); }
@Test public void shouldNotScheduleBuildIfNoModification() throws Exception { autoSchedulePipelines("mingle", "evolve"); // Get the scheduled evolve stage and complete it. Stage evolveInstance = stageDao.mostRecentWithBuilds( CaseInsensitiveString.str(evolveConfig.name()), evolveConfig.findBy(new CaseInsensitiveString("dev"))); dbHelper.passStage(evolveInstance); stageDao.stageStatusChanged(evolveInstance); autoSchedulePipelines(); Stage mostRecent = stageDao.mostRecentWithBuilds( CaseInsensitiveString.str(evolveConfig.name()), evolveConfig.findBy(new CaseInsensitiveString("dev"))); assertThat(mostRecent.getId(), is(evolveInstance.getId())); assertThat(mostRecent.getJobInstances().first().getState(), is(JobState.Completed)); }
@Test public void shouldPassEnvironmentLevelEnvironmentVariablesToJobsForNewlyScheduledStage() throws Exception { scheduleAndCompleteInitialPipelines(); Pipeline pipeline = pipelineDao.mostRecentPipeline("go"); Stage stage = scheduleService.scheduleStage( pipeline, "ft", "anonymous", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler()); EnvironmentVariablesConfig jobVariables = stage.getJobInstances().first().getPlan().getVariables(); assertThat( jobVariables.size(), is(3)); // pipeline, stage, job, env is applied while creating work assertThat( jobVariables, hasItem(new EnvironmentVariableConfig("PIPELINE_LVL", "pipeline value"))); assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("STAGE_LVL", "stage value"))); assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("JOB_LVL", "job value"))); }
public StageResult completeAllJobs(Stage stage, JobResult jobResult) { for (JobInstance job : stage.getJobInstances()) { JobInstanceMother.setBuildingState(job); job.setAgentUuid(AGENT_UUID); job.completing(jobResult); job.completed(new DateTime().plusMinutes(5).toDate()); jobInstanceDao.updateAssignedInfo(job); } StageResult stageResult; switch (jobResult) { case Failed: stageResult = StageResult.Failed; break; case Cancelled: stageResult = StageResult.Cancelled; break; default: stageResult = StageResult.Passed; } stage.calculateResult(); return stageResult; }