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