Search in sources :

Example 1 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class PipelineHistoryController method list.

@RequestMapping(value = "/**/pipelineHistory.json", method = RequestMethod.GET)
public ModelAndView list(@RequestParam("pipelineName") String pipelineName, @RequestParam(value = "perPage", required = false) Integer perPageParam, @RequestParam(value = "start", required = false) Integer startParam, @RequestParam(value = "labelFilter", required = false) String labelFilter, HttpServletResponse response, HttpServletRequest request) throws NamingException {
    PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
    String username = CaseInsensitiveString.str(UserHelper.getUserName().getUsername());
    Pagination pagination;
    try {
        pagination = Pagination.pageStartingAt(startParam, pipelineHistoryService.totalCount(pipelineName), perPageParam);
    } catch (Exception e) {
        Map<String, Object> json = new LinkedHashMap<>();
        addDeveloperErrorMessage(json, e);
        return jsonNotAcceptable(json).respond(response);
    }
    PipelinePauseInfo pauseInfo = pipelinePauseService.pipelinePauseInfo(pipelineName);
    boolean hasBuildCauseInBuffer = pipelineScheduleQueue.hasBuildCause(CaseInsensitiveString.str(pipelineConfig.name()));
    PipelineInstanceModels pipelineHistory = StringUtil.isBlank(labelFilter) ? pipelineHistoryService.load(pipelineName, pagination, username, true) : pipelineHistoryService.findMatchingPipelineInstances(pipelineName, labelFilter, perPageParam, UserHelper.getUserName(), new HttpLocalizedOperationResult());
    boolean hasForcedBuildCause = pipelineScheduleQueue.hasForcedBuildCause(pipelineName);
    PipelineHistoryJsonPresentationModel historyJsonPresenter = new PipelineHistoryJsonPresentationModel(pauseInfo, pipelineHistory, pipelineConfig, pagination, canForce(pipelineConfig, username), hasForcedBuildCause, hasBuildCauseInBuffer, canPause(pipelineConfig, username));
    return jsonFound(historyJsonPresenter.toJson()).respond(response);
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) PipelineInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels) PipelineHistoryJsonPresentationModel(com.thoughtworks.go.server.presentation.models.PipelineHistoryJsonPresentationModel) PipelinePauseInfo(com.thoughtworks.go.domain.PipelinePauseInfo) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) NamingException(javax.naming.NamingException) PipelineNotFoundException(com.thoughtworks.go.config.PipelineNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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 3 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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 4 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class ScheduleServiceSecurityTest method shouldNotThrowExceptionIfUserHasOperatePermission.

@Test
public void shouldNotThrowExceptionIfUserHasOperatePermission() throws Exception {
    configHelper.addSecurityWithAdminConfig();
    Username user = UserHelper.getUserName();
    configHelper.setOperatePermissionForGroup("defaultGroup", user.getUsername().toString());
    Pipeline pipeline = fixture.createPipelineWithFirstStagePassedAndSecondStageRunning();
    HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
    Stage stageForCancellation = pipeline.getStages().byName(fixture.ftStage);
    Stage resultStage = scheduleService.cancelAndTriggerRelevantStages(stageForCancellation.getId(), user, operationResult);
    assertThat(resultStage, is(not(nullValue())));
    assertThat(operationResult.isSuccessful(), is(true));
    assertThat(operationResult.httpCode(), is(SC_OK));
//TODO: Check why stage result is not persisted after stage is cancelled
//        Stage mostRecent = stageDao.mostRecentStage(new StageConfigIdentifier(fixture.pipelineName, fixture.ftStage));
//        assertThat(mostRecent.getResult(), is(StageResult.Cancelled));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Stage(com.thoughtworks.go.domain.Stage) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 5 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class ScheduleServiceSecurityTest method shouldReturnAppropriateHttpResultIfTheStageIsInvalid.

@Test
public void shouldReturnAppropriateHttpResultIfTheStageIsInvalid() throws Exception {
    configHelper.addSecurityWithAdminConfig();
    configHelper.setOperatePermissionForGroup("defaultGroup", "jez");
    Username jez = new Username(new CaseInsensitiveString("jez"));
    HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
    Stage resultStage = scheduleService.cancelAndTriggerRelevantStages(-23l, jez, operationResult);
    assertThat(resultStage, is(nullValue()));
    assertThat(operationResult.isSuccessful(), is(false));
    assertThat(operationResult.httpCode(), is(SC_NOT_FOUND));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Stage(com.thoughtworks.go.domain.Stage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)361 Test (org.junit.Test)329 Username (com.thoughtworks.go.server.domain.Username)131 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)36 Pipeline (com.thoughtworks.go.domain.Pipeline)27 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)22 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)17 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)15 GoCipher (com.thoughtworks.go.security.GoCipher)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)13 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)12