private Exception represent(ServerHealthState serverHealthState) { String message = new StringBuilder() .append(serverHealthState.getMessage().toUpperCase()) .append("\n") .append(serverHealthState.getDescription()) .toString(); return new Exception(message); }
public String fullMessage() { ServerHealthState serverHealthState = serverHealthStateOperationResult.getServerHealthState(); String desc = serverHealthState == null ? BLANK_STRING : serverHealthState.getDescription(); return StringUtils.isBlank(desc) ? message : String.format("%s { %s }", message, desc); }
public String getLogsAsText() { StringBuilder text = new StringBuilder(); for (ServerHealthState state : logs()) { text.append(state.getDescription()); text.append("\n\t"); text.append(state.getMessage()); text.append("\n"); } return text.toString(); }
public Map<String, String> asJson() { Map<String, String> json = new LinkedHashMap<>(); json.put("message", getMessage()); json.put("detail", getDescription()); json.put("level", healthStateLevel.toString()); return json; }
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); }
public void canProduce(PipelineConfig pipelineConfig, SchedulingCheckerService schedulingChecker, ServerHealthService serverHealthService, OperationResult operationResult) { schedulingChecker.canTriggerPipelineWithTimer(pipelineConfig, operationResult); if (!operationResult.canContinue()) { ServerHealthState serverHealthState = operationResult.getServerHealthState(); LOGGER.info("'{}' because '{}'", serverHealthState.getMessage(), serverHealthState.getDescription()); } else { TimerConfig timer = pipelineConfig.getTimer(); String timerSpec = timer == null ? "Missing timer spec" : timer.getTimerSpec(); LOGGER.info("Timer scheduling pipeline '{}' using spec '{}'", pipelineConfig.name(), timerSpec); } }
public void canProduce(PipelineConfig pipelineConfig, SchedulingCheckerService schedulingChecker, ServerHealthService serverHealthService, OperationResult operationResult) { schedulingChecker.canTriggerManualPipeline(pipelineConfig, CaseInsensitiveString.str(username.getUsername()), operationResult); if (!operationResult.canContinue()) { ServerHealthState serverHealthState = operationResult.getServerHealthState(); LOGGER.info("'{}' because '{}'", serverHealthState.getMessage(), serverHealthState.getDescription()); serverHealthService.update(serverHealthState); } }
public static void toJSON(OutputListWriter outputListWriter, Collection<ServerHealthState> healthStates) { healthStates.forEach(healthState -> outputListWriter.addChild(writer -> writer.add("message", healthState.getMessage()) .add("detail", healthState.getDescription()) .add("level", healthState.getLogLevel().toString()) .add("time", healthState.getTimestamp())) ); } }
private Stage internalRerun(Pipeline pipeline, String stageName, String approvedBy, final StageInstanceCreator creator, ErrorConditionHandler errorHandler) { ServerHealthStateOperationResult result = new ServerHealthStateOperationResult(); if (!schedulingChecker.canRerunStage(pipeline.getIdentifier(), stageName, approvedBy, result)) { errorHandler.cantSchedule("Cannot schedule: " + result.getServerHealthState().getDescription(), pipeline.getName(), stageName); } return scheduleStage(pipeline, stageName, approvedBy, creator, errorHandler); }
@Test public void shouldAddWarningWhenConfigRepoLooseObjectCountGoesBeyondTheConfiguredThreshold() throws Exception { when(systemEnvironment.get(SystemEnvironment.GO_CONFIG_REPO_GC_LOOSE_OBJECT_WARNING_THRESHOLD)).thenReturn(10L); when(configRepository.getLooseObjectCount()).thenReturn(20L); service.checkRepoAndAddWarningIfRequired(); List<ServerHealthState> healthStates = serverHealthService.filterByScope(HealthStateScope.forConfigRepo("GC")); String message = "Action required: Run 'git gc' on config.git repo"; String description = "Number of loose objects in your Configuration repository(config.git) has grown beyond " + "the configured threshold. As the size of config repo increases, the config save operations tend to slow down " + "drastically. It is recommended that you run 'git gc' from " + "'<go server installation directory>/db/config.git/' to address this problem. Go can do this " + "automatically on a periodic basis if you enable automatic GC. <a target='_blank' href='" + docsUrl("/advanced_usage/config_repo.html") + "'>read more...</a>"; assertThat(healthStates.get(0).getDescription(), is(description)); assertThat(healthStates.get(0).getLogLevel(), is(HealthStateLevel.WARNING)); assertThat(healthStates.get(0).getMessage(), is(message)); }
@Test public void shouldEscapeWarningMessageAndDescriptionByDefault() { ServerHealthState warningStateWithoutTimeout = ServerHealthState.warning("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo"))); ServerHealthState warningStateWithTimeout = ServerHealthState.warning("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo")), Timeout.TEN_SECONDS); ServerHealthState warningState = ServerHealthState.warning("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo")), 15L); assertThat(warningStateWithoutTimeout.getMessage(), is(""<message1 & message2>"")); assertThat(warningStateWithoutTimeout.getDescription(), is(""<message1 & message2>"")); assertThat(warningStateWithTimeout.getMessage(), is("\"<message1 & message2>\"")); assertThat(warningStateWithTimeout.getDescription(), is("\"<message1 & message2>\"")); assertThat(warningState.getMessage(), is(""<message1 & message2>"")); assertThat(warningState.getDescription(), is(""<message1 & message2>"")); }
@Test public void shouldPreserverHtmlInWarningMessageAndDescription() { ServerHealthState warningState = ServerHealthState.warningWithHtml("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo"))); ServerHealthState warningStateWithTime = ServerHealthState.warningWithHtml("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo")), 15L); assertThat(warningState.getMessage(), is("\"<message1 & message2>\"")); assertThat(warningState.getDescription(), is("\"<message1 & message2>\"")); assertThat(warningStateWithTime.getMessage(), is("\"<message1 & message2>\"")); assertThat(warningStateWithTime.getDescription(), is("\"<message1 & message2>\"")); } }
@Test public void shouldEscapeErrorMessageAndDescriptionByDefault() { ServerHealthState errorState = ServerHealthState.error("\"<message1 & message2>\"", "\"<message1 & message2>\"", HealthStateType.general(HealthStateScope.forPipeline("foo"))); assertThat(errorState.getMessage(), is(""<message1 & message2>"")); assertThat(errorState.getDescription(), is(""<message1 & message2>"")); }
private Stage lockAndRerunStage(String pipelineName, Integer counter, String stageName, StageInstanceCreator creator, final ErrorConditionHandler errorHandler) { synchronized (mutexForPipeline(pipelineName)) { OperationResult result = new ServerHealthStateOperationResult(); if (!schedulingChecker.canSchedule(result)) { errorHandler.cantSchedule(result.getServerHealthState().getDescription(), pipelineName, stageName); } String username = CaseInsensitiveString.str(SessionUtils.currentUsername().getUsername()); if (!securityService.hasOperatePermissionForStage(pipelineName, stageName, username)) { errorHandler.noOperatePermission(pipelineName, stageName); } Pipeline pipeline = pipelineService.fullPipelineByCounter(pipelineName, counter); if (pipeline == null) { errorHandler.nullPipeline(pipelineName, counter, stageName); } if (!pipeline.hasStageBeenRun(stageName)) { if (goConfigService.hasPreviousStage(pipelineName, stageName)) { CaseInsensitiveString previousStageName = goConfigService.previousStage(pipelineName, stageName).name(); if (!pipeline.hasStageBeenRun(CaseInsensitiveString.str(previousStageName))) { errorHandler.previousStageNotRun(pipeline.getName(), stageName); } } } Stage stage = internalRerun(pipeline, stageName, username, creator, errorHandler); if (stage == null) { errorHandler.nullStage(stageName); } return stage; } }