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