use of com.thoughtworks.go.serverhealth.HealthStateScope in project gocd by gocd.
the class ConfigReposMaterialParseResultManager method markFailedResultsForReparse.
/**
* After a successful update of the server config, we should reparse any failed config-repos in case
* any upstream dependency issues have been resolved.
* <p>
* This clears the last parse states and errors related to config-repos so as to allow reparsing. Should be
* used by ConfigChangedListener and EntityConfigChangedListener instances to hook into config update events.
*/
void markFailedResultsForReparse() {
for (Map.Entry<String, PartialConfigParseResult> entry : fingerprintOfPartialToParseResultMap.entrySet()) {
String fingerprint = entry.getKey();
PartialConfigParseResult result = entry.getValue();
HealthStateScope scope = HealthStateScope.forPartialConfigRepo(fingerprint);
List<ServerHealthState> serverHealthErrors = serverHealthService.filterByScope(scope);
if (!serverHealthErrors.isEmpty() || !result.isSuccessful()) {
// clear modification to allow a reparse to happen
result.setLatestParsedModification(null);
}
}
}
use of com.thoughtworks.go.serverhealth.HealthStateScope in project gocd by gocd.
the class GoConfigRepoConfigDataSource method onCheckoutComplete.
public void onCheckoutComplete(MaterialConfig material, File folder, Modification modification) {
// 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) {
this.configReposMaterialParseResultManager.parseFailed(fingerprint, modification, 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.getPluginId(), 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 {
this.modifiedConfigRepoConfigsAwaitingParse.remove(repoConfig);
// 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, modification.getRevision()));
this.configReposMaterialParseResultManager.parseSuccess(fingerprint, modification, newPart);
// it is the responsibility of the success listeners to clear the ServerHealthState
notifySuccessListeners(repoConfig, newPart);
} catch (Exception ex) {
this.configReposMaterialParseResultManager.parseFailed(fingerprint, modification, 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 ConfigReposMaterialParseResultManagerTest method markForReparseShouldClearLastModificationAndHealthErrors.
@Test
void markForReparseShouldClearLastModificationAndHealthErrors() {
String fingerprint = "repo1";
HealthStateScope scope = HealthStateScope.forPartialConfigRepo(fingerprint);
ServerHealthState error = ServerHealthState.error("boom", "bang!", HealthStateType.general(scope));
when(serverHealthService.filterByScope(scope)).thenReturn(Collections.singletonList(error));
Modification modification = modificationFor("rev1");
manager.parseFailed(fingerprint, modification, new Exception());
PartialConfigParseResult result = manager.get(fingerprint);
assertNotNull(result);
assertFalse(result.isSuccessful());
assertNotNull(result.getLatestParsedModification());
assertEquals(result.getLatestParsedModification(), modification);
manager.markFailedResultsForReparse();
assertNull(result.getLatestParsedModification());
verify(serverHealthService, never()).removeByScope(scope);
}
use of com.thoughtworks.go.serverhealth.HealthStateScope in project gocd by gocd.
the class ElasticAgentPluginServiceTest method shouldRemoveExistingMissingPluginErrorFromAPreviousAttemptIfThePluginIsNowRegistered.
@Test
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<>(), asList(plan1));
verify(createAgentQueue, times(1)).post(any(), ttl.capture());
verify(serverHealthService).removeByScope(captor.capture());
HealthStateScope healthStateScope = captor.getValue();
assertThat(healthStateScope.getScope()).isEqualTo("pipeline-1/stage/job");
}
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 = svn("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, maintenanceModeService, null, null);
materialUpdateService.onConfigChange(configWithMaterial(goodMaterial));
assertThat(serverHealthService, ServerHealthMatcher.containsState(HealthStateType.general(goodScope)));
}
Aggregations