Search in sources :

Example 16 with StageInstanceModel

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;
}
Also used : StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) ArrayList(java.util.ArrayList) List(java.util.List) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel)

Example 17 with StageInstanceModel

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;
}
Also used : NullStageHistoryItem(com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem) DOMElement(org.dom4j.dom.DOMElement) Element(org.dom4j.Element) DOMDocument(org.dom4j.dom.DOMDocument) DOMElement(org.dom4j.dom.DOMElement) Document(org.dom4j.Document) DOMDocument(org.dom4j.dom.DOMDocument) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry)

Example 18 with StageInstanceModel

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"));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) Test(org.junit.Test)

Example 19 with StageInstanceModel

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())));
}
Also used : PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) Test(org.junit.Test)

Example 20 with StageInstanceModel

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));
}
Also used : PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels) Username(com.thoughtworks.go.server.domain.Username) PipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel) EmptyPipelineInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.EmptyPipelineInstanceModel) PipelineGroupModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineGroupModel) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) PipelineModel(com.thoughtworks.go.presentation.pipelinehistory.PipelineModel) Test(org.junit.Test)

Aggregations

StageInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel)21 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)13 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)8 Test (org.junit.Test)8 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)6 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)3 PipelineDependencyGraphOld (com.thoughtworks.go.domain.PipelineDependencyGraphOld)3 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 JobHistory (com.thoughtworks.go.presentation.pipelinehistory.JobHistory)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 StageConfig (com.thoughtworks.go.config.StageConfig)1 DefaultSchedulingContext (com.thoughtworks.go.domain.DefaultSchedulingContext)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 PipelinePauseInfo (com.thoughtworks.go.domain.PipelinePauseInfo)1 PipelineTimelineEntry (com.thoughtworks.go.domain.PipelineTimelineEntry)1 EmptyPipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.EmptyPipelineInstanceModel)1 NullStageHistoryItem (com.thoughtworks.go.presentation.pipelinehistory.NullStageHistoryItem)1 PipelineGroupModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineGroupModel)1