use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.
the class StageManualTriggerChecker method check.
@Override
public void check(OperationResult result) {
HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forPipeline(pipelineName));
Pipeline pipeline = pipelineService.fullPipelineByCounter(pipelineName, pipelineCounter);
ScheduleStageResult scheduleStageResult = schedulingCheckerService.shouldAllowSchedulingStage(pipeline, stageName);
if (scheduleStageResult == ScheduleStageResult.PreviousStageNotPassed) {
String errorMessage = String.format("Cannot schedule %s as the previous stage %s has %s!", stageName, scheduleStageResult.getPreviousStageName(), scheduleStageResult.getPreviousStageResult());
healthStateType = HealthStateType.forbidden();
result.notAcceptable(errorMessage, healthStateType);
return;
}
result.success(healthStateType);
}
use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.
the class ScheduleOptionsBuilder method build.
public ScheduleOptions build(HttpOperationResult result, String pipelineName, PipelineScheduleOptions pipelineScheduleOptions) {
ScheduleOptions scheduleOptions = new ScheduleOptions();
HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forPipeline(pipelineName));
if (!goConfigService.hasPipelineNamed(new CaseInsensitiveString(pipelineName))) {
result.notFound(String.format("Pipeline '%s' not found.", pipelineName), "", healthStateType);
return null;
}
for (Builder builder : builders) {
if (result.canContinue())
builder.build(scheduleOptions, result, pipelineName, pipelineScheduleOptions, healthStateType);
}
return scheduleOptions;
}
use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.
the class AboutToBeTriggeredChecker method check.
@Override
public void check(OperationResult result) {
String pipelineNameString = CaseInsensitiveString.str(pipelineName);
HealthStateType type = HealthStateType.general(HealthStateScope.forPipeline(pipelineNameString));
if (triggerMonitor.isAlreadyTriggered(pipelineName) || pipelineScheduleQueue.hasForcedBuildCause(pipelineName)) {
result.conflict("Failed to trigger pipeline: " + pipelineName, "Pipeline already triggered", HealthStateType.general(HealthStateScope.forPipeline(pipelineNameString)));
} else {
result.success(type);
}
}
use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.
the class MaterialDatabaseDependencyUpdaterTest method shouldUpdateServerHealthIfCheckFails.
@Test
public void shouldUpdateServerHealthIfCheckFails() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
RuntimeException runtimeException = new RuntimeException("Description of error");
Mockito.when(dependencyMaterialSourceDao.getPassedStagesByName(new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name")), Pagination.pageStartingAt(0, null, MaterialDatabaseUpdater.STAGES_PER_PAGE))).thenThrow(runtimeException);
try {
updater.updateMaterial(dependencyMaterial);
fail("should have thrown exception " + runtimeException.getMessage());
} catch (Exception e) {
assertSame(e, runtimeException);
}
HealthStateType scope = HealthStateType.general(HealthStateScope.forMaterial(dependencyMaterial));
ServerHealthState state = ServerHealthState.errorWithHtml("Modification check failed for material: pipeline-name [ stage-name ]\nNo pipelines are affected by this material, perhaps this material is unused.", "Description of error", scope);
Mockito.verify(healthService).update(state);
}
use of com.thoughtworks.go.serverhealth.HealthStateType in project gocd by gocd.
the class StageInstanceControllerV3 method rerunSelectedJobs.
public String rerunSelectedJobs(Request req, Response res) throws IOException {
HttpOperationResult result = new HttpOperationResult();
haltIfRequestBodyDoesNotContainPropertyJobs(req);
JsonReader requestBody = GsonTransformer.getInstance().jsonReaderFrom(req.body());
List<String> requestedJobs = requestBody.readStringArrayIfPresent(JOB_NAMES_PROPERTY).get();
Optional<Stage> optionalStage = getStageFromRequestParam(req, result);
optionalStage.ifPresent(stage -> {
HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forStage(stage.getIdentifier().getPipelineName(), stage.getName()));
Set<String> jobsInStage = stage.getJobInstances().stream().map(JobInstance::getName).collect(Collectors.toSet());
List<String> unknownJobs = requestedJobs.stream().filter(jobToRun -> !jobsInStage.contains(jobToRun)).collect(Collectors.toList());
if (unknownJobs.isEmpty()) {
scheduleService.rerunJobs(stage, requestedJobs, result);
} else {
String msg = String.format("Job(s) %s does not exist in stage '%s'.", unknownJobs, stage.getIdentifier().getStageLocator());
result.notFound(msg, "", healthStateType);
}
});
return renderHTTPOperationResult(result, req, res);
}
Aggregations