Search in sources :

Example 1 with StageNotFoundException

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'"));
    }
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) StageNotFoundException(com.thoughtworks.go.config.exceptions.StageNotFoundException) Test(org.junit.jupiter.api.Test)

Example 2 with StageNotFoundException

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;
    });
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) StageNotFoundException(com.thoughtworks.go.config.exceptions.StageNotFoundException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageConfig(com.thoughtworks.go.config.StageConfig)

Aggregations

StageNotFoundException (com.thoughtworks.go.config.exceptions.StageNotFoundException)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 StageConfig (com.thoughtworks.go.config.StageConfig)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 Test (org.junit.jupiter.api.Test)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1