Search in sources :

Example 16 with ServerHealthState

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

the class ScheduledPipelineLoader method pipelineWithPasswordAwareBuildCauseByBuildId.

// TODO: Do we need to do this differently than PipelineService#fullPipeline?
public Pipeline pipelineWithPasswordAwareBuildCauseByBuildId(final long buildId) {
    Pipeline pipeline = pipelineDao.pipelineWithMaterialsAndModsByBuildId(buildId);
    MaterialRevisions scheduledRevs = pipeline.getBuildCause().getMaterialRevisions();
    MaterialConfigs knownMaterials = knownMaterials(pipeline, scheduledRevs);
    for (MaterialRevision materialRevision : scheduledRevs) {
        MaterialConfig materialConfig = materialFrom(knownMaterials, materialRevision);
        Material usedMaterial = materialRevision.getMaterial();
        if (materialConfig == null) {
            final JobInstance jobInstance = jobInstanceService.buildByIdWithTransitions(buildId);
            scheduleService.failJob(jobInstance);
            final String message = "Cannot load job '" + jobInstance.buildLocator() + "' because material " + usedMaterial.config() + " was not found in config.";
            final String description = "Job for pipeline '" + jobInstance.buildLocator() + "' has been failed as one or more material configurations were either changed or removed.";
            transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {

                @Override
                public void afterCommit() {
                    final ServerHealthState error = ServerHealthState.error(message, description, HealthStateType.general(HealthStateScope.forJob(jobInstance.getPipelineName(), jobInstance.getStageName(), jobInstance.getName())));
                    error.setTimeout(Timeout.FIVE_MINUTES);
                    serverHealthService.update(error);
                    appendToConsoleLog(jobInstance, message);
                    appendToConsoleLog(jobInstance, description);
                }
            });
            throw new StaleMaterialsOnBuildCause(message);
        }
        usedMaterial.updateFromConfig(materialConfig);
    }
    return pipeline;
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) JobInstance(com.thoughtworks.go.domain.JobInstance) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) StaleMaterialsOnBuildCause(com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) Material(com.thoughtworks.go.domain.materials.Material) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Pipeline(com.thoughtworks.go.domain.Pipeline)

Example 17 with ServerHealthState

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

the class ServerHealthRequestProcessor method replaceServerHealthMessages.

private void replaceServerHealthMessages(String errorMessageTitle, HealthStateScope scope, List<PluginHealthMessage> pluginHealthMessages) {
    serverHealthService.removeByScope(scope);
    for (int index = 0; index < pluginHealthMessages.size(); index++) {
        PluginHealthMessage pluginHealthMessage = pluginHealthMessages.get(index);
        ServerHealthState state;
        if (pluginHealthMessage.isWarning()) {
            state = ServerHealthState.warning(errorMessageTitle, pluginHealthMessage.message(), HealthStateType.withSubkey(scope, "message_" + index));
        } else {
            state = ServerHealthState.error(errorMessageTitle, pluginHealthMessage.message(), HealthStateType.withSubkey(scope, "message_" + index));
        }
        serverHealthService.update(state);
    }
}
Also used : ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 18 with ServerHealthState

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

the class DiskSpaceOperationResult method error.

public ServerHealthState error(String message, String description, HealthStateType type) {
    ServerHealthState state = ServerHealthState.error(message, description, type);
    serverHealthService.update(state);
    canContinue = false;
    return state;
}
Also used : ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 19 with ServerHealthState

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

the class ServerHealthInformationProvider method asJson.

@Override
public Map<String, Object> asJson() {
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();
    ServerHealthStates allLogs = service.logs();
    json.put("Messages Count", allLogs.size());
    ArrayList<Map<String, String>> messages = new ArrayList<>();
    for (ServerHealthState log : allLogs) {
        messages.add(log.asJson());
    }
    json.put("Messages", messages);
    return json;
}
Also used : ArrayList(java.util.ArrayList) ServerHealthStates(com.thoughtworks.go.serverhealth.ServerHealthStates) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with ServerHealthState

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

the class ManualBuild method canProduce.

public void canProduce(PipelineConfig pipelineConfig, SchedulingCheckerService schedulingChecker, ServerHealthService serverHealthService, OperationResult operationResult) {
    schedulingChecker.canTriggerManualPipeline(pipelineConfig, CaseInsensitiveString.str(username.getUsername()), operationResult);
    if (!operationResult.canContinue()) {
        ServerHealthState serverHealthState = operationResult.getServerHealthState();
        LOGGER.info("'{}'  because '{}'", serverHealthState.getMessage(), serverHealthState.getDescription());
        serverHealthService.update(serverHealthState);
    }
}
Also used : ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Aggregations

ServerHealthState (com.thoughtworks.go.serverhealth.ServerHealthState)25 Test (org.junit.Test)10 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)3 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)3 Material (com.thoughtworks.go.domain.materials.Material)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)2 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)2 StaleMaterialsOnBuildCause (com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause)2 Gson (com.google.gson.Gson)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 TimerConfig (com.thoughtworks.go.config.TimerConfig)1 Materials (com.thoughtworks.go.config.materials.Materials)1 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)1 P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1