Search in sources :

Example 1 with GoUnauthorizedException

use of com.thoughtworks.go.server.GoUnauthorizedException in project gocd by gocd.

the class ScheduleServiceStageTriggerTest method shouldNotNotifyListenersForWhenCancelStageTransactionRollsback.

@Test
public void shouldNotNotifyListenersForWhenCancelStageTransactionRollsback() throws Exception {
    Pipeline oldest = preCondition.createPipelineWithFirstStagePassedAndSecondStageRunning();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    final Stage stage = oldest.getStages().byName(preCondition.ftStage);
    final StageIdentifier identifier = stage.getIdentifier();
    StageStatusTopic stageStatusTopic = mock(StageStatusTopic.class);
    JobResultTopic jobResultTopic = mock(JobResultTopic.class);
    StageStatusListener stageStatusListener = mock(StageStatusListener.class);
    JobInstanceService jobInstanceService = jobInstanceService(jobResultTopic);
    StageService stageService = new StageService(stageDao, jobInstanceService, stageStatusTopic, stageStatusCache, securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, stageStatusListener);
    SchedulingPerformanceLogger schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    scheduleService = new ScheduleService(goConfigService, pipelineService, stageService, schedulingCheckerService, pipelineDao, stageDao, stageOrderService, securityService, pipelineScheduleQueue, this.jobInstanceService, jobInstanceDao, agentAssignment, environmentConfigService, pipelineLockService, serverHealthService, transactionTemplate, null, transactionSynchronizationManager, null, null, null, null, schedulingPerformanceLogger, null);
    try {
        transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {

            @Override
            public Object doInTransaction(TransactionStatus status) throws Exception {
                scheduleService.cancelAndTriggerRelevantStages(stage.getId(), null, null);
                throw new GoUnauthorizedException();
            }
        });
    } catch (Exception e) {
    // ignore
    }
    verify(stageStatusTopic, never()).post(any(StageStatusMessage.class));
    verify(jobResultTopic, never()).post(any(JobResultMessage.class));
    verify(stageStatusListener, never()).stageStatusChanged(any(Stage.class));
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) TransactionStatus(org.springframework.transaction.TransactionStatus) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.Test)

Example 2 with GoUnauthorizedException

use of com.thoughtworks.go.server.GoUnauthorizedException in project gocd by gocd.

the class StageController method cancelViaPost.

@RequestMapping(value = "/**/cancel.json", method = RequestMethod.POST)
public ModelAndView cancelViaPost(@RequestParam(value = "id") Long stageId, HttpServletResponse response, HttpServletRequest request) {
    if (!headerConstraint.isSatisfied(request)) {
        return ResponseCodeView.create(HttpServletResponse.SC_BAD_REQUEST, "Missing required header 'Confirm'");
    }
    try {
        HttpLocalizedOperationResult cancelResult = new HttpLocalizedOperationResult();
        scheduleService.cancelAndTriggerRelevantStages(stageId, UserHelper.getUserName(), cancelResult);
        return handleResult(cancelResult, response);
    } catch (GoUnauthorizedException e) {
        return ResponseCodeView.create(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    } catch (Exception e) {
        return ResponseCodeView.create(HttpServletResponse.SC_NOT_ACCEPTABLE, e.getMessage());
    }
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) StageNotFoundException(com.thoughtworks.go.config.StageNotFoundException) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

GoUnauthorizedException (com.thoughtworks.go.server.GoUnauthorizedException)2 StageNotFoundException (com.thoughtworks.go.config.StageNotFoundException)1 StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)1 JobResultMessage (com.thoughtworks.go.server.messaging.JobResultMessage)1 JobResultTopic (com.thoughtworks.go.server.messaging.JobResultTopic)1 StageStatusMessage (com.thoughtworks.go.server.messaging.StageStatusMessage)1 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)1 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1