Search in sources :

Example 1 with StageSummaryModel

use of com.thoughtworks.go.server.ui.StageSummaryModel in project gocd by gocd.

the class ScheduleServiceCachedIntegrationTest method shouldUpdateResultOfStageWhenJobCompletes_irrespectiveOfOtherThreadsPrimingStageCache.

@Test
public void shouldUpdateResultOfStageWhenJobCompletes_irrespectiveOfOtherThreadsPrimingStageCache() throws Exception {
    Pipeline assigned = preCondition.createPipelineWithFirstStageAssigned();
    Stage stage = assigned.findStage(preCondition.devStage);
    StageSummaryModel model = stageService.findStageSummaryByIdentifier(stage.getIdentifier(), new Username(new CaseInsensitiveString("foo")), new HttpLocalizedOperationResult());
    JobIdentifier identifier = stage.getFirstJob().getIdentifier();
    scheduleService.updateJobStatus(identifier, JobState.Building);
    scheduleService.jobCompleting(identifier, JobResult.Passed, "uuid");
    //priming the cache
    Stage stageLoadedByOtherFlows = stageDao.stageById(stage.getId());
    scheduleService.updateJobStatus(stage.getFirstJob().getIdentifier(), JobState.Completed);
    StageSummaryModel reloadedModel = stageService.findStageSummaryByIdentifier(stage.getIdentifier(), new Username(new CaseInsensitiveString("foo")), new HttpLocalizedOperationResult());
    Stage reloadedStage = reloadedModel.getStage();
    assertThat(reloadedStage.getFirstJob().getState(), is(JobState.Completed));
    assertThat(reloadedStage.getCompletedByTransitionId(), is(reloadedStage.getFirstJob().getTransitions().byState(JobState.Completed).getId()));
    assertThat(reloadedStage.getResult(), is(StageResult.Passed));
    assertThat(reloadedStage.getState(), is(StageState.Passed));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) StageSummaryModel(com.thoughtworks.go.server.ui.StageSummaryModel) Stage(com.thoughtworks.go.domain.Stage) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 2 with StageSummaryModel

use of com.thoughtworks.go.server.ui.StageSummaryModel in project gocd by gocd.

the class ScheduleServiceCachedIntegrationTest method shouldUpdateResultOfStageWhenJobCompletes.

@Test
public void shouldUpdateResultOfStageWhenJobCompletes() throws Exception {
    //        ScheduleService service = new ScheduleService(goConfigService, pipelineService, stageService, currentActivityService, schedulingChecker, pipelineScheduledTopic, pipelineDao,
    //                stageDao, stageOrderService, securityService, pipelineScheduleQueue, jobInstanceService, jobInstanceDao, agentAssignment, environmentConfigService,
    //                pipelineLockService, serverHealthService, transactionTemplate, agentService);
    Pipeline assigned = preCondition.createPipelineWithFirstStageAssigned();
    Stage stage = assigned.findStage(preCondition.devStage);
    StageSummaryModel model = stageService.findStageSummaryByIdentifier(stage.getIdentifier(), new Username(new CaseInsensitiveString("foo")), new HttpLocalizedOperationResult());
    assertThat(model.getStage().getFirstJob().getState(), is(JobState.Assigned));
    scheduleService.updateJobStatus(stage.getFirstJob().getIdentifier(), JobState.Building);
    StageSummaryModel reloadedModel = stageService.findStageSummaryByIdentifier(stage.getIdentifier(), new Username(new CaseInsensitiveString("foo")), new HttpLocalizedOperationResult());
    assertThat(reloadedModel.getStage().getFirstJob().getState(), is(JobState.Building));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) StageSummaryModel(com.thoughtworks.go.server.ui.StageSummaryModel) Stage(com.thoughtworks.go.domain.Stage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 3 with StageSummaryModel

use of com.thoughtworks.go.server.ui.StageSummaryModel in project gocd by gocd.

the class StageService method findStageSummaryByIdentifier.

public StageSummaryModel findStageSummaryByIdentifier(StageIdentifier stageId, Username username, LocalizedOperationResult result) {
    if (!securityService.hasViewPermissionForPipeline(username, stageId.getPipelineName())) {
        result.unauthorized(LocalizedMessage.cannotViewPipeline(stageId.getPipelineName()), HealthStateType.general(HealthStateScope.forPipeline(stageId.getPipelineName())));
        return null;
    }
    Stages stages = stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName());
    for (Stage stage : stages) {
        if (stage.getIdentifier().getStageCounter().equals(stageId.getStageCounter())) {
            StageSummaryModel summaryModel = new StageSummaryModel(stage, stages, stageDao, null);
            return summaryModel;
        }
    }
    result.notFound(LocalizedMessage.stageNotFound(stageId), HealthStateType.general(HealthStateScope.GLOBAL));
    return null;
}
Also used : StageSummaryModel(com.thoughtworks.go.server.ui.StageSummaryModel)

Example 4 with StageSummaryModel

use of com.thoughtworks.go.server.ui.StageSummaryModel in project gocd by gocd.

the class StageService method findStageHistoryForChart.

public StageSummaryModels findStageHistoryForChart(String pipelineName, String stageName, int pageNumber, int pageSize, Username username) {
    int total = stageDao.getTotalStageCountForChart(pipelineName, stageName);
    Pagination pagination = Pagination.pageByNumber(pageNumber, total, pageSize);
    List<Stage> stages = stageDao.findStageHistoryForChart(pipelineName, stageName, pageSize, pagination.getOffset());
    StageSummaryModels stageSummaryModels = new StageSummaryModels();
    for (Stage forStage : stages) {
        StageSummaryModel stageSummaryByIdentifier = new StageSummaryModel(forStage, null, stageDao, forStage.getIdentifier());
        if (!stageSummaryByIdentifier.getStage().getState().completed()) {
            continue;
        }
        stageSummaryModels.add(stageSummaryByIdentifier);
    }
    stageSummaryModels.setPagination(pagination);
    return stageSummaryModels;
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageSummaryModel(com.thoughtworks.go.server.ui.StageSummaryModel) StageSummaryModels(com.thoughtworks.go.server.ui.StageSummaryModels)

Aggregations

StageSummaryModel (com.thoughtworks.go.server.ui.StageSummaryModel)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 Pipeline (com.thoughtworks.go.domain.Pipeline)2 Stage (com.thoughtworks.go.domain.Stage)2 Username (com.thoughtworks.go.server.domain.Username)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 Test (org.junit.Test)2 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 StageSummaryModels (com.thoughtworks.go.server.ui.StageSummaryModels)1 Pagination (com.thoughtworks.go.server.util.Pagination)1