Search in sources :

Example 6 with HealthStateScope

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"));
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) Test(org.junit.Test)

Example 7 with HealthStateScope

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));
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) Test(org.junit.Test)

Example 8 with HealthStateScope

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);
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) DefaultGoApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse)

Example 9 with HealthStateScope

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)));
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) MDUPerformanceLogger(com.thoughtworks.go.server.perf.MDUPerformanceLogger) GoConfigWatchList(com.thoughtworks.go.config.GoConfigWatchList) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Aggregations

HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)9 Test (org.junit.Test)4 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)2 GoConfigWatchList (com.thoughtworks.go.config.GoConfigWatchList)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)1 ConfigChangedListener (com.thoughtworks.go.listener.ConfigChangedListener)1 EntityConfigChangedListener (com.thoughtworks.go.listener.EntityConfigChangedListener)1 DefaultGoApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse)1 Result (com.thoughtworks.go.plugin.api.response.Result)1 MDUPerformanceLogger (com.thoughtworks.go.server.perf.MDUPerformanceLogger)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1