Search in sources :

Example 1 with HealthStateScope

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

the class PluginNotificationService method notifyPlugin.

private <T> void notifyPlugin(String pluginId, PluginNotificationMessage<T> pluginNotificationMessage) {
    HealthStateScope scope = HealthStateScope.aboutPlugin(pluginId);
    try {
        Result result = notificationExtension.notify(pluginId, pluginNotificationMessage.getRequestName(), pluginNotificationMessage.getData());
        if (result.isSuccessful()) {
            serverHealthService.removeByScope(scope);
        } else {
            String errorDescription = result.getMessages() == null ? null : StringUtils.join(result.getMessages(), ", ");
            handlePluginNotifyError(pluginId, scope, errorDescription, null);
        }
    } catch (Exception e) {
        String errorDescription = e.getMessage() == null ? "Unknown error" : e.getMessage();
        handlePluginNotifyError(pluginId, scope, errorDescription, e);
    }
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) Result(com.thoughtworks.go.plugin.api.response.Result)

Example 2 with HealthStateScope

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

the class GoRepoConfigDataSource method onCheckoutComplete.

public void onCheckoutComplete(MaterialConfig material, File folder, String revision) {
    // called when pipelines/flyweight/[flyweight] has a clean checkout of latest material
    // Having modifications in signature might seem like an overkill
    // but on the other hand if plugin is smart enough it could
    // parse only files that have changed, which is a huge performance gain where there are many pipelines
    /* if this is material listed in config-repos
           Then ask for config plugin implementation
           Give it the directory and store partial config
           post event about completed (successful or not) parsing
         */
    String fingerprint = material.getFingerprint();
    if (this.configWatchList.hasConfigRepoWithFingerprint(fingerprint)) {
        PartialConfigProvider plugin = null;
        ConfigRepoConfig repoConfig = configWatchList.getConfigRepoForMaterial(material);
        HealthStateScope scope = HealthStateScope.forPartialConfigRepo(repoConfig);
        try {
            plugin = this.configPluginService.partialConfigProviderFor(repoConfig);
        } catch (Exception ex) {
            fingerprintOfPartialToLatestParseResultMap.put(fingerprint, new PartialConfigParseResult(revision, ex));
            LOGGER.error("Failed to get config plugin for {}", material.getDisplayName());
            String message = String.format("Failed to obtain configuration plugin '%s' for material: %s", repoConfig.getConfigProviderPluginName(), material.getLongDescription());
            String errorDescription = ex.getMessage() == null ? ex.toString() : ex.getMessage();
            serverHealthService.update(ServerHealthState.error(message, errorDescription, HealthStateType.general(scope)));
            notifyFailureListeners(repoConfig, ex);
            return;
        }
        try {
            // TODO put modifications and previous partial config in context
            // the context is just a helper for plugin.
            PartialConfigLoadContext context = new LoadContext(repoConfig);
            PartialConfig newPart = plugin.load(folder, context);
            if (newPart == null) {
                LOGGER.warn("Parsed configuration material {} by {} is null", material.getDisplayName(), plugin.displayName());
                newPart = new PartialConfig();
            }
            newPart.setOrigins(new RepoConfigOrigin(repoConfig, revision));
            fingerprintOfPartialToLatestParseResultMap.put(fingerprint, new PartialConfigParseResult(revision, newPart));
            serverHealthService.removeByScope(scope);
            notifySuccessListeners(repoConfig, newPart);
        } catch (Exception ex) {
            fingerprintOfPartialToLatestParseResultMap.put(fingerprint, new PartialConfigParseResult(revision, ex));
            LOGGER.error("Failed to parse configuration material {} by {}", material.getDisplayName(), plugin.displayName(), ex);
            String message = String.format("Parsing configuration repository using %s failed for material: %s", plugin.displayName(), material.getLongDescription());
            String errorDescription = ex.getMessage() == null ? ex.toString() : ex.getMessage();
            serverHealthService.update(ServerHealthState.error(message, errorDescription, HealthStateType.general(scope)));
            notifyFailureListeners(repoConfig, ex);
        }
    }
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin)

Example 3 with HealthStateScope

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

the class ScheduledPipelineLoader method updateServerHealthStateToError.

