use of com.thoughtworks.go.serverhealth.HealthStateScope in project gocd by gocd.
the class ElasticAgentPluginServiceTest method shouldRemoveExistingMissingPluginErrorFromAPreviousAttemptIfThePluginIsNowRegistered.
@Test
public void shouldRemoveExistingMissingPluginErrorFromAPreviousAttemptIfThePluginIsNowRegistered() {
JobPlan plan1 = plan(1, "docker");
ArgumentCaptor<HealthStateScope> captor = ArgumentCaptor.forClass(HealthStateScope.class);
ArgumentCaptor<Long> ttl = ArgumentCaptor.forClass(Long.class);
service.createAgentsFor(new ArrayList<>(), Arrays.asList(plan1));
verify(createAgentQueue, times(1)).post(any(), ttl.capture());
verify(serverHealthService).removeByScope(captor.capture());
HealthStateScope healthStateScope = captor.getValue();
assertThat(healthStateScope.getScope(), is("pipeline-1/stage/job"));
}
use of com.thoughtworks.go.serverhealth.HealthStateScope in project gocd by gocd.
the class ServerHealthServiceTest method shouldRemoveLogByCategoryFromServerHealth.
@Test
public void shouldRemoveLogByCategoryFromServerHealth() throws Exception {
HealthStateScope scope = forPipeline(PIPELINE_NAME);
serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(scope)));
serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.invalidLicense(scope)));
serverHealthService.update(ServerHealthState.error("message", "description", globalId));
assertThat(serverHealthService.logs().size(), is(3));
serverHealthService.removeByScope(scope);
assertThat(serverHealthService.logs().size(), is(1));
assertThat(serverHealthService, ServerHealthMatcher.containsState(globalId));
}
use of com.thoughtworks.go.serverhealth.HealthStateScope in project gocd by gocd.
the class ServerHealthRequestProcessor method process.
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
String errorMessageTitle = format("Message from plugin: {0}", pluginDescriptor.id());
HealthStateScope scope = HealthStateScope.fromPlugin(pluginDescriptor.id());
try {
MessageHandlerForServerHealthRequestProcessor messageHandler = versionToMessageHandlerMap.get(goPluginApiRequest.apiVersion());
List<PluginHealthMessage> pluginHealthMessages = messageHandler.deserializeServerHealthMessages(goPluginApiRequest.requestBody());
replaceServerHealthMessages(errorMessageTitle, scope, pluginHealthMessages);
} catch (Exception e) {
DefaultGoApiResponse response = new DefaultGoApiResponse(DefaultGoApiResponse.INTERNAL_ERROR);
response.setResponseBody(format("'{' \"message\": \"{0}\" '}'", e.getMessage()));
LOGGER.warn("Failed to handle message from plugin {}: {}", pluginDescriptor.id(), goPluginApiRequest.requestBody(), e);
return response;
}
return new DefaultGoApiResponse(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
}
use of com.thoughtworks.go.serverhealth.HealthStateScope in project gocd by gocd.
the class MaterialUpdateServiceIntegrationTest method shouldClearServerHealthLogsForMaterialThatNoLongerExistsInCruiseConfig.
@Test
public void shouldClearServerHealthLogsForMaterialThatNoLongerExistsInCruiseConfig() throws Exception {
HealthStateScope badScope = HealthStateScope.forMaterial(new SvnMaterial("non-existent-url!", "user", "pwd", false));
serverHealthService.update(ServerHealthState.error("where's the material!", "fubar", HealthStateType.general(badScope)));
SvnMaterialConfig goodMaterial = new SvnMaterialConfig("good-url!", "user", "pwd", false);
HealthStateScope goodScope = HealthStateScope.forMaterialConfig(goodMaterial);
serverHealthService.update(ServerHealthState.error("could not update!", "why", HealthStateType.general(goodScope)));
MaterialUpdateService materialUpdateService = new MaterialUpdateService(null, null, mock(MaterialUpdateCompletedTopic.class), mock(GoConfigWatchList.class), mock(GoConfigService.class), systemEnvironment, serverHealthService, null, mock(MDUPerformanceLogger.class), materialConfigConverter, null);
materialUpdateService.onConfigChange(configWithMaterial(goodMaterial));
assertThat(serverHealthService, ServerHealthMatcher.containsState(HealthStateType.general(goodScope)));
}
Aggregations