use of com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel in project gocd by gocd.
the class StageSqlMapDao method findDetailedStageHistory.
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;
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel in project gocd by gocd.
the class PipelineXmlViewModel method toXml.
public Document toXml(XmlWriterContext writerContext) throws DocumentException, IOException {
DOMElement root = new DOMElement("pipeline");
root.addAttribute("name", pipeline.getName()).addAttribute("counter", String.valueOf(pipeline.getCounter())).addAttribute("label", pipeline.getLabel());
Document document = new DOMDocument(root);
String baseUrl = writerContext.getBaseUrl();
root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(baseUrl));
root.addElement("id").addCDATA(pipeline.getPipelineIdentifier().asURN());
PipelineTimelineEntry pipelineAfter = pipeline.getPipelineAfter();
if (pipelineAfter != null) {
addTimelineLink(root, baseUrl, "insertedBefore", pipelineAfter);
}
PipelineTimelineEntry pipelineBefore = pipeline.getPipelineBefore();
if (pipelineBefore != null) {
addTimelineLink(root, baseUrl, "insertedAfter", pipelineBefore);
}
root.addElement("scheduleTime").addText(DateUtils.formatISO8601(pipeline.getScheduledDate()));
Element materials = root.addElement("materials");
for (MaterialRevision materialRevision : pipeline.getCurrentRevisions()) {
populateXml(materials, materialRevision, writerContext);
}
Element stages = root.addElement("stages");
for (StageInstanceModel stage : pipeline.getStageHistory()) {
if (!(stage instanceof NullStageHistoryItem)) {
stages.addElement("stage").addAttribute("href", StageXmlViewModel.httpUrlFor(writerContext.getBaseUrl(), stage.getId()));
}
}
root.addElement("approvedBy").addCDATA(pipeline.getApprovedBy());
return document;
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel in project gocd by gocd.
the class PipelineSqlMapDaoIntegrationTest method shouldLoadPipelineHistories.
@Test
public void shouldLoadPipelineHistories() throws Exception {
String dev = "dev";
PipelineConfig mingleConfig = PipelineMother.twoBuildPlansWithResourcesAndMaterials("mingle", dev);
Pipeline mingle = schedulePipelineWithStages(mingleConfig);
Stage firstStage = mingle.getFirstStage();
Pipeline mingle2 = schedulePipelineWithStages(mingleConfig);
JobInstance instance = firstStage.getJobInstances().first();
jobInstanceDao.ignore(instance);
PipelineInstanceModels pipelineHistories = pipelineDao.loadHistory(mingle.getName(), 10, 0);
assertThat(pipelineHistories.size(), is(2));
StageInstanceModels stageHistories = pipelineHistories.first().getStageHistory();
assertThat(stageHistories.size(), is(1));
StageInstanceModel history = stageHistories.first();
assertThat(history.getName(), is(dev));
assertThat(history.getApprovalType(), is(GoConstants.APPROVAL_SUCCESS));
assertThat(history.getBuildHistory().size(), is(2));
assertThat(pipelineHistories.get(1).getName(), is("mingle"));
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel in project gocd by gocd.
the class PipelineSqlMapDaoIntegrationTest method shouldLoadStageIdentifier.
@Test
public void shouldLoadStageIdentifier() throws SQLException {
Stage stage = new Stage("dev", new JobInstances(new JobInstance("unit")), "anonymous", "manual", new TimeProvider());
stage.building();
Pipeline pipeline = new Pipeline("Test", BuildCause.createManualForced(), stage);
savePipeline(pipeline);
PipelineInstanceModel loaded = pipelineDao.loadHistory("Test").get(0);
StageInstanceModel historicalStage = loaded.getStageHistory().get(0);
assertThat(historicalStage.getIdentifier(), is(new StageIdentifier("Test", loaded.getCounter(), loaded.getLabel(), "dev", historicalStage.getCounter())));
PipelineInstanceModel loadedById = pipelineDao.loadHistory(pipeline.getId());
StageInstanceModel historicalStageModelById = loadedById.getStageHistory().get(0);
assertThat(historicalStageModelById.getIdentifier(), is(new StageIdentifier("Test", loadedById.getCounter(), loadedById.getLabel(), "dev", historicalStage.getCounter())));
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel in project gocd by gocd.
the class PipelineHistoryServiceIntegrationTest method shouldGetLatestPipelineInstanceWithPreviousStateFromAllPipelineGroups.
@Test
public void shouldGetLatestPipelineInstanceWithPreviousStateFromAllPipelineGroups() throws Exception {
configHelper.setViewPermissionForGroup("group1", "jez");
dbHelper.updateNaturalOrder(pipelineOne.createdPipelineWithAllStagesPassed().getId(), 1.0);
dbHelper.updateNaturalOrder(pipelineTwo.createdPipelineWithAllStagesPassed().getId(), 1.0);
dbHelper.updateNaturalOrder(pipelineTwo.createPipelineWithFirstStagePassedAndSecondStageRunning().getId(), 2.0);
Pipeline toRerun = pipelineTwo.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
pipelineTwo.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
dbHelper.updateNaturalOrder(toRerun.getId(), 3);
dbHelper.scheduleStage(toRerun, pipelineTwo.devStage());
pipelineRepository.updatePipelineTimeline(pipelineTimeline, new ArrayList<>());
List<PipelineGroupModel> groupModels = pipelineHistoryService.allActivePipelineInstances(new Username(new CaseInsensitiveString("jez")), PipelineSelections.ALL);
assertThat(groupModels.size(), is(2));
List<PipelineModel> pipelineOneModels = groupModels.get(1).getPipelineModels();
assertThat(pipelineOneModels.size(), is(1));
PipelineInstanceModels pipelineOneInstances = pipelineOneModels.get(0).getActivePipelineInstances();
assertThat(pipelineOneInstances.size(), is(1));
PipelineInstanceModel pipelineOne = pipelineOneInstances.get(0);
assertThat(pipelineOne.getCounter(), is(1));
List<PipelineModel> pipelineTwoModels = groupModels.get(0).getPipelineModels();
assertThat(pipelineTwoModels.size(), is(1));
PipelineInstanceModels pipelineTwoInstances = pipelineTwoModels.get(0).getActivePipelineInstances();
assertThat(pipelineTwoInstances.size(), is(3));
PipelineInstanceModel pipelineTwoJustScheduled = pipelineTwoInstances.get(0);
assertThat(pipelineTwoJustScheduled.getCounter(), is(4));
assertThat(pipelineTwoJustScheduled.getStageHistory().size(), is(2));
StageInstanceModel activeStage = pipelineTwoJustScheduled.activeStage();
assertThat(activeStage, is(nullValue()));
PipelineInstanceModel pipelineTwoPostFirstStage = pipelineTwoInstances.get(1);
assertThat(pipelineTwoPostFirstStage.getCounter(), is(3));
assertThat(pipelineTwoPostFirstStage.getStageHistory().size(), is(2));
activeStage = pipelineTwoPostFirstStage.activeStage();
assertThat(activeStage.getName(), is("dev"));
assertThat(activeStage.hasPreviousStage(), is(true));
assertThat(activeStage.getPreviousStage().getResult(), is(StageResult.Passed));
PipelineInstanceModel pipelineTwoWithSecondStageRunning = pipelineTwoInstances.get(2);
assertThat(pipelineTwoWithSecondStageRunning.getCounter(), is(2));
assertThat(pipelineTwoWithSecondStageRunning.getStageHistory().size(), is(2));
activeStage = pipelineTwoWithSecondStageRunning.activeStage();
assertThat(activeStage.getName(), is("ft"));
assertThat(activeStage.hasPreviousStage(), is(true));
assertThat(activeStage.getPreviousStage().getResult(), is(StageResult.Passed));
}
Aggregations