private void updateServerHealthStateToError(JobInstance jobInstance, String message, String description) {
    HealthStateScope scope = forJob(jobInstance.getPipelineName(), jobInstance.getStageName(), jobInstance.getName());
    final ServerHealthState error = error(message, description, general(scope));
    error.setTimeout(Timeout.FIVE_MINUTES);
    serverHealthService.update(error);
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 4 with HealthStateScope

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

the class InvalidConfigMessageRemoverTest method shouldRemoveServerHealthServiceMessageAboutStartedWithInvalidConfigurationOnPipelineConfigSave.

@Test
public void shouldRemoveServerHealthServiceMessageAboutStartedWithInvalidConfigurationOnPipelineConfigSave() {
    GoConfigService goConfigService = mock(GoConfigService.class);
    ServerHealthService serverHealthService = mock(ServerHealthService.class);
    ArgumentCaptor<ConfigChangedListener> configChangedListenerArgumentCaptor = ArgumentCaptor.forClass(ConfigChangedListener.class);
    doNothing().when(goConfigService).register(configChangedListenerArgumentCaptor.capture());
    InvalidConfigMessageRemover invalidConfigMessageRemover = new InvalidConfigMessageRemover(goConfigService, serverHealthService);
    invalidConfigMessageRemover.initialize();
    invalidConfigMessageRemover.onConfigChange(null);
    List<ConfigChangedListener> listeners = configChangedListenerArgumentCaptor.getAllValues();
    assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
    EntityConfigChangedListener listener = (EntityConfigChangedListener) listeners.get(1);
    assertThat(listener.shouldCareAbout(mock(PipelineConfig.class)), is(true));
    invalidConfigMessageRemover.pipelineConfigChangedListener().onEntityConfigChange(mock(PipelineConfig.class));
    ArgumentCaptor<HealthStateScope> captor = ArgumentCaptor.forClass(HealthStateScope.class);
    verify(serverHealthService).removeByScope(captor.capture());
    assertThat(captor.getValue().compareTo(HealthStateScope.forInvalidConfig()), is(0));
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.jupiter.api.Test)

Example 5 with HealthStateScope

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

the class MaterialUpdateServiceIntegrationTest method shouldClearServerHealthLogsForMaterialWhereAutoUpdateChanged.

@Test
public void shouldClearServerHealthLogsForMaterialWhereAutoUpdateChanged() throws Exception {
    SvnMaterialConfig material = svn("non-existent-url!", "user", "pwd2", false);
    HealthStateScope scope = HealthStateScope.forMaterialConfig(material);
    serverHealthService.update(ServerHealthState.error("where's the material!", "fubar", HealthStateType.general(scope)));
    material.setAutoUpdate(false);
    MaterialUpdateService materialUpdateService = new MaterialUpdateService(null, null, mock(MaterialUpdateCompletedTopic.class), mock(GoConfigWatchList.class), mock(GoConfigService.class), systemEnvironment, serverHealthService, null, mock(MDUPerformanceLogger.class), materialConfigConverter, null, maintenanceModeService, null, null);
    materialUpdateService.onConfigChange(configWithMaterial(material));
    assertThat(serverHealthService, ServerHealthMatcher.doesNotContainState(HealthStateType.general(scope)));
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) MDUPerformanceLogger(com.thoughtworks.go.server.perf.MDUPerformanceLogger) GoConfigWatchList(com.thoughtworks.go.config.GoConfigWatchList) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.jupiter.api.Test)

Aggregations

HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)21 Test (org.junit.jupiter.api.Test)8 ServerHealthState (com.thoughtworks.go.serverhealth.ServerHealthState)7 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)3 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)3 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)3 GoConfigWatchList (com.thoughtworks.go.config.GoConfigWatchList)2 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)2 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)2 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Result (com.thoughtworks.go.plugin.api.response.Result)2 MDUPerformanceLogger (com.thoughtworks.go.server.perf.MDUPerformanceLogger)2 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)2 ApiController (com.thoughtworks.go.api.ApiController)1 ApiVersion (com.thoughtworks.go.api.ApiVersion)1 ApiAuthenticationHelper (com.thoughtworks.go.api.spring.ApiAuthenticationHelper)1 MessageJson (com.thoughtworks.go.api.util.MessageJson)1 MaterialInfo (com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo)1 MaterialWithModificationsRepresenter (com.thoughtworks.go.apiv1.internalmaterials.representers.MaterialWithModificationsRepresenter)1