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