Search in sources :

Example 16 with HealthStateScope

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);
        }
    }
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 17 with HealthStateScope

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);
        }
    }
}
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 18 with HealthStateScope

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);
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) Modification(com.thoughtworks.go.domain.materials.Modification) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with HealthStateScope

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

Example 20 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 = 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)));
}
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.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