use of com.thoughtworks.go.config.exceptions.StageNotFoundException in project gocd by gocd.
the class InstanceFactoryTest method shouldThrowStageNotFoundExceptionWhenStageDoesNotExist.
@Test
void shouldThrowStageNotFoundExceptionWhenStageDoesNotExist() {
PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("cruise"), new MaterialConfigs(), new StageConfig(new CaseInsensitiveString("first"), new JobConfigs()));
try {
instanceFactory.createStageInstance(pipelineConfig, new CaseInsensitiveString("doesNotExist"), new DefaultSchedulingContext(), "md5", clock);
fail("Found the stage doesNotExist but, well, it doesn't");
} catch (StageNotFoundException expected) {
assertThat(expected.getMessage(), is("Stage 'doesNotExist' not found in pipeline 'cruise'"));
}
}
use of com.thoughtworks.go.config.exceptions.StageNotFoundException in project gocd by gocd.
the class ScheduleService method scheduleStage.
public Stage scheduleStage(final Pipeline pipeline, final String stageName, final String username, final StageInstanceCreator creator, final ErrorConditionHandler errorHandler) {
return (Stage) transactionTemplate.execute((TransactionCallback) status -> {
String pipelineName = pipeline.getName();
PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(stageName));
if (stageConfig == null) {
throw new StageNotFoundException(pipelineName, stageName);
}
SchedulingContext context = schedulingContext(username, pipelineConfig, stageConfig);
pipelineLockService.lockIfNeeded(pipeline);
Stage instance = null;
try {
instance = creator.create(pipelineName, stageName, context);
LOGGER.info("[Stage Schedule] Scheduling stage {} for pipeline {}", stageName, pipeline.getName());
} catch (CannotScheduleException e) {
serverHealthService.update(stageSchedulingFailedState(pipelineName, e));
errorHandler.cantSchedule(e, pipelineName);
}
serverHealthService.update(stageSchedulingSuccessfulState(pipelineName, stageName));
stageService.save(pipeline, instance);
return instance;
});
}
Aggregations