Search in sources :

Example 6 with HealthStateType

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);
}
Also used : HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) Pipeline(com.thoughtworks.go.domain.Pipeline)

Example 7 with 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;
}
Also used : PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 8 with HealthStateType

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);
    }
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType)

Example 9 with HealthStateType

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);
}
Also used : ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 10 with HealthStateType

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);
}
Also used : HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonReader(com.thoughtworks.go.api.representers.JsonReader) Request(spark.Request) SparkSpringController(com.thoughtworks.go.spark.spring.SparkSpringController) NullStage(com.thoughtworks.go.domain.NullStage) ApiVersion(com.thoughtworks.go.api.ApiVersion) Routes(com.thoughtworks.go.spark.Routes) Stage(com.thoughtworks.go.domain.Stage) ApiController(com.thoughtworks.go.api.ApiController) GsonTransformer(com.thoughtworks.go.api.util.GsonTransformer) StageInstancesRepresenter(com.thoughtworks.go.apiv3.stageinstance.representers.StageInstancesRepresenter) StageRepresenter(com.thoughtworks.go.apiv3.stageinstance.representers.StageRepresenter) JobInstance(com.thoughtworks.go.domain.JobInstance) PipelineRunIdInfo(com.thoughtworks.go.domain.PipelineRunIdInfo) HaltApiResponses(com.thoughtworks.go.api.util.HaltApiResponses) Set(java.util.Set) IOException(java.io.IOException) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) Collectors(java.util.stream.Collectors) ApiAuthenticationHelper(com.thoughtworks.go.api.spring.ApiAuthenticationHelper) Component(org.springframework.stereotype.Component) List(java.util.List) HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) Response(spark.Response) Optional(java.util.Optional) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ScheduleService(com.thoughtworks.go.server.service.ScheduleService) StageService(com.thoughtworks.go.server.service.StageService) Spark(spark.Spark) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) JsonReader(com.thoughtworks.go.api.representers.JsonReader) NullStage(com.thoughtworks.go.domain.NullStage) Stage(com.thoughtworks.go.domain.Stage) 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