public static PipelineInstanceModel singlePipeline(String pipelineName, StageInstanceModel stage) { StageInstanceModels stageInstanceModels = new StageInstanceModels(); stageInstanceModels.add(stage); return singlePipeline(pipelineName, stageInstanceModels, new Date()); }
public StageInstanceModel latestStage() { if (size() == 0) { return null; } StageInstanceModel latest = first(); for (int i = 1; i < size(); i++) { StageInstanceModel current = get(i); if (!(current instanceof NullStageHistoryItem) && current.getScheduledDate().after(latest.getScheduledDate())) { latest = current; } } return latest; }
private PipelineInstanceModel() { stageHistory = new StageInstanceModels(); }
@Test public void shouldReturnNullWhenNoActiveStage() { StageInstanceModels stages = new StageInstanceModels(); stages.addStage("unit1", JobHistory.withJob("test", JobState.Completed, JobResult.Passed, new Date())); JobHistory history = new JobHistory(); history.add(new JobHistoryItem("test-1", JobState.Completed, JobResult.Failed, new Date())); history.add(new JobHistoryItem("test-2", JobState.Completed, JobResult.Passed, new Date())); stages.add(new StageInstanceModel("unit2", "1", history)); stages.addFutureStage("unit3", false); PipelineInstanceModel model = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createManualForced(), stages); assertThat(model.activeStage(), is(nullValue())); }
@Test public void shouldUnderstandIfItHasNeverCheckedForRevisions() { StageInstanceModels stages = new StageInstanceModels(); stages.addStage("unit1", JobHistory.withJob("test", JobState.Completed, JobResult.Passed, new Date())); stages.addFutureStage("unit2", false); PipelineInstanceModel pim = PipelineInstanceModel.createPipeline("pipeline", -1, "label", BuildCause.createNeverRun(), stages); pim.setLatestRevisions(MaterialRevisions.EMPTY); assertThat("pim.hasNeverCheckedForRevisions()", pim.hasNeverCheckedForRevisions(), is(true)); } @Test
@Test public void shouldReturnEarliestDate() { StageInstanceModels history = new StageInstanceModels(); history.add(new StageHistoryItemStub(EARLIEAR_DATE)); history.add(new StageHistoryItemStub(DATE)); assertThat(history.getScheduledDate(), Matchers.is(EARLIEAR_DATE)); }
public static StageInstanceModels stagePerJob(String baseName, List<JobHistory> histories) { StageInstanceModels stageInstanceModels = new StageInstanceModels(); for (int i = 0; i < histories.size(); i++) { String stageName = baseName + "-" + i; StageInstanceModel stage = new StageInstanceModel(stageName, "1", StageResult.Passed, new StageIdentifier("pipeline", 1, "1", stageName, "1")); stage.setBuildHistory(histories.get(i)); stageInstanceModels.add(stage); stageInstanceModels.latestStage().setApprovedBy("cruise"); } return stageInstanceModels; }
@Test public void shouldReturnIfAStageIsLatest() { Date occuredFirst = new DateTime().minusDays(1).toDate(); Date occuredSecond = new DateTime().toDate(); StageInstanceModels stageInstanceModels = stagePerJob("stage", job(JobResult.Passed, occuredSecond), job(JobResult.Passed, occuredFirst)); NullStageHistoryItem stageHistoryItem = new NullStageHistoryItem("not_yet_run", false); stageInstanceModels.add(stageHistoryItem); PipelineInstanceModel instanceModel = PipelineInstanceModel.createPipeline("pipeline", -1, "label", createWithEmptyModifications(), stageInstanceModels); assertThat(instanceModel.isLatestStage(stageInstanceModels.get(0)), is(true)); assertThat(instanceModel.isLatestStage(stageInstanceModels.get(1)), is(false)); }
public boolean hasSameStagesAs(PipelineInstanceModel pipelineInstanceModel) { StageInstanceModels stageHistory = pipelineInstanceModel.getStageHistory(); if (stages.size() != stageHistory.size()) { return false; } for (int i = 0; i < stages.size(); i++) { if (!equals(stages.get(i), stageHistory.get(i))) { return false; } } return true; }
@Test public void shouldNotHaveDateForEmptyHistory() { assertThat(new StageInstanceModels().getScheduledDate(), is(nullValue())); }
@Test public void shouldUnderstandPipelineStatusMessage() throws Exception { StageInstanceModels stages = new StageInstanceModels(); stages.addFutureStage("unit1", false); stages.addFutureStage("unit2", false); PipelineInstanceModel pipeline = PipelineInstanceModel.createPreparingToSchedule("pipeline-name", stages); assertThat(pipeline.getPipelineStatusMessage(), Matchers.is("Preparing to schedule (0/2)")); }
public void updateFutureStagesFrom(PipelineConfig pipelineConfig) { StageInstanceModel lastStage = this.last(); StageConfig nextStage = lastStage == null ? pipelineConfig.getFirstStageConfig() : pipelineConfig.nextStage(new CaseInsensitiveString(lastStage.getName())); while (nextStage != null && !this.hasStage(str(nextStage.name()))) { this.addFutureStage(str(nextStage.name()), !nextStage.requiresApproval()); nextStage = pipelineConfig.nextStage(nextStage.name()); } } }
public StageInstanceModel latestStage() { return stageHistory.latestStage(); }
StageInstanceModels findDetailedStageHistory(String pipelineName, String stageName, Pagination pagination) { Map<String, Object> args = arguments("pipelineName", pipelineName). and("stageName", stageName). and("limit", pagination.getPageSize()). and("offset", pagination.getOffset()).asMap(); List<StageInstanceModel> detailedStageHistory = (List<StageInstanceModel>) getSqlMapClientTemplate().queryForList("getDetailedStageHistory", args); StageInstanceModels stageInstanceModels = new StageInstanceModels(); stageInstanceModels.addAll(detailedStageHistory); return stageInstanceModels; }
/** * * @deprecated use add method. This is a test helper */ public void addStage(String name, JobHistory history) { add(new StageInstanceModel(name, "1", history)); }
public boolean hasStage(String stageName) { return byName(stageName) != null; }
private static Consumer<OutputListWriter> getStages(PipelineInstanceModel model) { return writer -> { model.getStageHistory().forEach(stage -> { writer.addChild(childWriter -> { StageRepresenter.toJSON(childWriter, stage, model.getName(), String.valueOf(model.getCounter())); }); }); }; } }
public boolean hasStageBeenRun(String stageName) { return stageHistory.hasStage(stageName); }