Search in sources :

Example 11 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.jupiter.api.Test)

Example 12 with HealthStateScope

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

the class InternalMaterialsControllerV1 method createMergedMap.

private Map<MaterialConfig, MaterialInfo> createMergedMap(Map<MaterialConfig, Boolean> materialConfigs, Map<String, Modification> modificationsMap, Collection<MaintenanceModeService.MaterialPerformingMDU> runningMDUs, ServerHealthStates allLogs) {
    HashMap<MaterialConfig, MaterialInfo> map = new HashMap<>();
    if (materialConfigs.isEmpty()) {
        return map;
    }
    materialConfigs.forEach((materialConfig, hasOperatePermission) -> {
        if (!materialConfig.getType().equals(DependencyMaterialConfig.TYPE)) {
            Material material = materialConfigConverter.toMaterial(materialConfig);
            List<HealthStateScope> scopes = asList(forMaterial(material), forMaterialUpdate(material), forMaterialConfig(materialConfig));
            List<ServerHealthState> logs = allLogs.stream().filter((log) -> scopes.contains(log.getType().getScope())).collect(toList());
            Modification mod = modificationsMap.getOrDefault(materialConfig.getFingerprint(), null);
            MaintenanceModeService.MaterialPerformingMDU mduInfo = runningMDUs.stream().filter((mdu) -> mdu.getMaterial().getFingerprint().equals(materialConfig.getFingerprint())).findFirst().orElse(null);
            boolean isMDUInProgress = mduInfo != null;
            Timestamp updateStartTime = isMDUInProgress ? mduInfo.getTimestamp() : null;
            map.put(materialConfig, new MaterialInfo(mod, hasOperatePermission, isMDUInProgress, updateStartTime, logs));
        }
    });
    return map;
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) MaintenanceModeService(com.thoughtworks.go.server.service.MaintenanceModeService) Material(com.thoughtworks.go.domain.materials.Material) MaterialConfigConverter(com.thoughtworks.go.server.service.MaterialConfigConverter) Autowired(org.springframework.beans.factory.annotation.Autowired) MaterialInfo(com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo) HashMap(java.util.HashMap) MessageJson(com.thoughtworks.go.api.util.MessageJson) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ServerHealthStates(com.thoughtworks.go.serverhealth.ServerHealthStates) MaterialConfigService(com.thoughtworks.go.server.service.MaterialConfigService) Request(spark.Request) Arrays.asList(java.util.Arrays.asList) SparkSpringController(com.thoughtworks.go.spark.spring.SparkSpringController) Map(java.util.Map) ApiVersion(com.thoughtworks.go.api.ApiVersion) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialUpdateService(com.thoughtworks.go.server.materials.MaterialUpdateService) Routes(com.thoughtworks.go.spark.Routes) ApiController(com.thoughtworks.go.api.ApiController) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) ApiAuthenticationHelper(com.thoughtworks.go.api.spring.ApiAuthenticationHelper) MaterialWithModificationsRepresenter(com.thoughtworks.go.apiv1.internalmaterials.representers.MaterialWithModificationsRepresenter) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Response(spark.Response) MaterialService(com.thoughtworks.go.server.service.MaterialService) UsagesRepresenter(com.thoughtworks.go.apiv1.internalmaterials.representers.UsagesRepresenter) Spark(spark.Spark) CachedDigestUtils.sha512_256Hex(com.thoughtworks.go.util.CachedDigestUtils.sha512_256Hex) Modification(com.thoughtworks.go.domain.materials.Modification) HashMap(java.util.HashMap) Material(com.thoughtworks.go.domain.materials.Material) MaintenanceModeService(com.thoughtworks.go.server.service.MaintenanceModeService) Timestamp(java.sql.Timestamp) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialInfo(com.thoughtworks.go.apiv1.internalmaterials.models.MaterialInfo) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState)

Example 13 with HealthStateScope

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

the class MaterialUpdateService method updateMaterial.

public boolean updateMaterial(Material material) {
    Date inProgressSince = inProgress.putIfAbsent(material, new Date());
    if (inProgressSince == null || !material.isAutoUpdate()) {
        LOGGER.debug("[Material Update] Starting update of material {}", material);
        try {
            long trackingId = mduPerformanceLogger.materialSentToUpdateQueue(material);
            queueFor(material).post(new MaterialUpdateMessage(material, trackingId));
            return true;
        } catch (RuntimeException e) {
            inProgress.remove(material);
            throw e;
        }
    } else {
        LOGGER.warn("[Material Update] Skipping update of material {} which has been in-progress since {}", material, inProgressSince);
        long idleTime = getProcessManager().getIdleTimeFor(new MaterialFingerprintTag(material.getFingerprint()));
        if (idleTime > getMaterialUpdateInActiveTimeoutInMillis()) {
            HealthStateScope scope = HealthStateScope.forMaterialUpdate(material);
            serverHealthService.removeByScope(scope);
            serverHealthService.update(warning("Material update for " + material.getUriForDisplay() + " hung:", "Material update is currently running but has not shown any activity in the last " + idleTime / 60000 + " minute(s). This may be hung. Details - " + material.getLongDescription(), general(scope)));
        }
        return false;
    }
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) MaterialFingerprintTag(com.thoughtworks.go.util.MaterialFingerprintTag)

Example 14 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 15 with HealthStateScope

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

the class GoConfigRepoConfigDataSourceTest method shouldSetOKHealthState_AtConfigRepoScope_WhenPluginHasParsed.

@Test
public void shouldSetOKHealthState_AtConfigRepoScope_WhenPluginHasParsed() {
    ScmMaterialConfig material = git("http://my.git");
    ConfigRepoConfig configRepoConfig = ConfigRepoConfig.createConfigRepoConfig(material, "myplugin", "id");
    cruiseConfig.setConfigRepos(new ConfigReposConfig(configRepoConfig));
    configWatchList.onConfigChange(cruiseConfig);
    // set error state to simulate previously failed parse
    HealthStateScope scope = HealthStateScope.forPartialConfigRepo(configRepoConfig);
    serverHealthService.update(ServerHealthState.error("Parse failed", "Bad config format", HealthStateType.general(scope)));
    // verify error health
    assertFalse(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(configRepoConfig)).isEmpty());
    // now this should fix health
    repoConfigDataSource.onCheckoutComplete(material, folder, getModificationFor("7a8f"));
    assertTrue(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(configRepoConfig)).isEmpty());
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) ConfigReposConfig(com.thoughtworks.go.config.remote.ConfigReposConfig) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) ScmMaterialConfig(com.thoughtworks.go.config.materials.ScmMaterialConfig) 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