Search in sources :

Example 1 with HealthStateType

use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.

the class ScheduleService method rerunStage.

/**
 * Top-level operation only; consumes exceptions
 */
public Stage rerunStage(String pipelineName, Integer pipelineCounter, String stageName, HttpOperationResult result) {
    String identifier = StringUtils.join(Arrays.asList(pipelineName, pipelineCounter, stageName), "/");
    HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forStage(pipelineName, stageName));
    Stage stage = null;
    try {
        stage = rerunStage(pipelineName, pipelineCounter, stageName, new ResultUpdatingErrorHandler(result));
        if (result.isSuccess()) {
            // this check is for clarity, but is not needed as failures result in RunTimeExceptions
            result.accepted(String.format("Request to schedule stage %s accepted", identifier), "", healthStateType);
        }
    } catch (RuntimeException e) {
        // else the result is assumed to contain the right status code and error message
        if (result.isSuccess()) {
            String message = String.format("Stage rerun request for stage [%s] could not be completed " + "because of an unexpected failure. Cause: %s", identifier, e.getMessage());
            LOGGER.error(message, e);
            result.internalServerError(message, healthStateType);
        }
    }
    return stage;
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType)

Example 2 with HealthStateType

use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.

the class ScheduleService method rerunJobs.

/**
 * IMPORTANT: this method is only meant for TOP level usage(never use this within a transaction). It gobbles exception.
 */
public Stage rerunJobs(final Stage stage, final List<String> jobNames, final HttpOperationResult result) {
    final StageIdentifier identifier = stage.getIdentifier();
    HealthStateType healthStateForStage = HealthStateType.general(HealthStateScope.forStage(identifier.getPipelineName(), identifier.getStageName()));
    if (jobNames == null || jobNames.isEmpty()) {
        String message = "No job was selected to re-run.";
        result.badRequest(message, message, healthStateForStage);
        return null;
    }
    try {
        Stage resultStage = lockAndRerunStage(identifier.getPipelineName(), identifier.getPipelineCounter(), identifier.getStageName(), (pipelineName, stageName, context) -> {
            StageConfig stageConfig = goConfigService.stageConfigNamed(identifier.getPipelineName(), identifier.getStageName());
            String latestMd5 = goConfigService.getCurrentConfig().getMd5();
            try {
                return instanceFactory.createStageForRerunOfJobs(stage, jobNames, context, stageConfig, timeProvider, latestMd5);
            } catch (CannotRerunJobException e) {
                result.notFound(e.getMessage(), e.getMessage(), healthStateForStage);
                throw e;
            }
        }, new ResultUpdatingErrorHandler(result));
        result.accepted(String.format("Request to rerun jobs accepted", identifier), "", healthStateForStage);
        return resultStage;
    } catch (RuntimeException e) {
        if (result.canContinue()) {
            String message = String.format("Job rerun request for job(s) [%s] could not be completed because of unexpected failure. Cause: %s", StringUtils.join(jobNames.toArray(), ", "), e.getMessage());
            result.internalServerError(message, healthStateForStage);
            LOGGER.error(message, e);
        }
        return null;
    }
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) StageConfig(com.thoughtworks.go.config.StageConfig)

Example 3 with HealthStateType

use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.

the class PipelinePauseChecker method check.

@Override
public void check(OperationResult result) {
    HealthStateType id = HealthStateType.general(HealthStateScope.forPipeline(pipelineName));
    if (pipelinePauseService.isPaused(pipelineName)) {
        String message = String.format("Failed to trigger pipeline [%s]", pipelineName);
        result.conflict(message, String.format("Pipeline %s is paused", pipelineName), id);
    } else {
        result.success(id);
    }
}
Also used : HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType)

Example 4 with HealthStateType

use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.

the class StageActiveChecker method check.

@Override
public void check(OperationResult result) {
    HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forPipeline(pipelineName));
    if (stageService.isStageActive(pipelineName, stageName)) {
        String message = String.format("Failed to trigger pipeline [%s]", pipelineName);
        result.conflict(message, String.format("Stage [%s] in pipeline [%s] is still in progress", stageName, pipelineName), healthStateType);
    } else {
        result.success(healthStateType);
    }
}
Also used : HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType)

Example 5 with HealthStateType

use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.

the class PipelineActiveChecker method check.

@Override
public void check(OperationResult result) {
    HealthStateType id = HealthStateType.general(HealthStateScope.forPipeline(pipelineIdentifier.getName()));
    if (stageService.isAnyStageActiveForPipeline(pipelineIdentifier)) {
        String description = String.format("Pipeline[name='%s', counter='%s', label='%s'] is still in progress", pipelineIdentifier.getName(), pipelineIdentifier.getCounter(), pipelineIdentifier.getLabel());
        String message = String.format("Failed to trigger pipeline [%s]", pipelineIdentifier.getName());
        result.error(message, description, id);
    } else {
        result.success(id);
    }
}
Also used : HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType)

Aggregations

HealthStateType (com.thoughtworks.go.serverhealth.HealthStateType)15 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 Test (org.junit.jupiter.api.Test)3 ApiController (com.thoughtworks.go.api.ApiController)1 ApiVersion (com.thoughtworks.go.api.ApiVersion)1 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 ApiAuthenticationHelper (com.thoughtworks.go.api.spring.ApiAuthenticationHelper)1 GsonTransformer (com.thoughtworks.go.api.util.GsonTransformer)1 HaltApiResponses (com.thoughtworks.go.api.util.HaltApiResponses)1 StageInstancesRepresenter (com.thoughtworks.go.apiv3.stageinstance.representers.StageInstancesRepresenter)1 StageRepresenter (com.thoughtworks.go.apiv3.stageinstance.representers.StageRepresenter)1 StageConfig (com.thoughtworks.go.config.StageConfig)1 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 NullStage (com.thoughtworks.go.domain.NullStage)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 PipelineRunIdInfo (com.thoughtworks.go.domain.PipelineRunIdInfo)1 Stage (com.thoughtworks.go.domain.Stage)1 ArtifactsDiskIsFull (com.thoughtworks.go.fixture.ArtifactsDiskIsFull)1 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)1