Search in sources :

Example 1 with ServerHealthState

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

the class HttpOperationResult method detailedMessage.

public String detailedMessage() {
    //cache me if gc mandates so -jj
    ServerHealthState serverHealthState = serverHealthStateOperationResult.getServerHealthState();
    String desc = serverHealthState == null ? BLANK_STRING : serverHealthState.getDescription();
    return StringUtil.isBlank(desc) ? message + "\n" : String.format("%s { %s }\n", message, desc);
}
Also used : ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 2 with ServerHealthState

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

the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.

@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
    String pipelineName = "pipeline";
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
    Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
    config.materialConfigs().clear();
    config.addMaterialConfig(svnMaterial.config());
    config.addMaterialConfig(dependencyMaterial.config());
    when(pipelineService.getRevisionsBasedOnDependencies(Matchers.<MaterialRevisions>any(), Matchers.<BasicCruiseConfig>any(), Matchers.<CaseInsensitiveString>any())).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
    when(pipelineScheduleQueue.mostRecentScheduled(pipelineName)).thenReturn(BuildCause.createNeverRun());
    Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
    when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
    when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
    when(specificMaterialRevisionFactory.create(Matchers.<String>any(), Matchers.<Map<String, String>>any())).thenReturn(MaterialRevisions.EMPTY);
    when(goConfigService.upstreamDependencyGraphOf(Matchers.<String>any(), Matchers.<BasicCruiseConfig>any())).thenReturn(new PipelineConfigDependencyGraph(config));
    MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
    Materials materials = new Materials(svnMaterial, dependencyMaterial);
    when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
    when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
    when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null);
    ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
    assertThat(serverHealthState.isSuccess(), is(true));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) Test(org.junit.Test)

Example 3 with ServerHealthState

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

the class MaterialDatabaseUpdaterTest method shouldThrowExceptionWithLongDescriptionOfMaterialWhenUpdateFails.

@Test
public void shouldThrowExceptionWithLongDescriptionOfMaterialWhenUpdateFails() throws Exception {
    Material material = new GitMaterial("url", "branch");
    Exception exception = new RuntimeException("failed");
    String message = "Modification check failed for material: " + material.getLongDescription();
    ServerHealthState error = ServerHealthState.error(message, exception.getMessage(), HealthStateType.general(HealthStateScope.forMaterial(material)));
    when(materialRepository.findMaterialInstance(material)).thenThrow(exception);
    try {
        materialDatabaseUpdater.updateMaterial(material);
        fail("should have thrown exception");
    } catch (Exception e) {
        assertThat(e, is(exception));
    }
    verify(healthService).update(error);
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Material(com.thoughtworks.go.domain.materials.Material) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.Test)

Example 4 with ServerHealthState

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

the class ElasticAgentPluginServiceTest method shouldReportMissingElasticPlugin.

@Test
public void shouldReportMissingElasticPlugin() {
    JobPlan plan1 = plan(1, "missing");
    ArgumentCaptor<ServerHealthState> captorForHealthState = ArgumentCaptor.forClass(ServerHealthState.class);
    service.createAgentsFor(new ArrayList<>(), Arrays.asList(plan1));
    verify(serverHealthService).update(captorForHealthState.capture());
    ServerHealthState serverHealthState = captorForHealthState.getValue();
    assertThat(serverHealthState.getDescription(), is("Plugin [missing] associated with JobConfigIdentifier[pipeline-1:stage:job] is missing. Either the plugin is not installed or could not be registered. Please check plugins tab and server logs for more details."));
    assertThat(serverHealthState.getLogLevel(), is(HealthStateLevel.ERROR));
    assertThat(serverHealthState.getMessage(), is("Unable to find agent for JobConfigIdentifier[pipeline-1:stage:job]"));
    verifyZeroInteractions(createAgentQueue);
}
Also used : ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.Test)

Example 5 with ServerHealthState

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

the class ServerHealthRequestProcessorTest method shouldAddDeserializedServerHealthMessages.

@Test
public void shouldAddDeserializedServerHealthMessages() {
    String requestBody = new Gson().toJson(asList(new PluginHealthMessage("warning", "message 1"), new PluginHealthMessage("error", "message 2")));
    GoApiResponse response = processor.process(descriptor, createRequest("1.0", requestBody));
    assertThat(response.responseCode()).isEqualTo(SUCCESS_RESPONSE_CODE);
    ArgumentCaptor<ServerHealthState> argumentCaptor = ArgumentCaptor.forClass(ServerHealthState.class);
    InOrder inOrder = inOrder(serverHealthService);
    inOrder.verify(serverHealthService, times(1)).removeByScope(HealthStateScope.fromPlugin(PLUGIN_ID));
    inOrder.verify(serverHealthService, times(2)).update(argumentCaptor.capture());
    assertThat(argumentCaptor.getAllValues().get(0).getDescription()).isEqualTo("message 1");
    assertThat(argumentCaptor.getAllValues().get(1).getDescription()).isEqualTo("message 2");
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) InOrder(org.mockito.InOrder) Gson(com.google.gson.Gson) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.Test)

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