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);
}
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));
}
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));
}
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));
}
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));
}
Aggregations