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