private boolean revisionInvalid(Map<String, String> revisions, OperationResult result) { for (Map.Entry<String, String> entry : revisions.entrySet()) { if (StringUtils.isEmpty(entry.getValue())) { String message = String.format("material with fingerprint [%s] has empty revision", entry.getKey()); result.notAcceptable(message, HealthStateType.general(HealthStateScope.GLOBAL)); return true; } } return false; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; HttpLocalizedOperationResult that = (HttpLocalizedOperationResult) o; if (httpCode != that.httpCode) return false; if (healthStateType != null ? !healthStateType.equals(that.healthStateType) : that.healthStateType != null) return false; if (message != null ? !message.equals(that.message) : that.message != null) return false; return true; }
public int getHttpCode() { return getType().getHttpCode(); }
@Test public void shouldDifferentiateTypeUsingSubkey() { HealthStateScope scope = HealthStateScope.fromPlugin("plugin-id"); assertEquals(HealthStateType.general(scope), HealthStateType.general(scope)); assertEquals(HealthStateType.withSubkey(scope, "subkey1"), HealthStateType.withSubkey(scope, "subkey1")); assertNotEquals(HealthStateType.withSubkey(scope, "subkey1"), HealthStateType.withSubkey(scope, "subkey2")); assertNotEquals(HealthStateType.withSubkey(scope, "subkey1"), HealthStateType.general(scope)); } }
private boolean userHasPermissions(Username username, String groupName, HttpLocalizedOperationResult result) { try { if (!securityService.isUserAdminOfGroup(username.getUsername(), groupName)) { result.forbidden(forbiddenToEditGroup(groupName), forbiddenForGroup(groupName)); return false; } } catch (Exception e) { result.notFound(LocalizedMessage.resourceNotFound("Pipeline group", groupName), HealthStateType.general(HealthStateScope.forGroup(groupName))); return false; } return true; }
@Before public void setUp() throws Exception { serverHealthService = new ServerHealthService(); globalId = HealthStateType.general(GLOBAL); pipelineId = HealthStateType.general(forPipeline(PIPELINE_NAME)); groupId = HealthStateType.invalidLicense(forGroup("group")); testingClock = new TestingClock(); ServerHealthState.clock = testingClock; }
private void removeByScope(HealthStateType type) { removeByScope(type.getScope()); }
private synchronized void saveValidConfigToCache(GoConfigHolder configHolder) { if (configHolder != null) { LOGGER.debug("[Config Save] Saving config to the cache"); this.lastException = null; this.configHolder = configHolder; this.currentConfig = this.configHolder.config; this.currentConfigForEdit = this.configHolder.configForEdit; this.mergedCurrentConfigForEdit = configHolder.mergedConfigForEdit; serverHealthService.update(ServerHealthState.success(HealthStateType.invalidConfig())); } }
private void removeLicenseInvalidFromLog() { serverHealthService.update(ServerHealthState.success( HealthStateType.invalidLicense(HealthStateScope.GLOBAL))); }
private void replaceServerHealthMessages(String errorMessageTitle, HealthStateScope scope, List<PluginHealthMessage> pluginHealthMessages) { serverHealthService.removeByScope(scope); for (int index = 0; index < pluginHealthMessages.size(); index++) { PluginHealthMessage pluginHealthMessage = pluginHealthMessages.get(index); ServerHealthState state; if (pluginHealthMessage.isWarning()) { state = ServerHealthState.warning(errorMessageTitle, pluginHealthMessage.message(), HealthStateType.withSubkey(scope, "message_" + index)); } else { state = ServerHealthState.error(errorMessageTitle, pluginHealthMessage.message(), HealthStateType.withSubkey(scope, "message_" + index)); } serverHealthService.update(state); } } }
@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)); }
@Override public void onConfigChange(CruiseConfig newCruiseConfig) { for (ServerHealthState state : serverHealthService.logs()) { HealthStateScope currentScope = state.getType().getScope(); if (currentScope.isForJob()) { serverHealthService.removeByScope(currentScope); } } }
private synchronized void saveConfigError(Exception e) { this.lastException = e; ServerHealthState state = ServerHealthState.error(INVALID_CRUISE_CONFIG_XML, GoConfigValidity.invalid(e).errorMessage(), HealthStateType.invalidConfig()); serverHealthService.update(state); }
private HealthStateType stageScopedHealthState(String pipelineName, String stageName) { return HealthStateType.general(HealthStateScope.forStage(pipelineName, stageName)); }
private boolean equals(ServerHealthState that) { if (!this.healthStateLevel.equals(that.healthStateLevel)) { return false; } if (!this.type.equals(that.type)) { return false; } if (!this.description.equals(that.description)) { return false; } if (!this.message.equals(that.message)) { return false; } return true; }
public void onConfigChange(CruiseConfig newCruiseConfig) { Set<HealthStateScope> materialScopes = toHealthStateScopes(newCruiseConfig.getAllUniqueMaterials()); for (ServerHealthState state : serverHealthService.logs()) { HealthStateScope currentScope = state.getType().getScope(); if (currentScope.isForMaterial() && !materialScopes.contains(currentScope)) { serverHealthService.removeByScope(currentScope); } } }
@Test public void globalStateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.invalidConfig())); assertTrue((serverHealthService.logs().get(0)).getPipelineNames(config).isEmpty()); }
public static JsonAction from(ServerHealthState serverHealthState) { if (serverHealthState.isSuccess()) { return jsonCreated(new LinkedHashMap()); } Map<String, Object> jsonLog = new LinkedHashMap<>(); jsonLog.put(ERROR_FOR_JSON, serverHealthState.getDescription()); return new JsonAction(serverHealthState.getType().getHttpCode(), jsonLog); }
private boolean pipelineDoesNotExist(String pipelineName, String counterOrLabel, HttpOperationResult result, Pipeline pipeline) { if (pipeline == null) { String msg = String.format("Pipeline '%s/%s' not found", pipelineName, counterOrLabel); LOGGER.error(msg); result.notFound(msg, "", HealthStateType.general(HealthStateScope.forPipeline(pipelineName))); return true; } return false; } }
public boolean containsError(HealthStateType type, HealthStateLevel level) { ServerHealthStates allLogs = logs(); for (ServerHealthState log : allLogs) { if (log.getType().equals(type) && log.getLogLevel() == level) { return true; } } return false; }