public ServerHealthState error(String message, String description, HealthStateType type) { ServerHealthState state = ServerHealthState.error(message, description, type); serverHealthService.update(state); canContinue = false; return state; }
private void updateMaterial(Material material) { if (skipUpdate) return; try { if (!materialUpdateService.updateMaterial(material)) { retryQueue.add(material); } } catch (Exception e) { HealthStateScope scope = HealthStateScope.forMaterialUpdate(material); serverHealthService.update(error(format("Error updating Dependency Material %s", material.getUriForDisplay()), e.getMessage(), general(scope))); retryQueue.add(material); } }
private void setServerHealthError(String message, String description) { serverHealthService.update( ServerHealthState.error(message, description, HealthStateType.general(HealthStateScope.forBackupCron())) ); }
private ServerHealthState showError(String pipelineName, String message, String desc) { if (desc == null) { desc = "Details not available, please check server logs."; } ServerHealthState serverHealthState = ServerHealthState.error(message, desc, HealthStateType.general(HealthStateScope.forPipeline(pipelineName))); serverHealthService.update(serverHealthState); return serverHealthState; }
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); }
@Test public void shouldUnderstandEquality() { ServerHealthState fooError = ServerHealthState.error("my message", "my description", HealthStateType.general(HealthStateScope.forPipeline("foo"))); ServerHealthState fooErrorCopy = ServerHealthState.error("my message", "my description", HealthStateType.general(HealthStateScope.forPipeline("foo"))); assertThat(fooError, is(fooErrorCopy)); }
private boolean updateConfig(final PartialConfig newPart, final String fingerprint, ConfigRepoConfig repoConfig) { try { goConfigService.updateConfig(buildUpdateCommand(newPart, fingerprint)); return true; } catch (Exception e) { if (repoConfig != null) { String description = String.format("%s- For Config Repo: %s", GoConfigValidity.invalid(e).errorMessage(), newPart.getOrigin().displayName()); ServerHealthState state = ServerHealthState.error(INVALID_CRUISE_CONFIG_MERGE, description, HealthStateType.general(HealthStateScope.forPartialConfigRepo(repoConfig))); serverHealthService.update(state); } return false; } }
@Test public void shouldNotAllowNullMessage() { ServerHealthState nullError = null; try { nullError = ServerHealthState.error(null, "some desc", HealthStateType.general(HealthStateScope.forPipeline("foo"))); fail("should have bombed as message given is null"); } catch(Exception e) { assertThat(nullError, is(nullValue())); assertThat(e.getMessage(), is("message cannot be null")); } }
@Override public void afterCommit() { final ServerHealthState error = ServerHealthState.error(message, description, HealthStateType.general(HealthStateScope.forJob(jobInstance.getPipelineName(), jobInstance.getStageName(), jobInstance.getName()))); error.setTimeout(Timeout.FIVE_MINUTES); serverHealthService.update(error); appendToConsoleLog(jobInstance, message); appendToConsoleLog(jobInstance, description); } });
@Test public void shouldUpdateLogInServerHealth() throws Exception { ServerHealthState serverHealthState = ServerHealthState.error("message", "description", globalId); serverHealthService.update(serverHealthState); ServerHealthState newServerHealthState = ServerHealthState.error("updated message", "updated description", globalId); serverHealthService.update(newServerHealthState); assertThat(serverHealthService.logs().size(), is(1)); assertThat(serverHealthService, ServerHealthMatcher.containsState(globalId, HealthStateLevel.ERROR, "updated message")); }
@Test public void shouldGetMessageWithTimestamp() { ServerHealthState errorState = ServerHealthState.error("my message", "my description", HealthStateType.general(HealthStateScope.forPipeline("foo"))); assertThat(errorState.getMessageWithTimestamp(), is("my message" + " [" + ServerHealthState.TIMESTAMP_FORMAT.format(errorState.getTimestamp()) + "]")); }
@Test public void shouldReturnFalseForRealSuccessIfThereIsAtleastOneError() throws Exception { ServerHealthStates states = new ServerHealthStates(ServerHealthState.error("msg", "desc", HealthStateType.artifactsDirChanged())); assertThat(states.isRealSuccess(), is(false)); }
@Test public void shouldAddMultipleLogToServerHealth() throws Exception { assertThat(serverHealthService.update(ServerHealthState.error("message", "description", globalId)), is(globalId)); assertThat(serverHealthService.update(ServerHealthState.error("message", "description", pipelineId)), is(pipelineId)); assertThat(serverHealthService.logs().size(), is(2)); assertThat(serverHealthService, ServerHealthMatcher.containsState(globalId)); assertThat(serverHealthService, ServerHealthMatcher.containsState(pipelineId)); }
@Test public void shouldRemoveErrorLogWhenCorrespondingPipelineIsMissing() throws Exception { serverHealthService.update(ServerHealthState.error("message", "description", pipelineId)); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forPipeline("other")))); serverHealthService.purgeStaleHealthMessages(new BasicCruiseConfig()); assertThat(serverHealthService.logs().size(), is(0)); }
@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)); }
@Test public void shouldReturnTheErrorCount() throws Exception { ServerHealthStates states = new ServerHealthStates(ServerHealthState.error("msg", "desc", HealthStateType.artifactsDirChanged()), ServerHealthState.warning("another", "some", HealthStateType.databaseDiskFull())); assertThat(states.errorCount(), is(1)); assertThat(states.warningCount(), is(1)); }
@Test public void shouldReturnErrorLogs() throws Exception { serverHealthService.update(ServerHealthState.error("message", "description", pipelineId)); CruiseConfig cruiseConfig = new BasicCruiseConfig(); new GoConfigMother().addPipeline(cruiseConfig, PIPELINE_NAME, "stageName", "jon"); serverHealthService.purgeStaleHealthMessages(cruiseConfig); assertThat(serverHealthService.logs().size(), is(1)); }
@Test public void shouldRemoveErrorLogWhenCorrespondingMaterialIsMissing() throws Exception { serverHealthService.update(ServerHealthState.error("hg-message", "description", HealthStateType.general(forMaterial(MaterialsMother.hgMaterial())))); SvnMaterialConfig svnMaterialConfig = MaterialConfigsMother.svnMaterialConfig(); serverHealthService.update(ServerHealthState.error("svn-message", "description", HealthStateType.general(forMaterialConfig(svnMaterialConfig)))); CruiseConfig cruiseConfig = new BasicCruiseConfig(); cruiseConfig.addPipeline("defaultGroup", new PipelineConfig(new CaseInsensitiveString("dev"), new MaterialConfigs(svnMaterialConfig), new StageConfig(new CaseInsensitiveString("first"), new JobConfigs()))); serverHealthService.purgeStaleHealthMessages(cruiseConfig); assertThat(serverHealthService.logs().size(), is(1)); }
@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()); }
@Test public void faninErrorStateRelatedPipelineNames() { 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.general(HealthStateScope.forFanin("pipeline2")))); Set<String> pipelines = (serverHealthService.logs().get(0)).getPipelineNames(config); assertEquals(Sets.newHashSet("pipeline2"), pipelines); } }