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 void check(OperationResult result) { HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forPipeline(pipelineName)); if (pipelineLockService.isLocked(pipelineName)) { String message = format("Pipeline %s cannot be scheduled", pipelineName); String description = format("Pipeline %s is locked as another instance of this pipeline is running.", pipelineName); result.conflict(message, description, healthStateType); } else{ result.success(healthStateType); } } }
private boolean pipelineNotFound(String pipelineName, OperationResult result) { if (!goConfigService.hasPipelineNamed(new CaseInsensitiveString(pipelineName))) { result.notFound(String.format("Pipeline '%s' not found", pipelineName), String.format("Pipeline '%s' not found", pipelineName), HealthStateType.general(HealthStateScope.forPipeline(pipelineName))); return true; } return false; }
public void check(OperationResult result) { HealthStateType id = HealthStateType.general(HealthStateScope.forPipeline(pipelineName)); if (pipelinePauseService.isPaused(pipelineName)) { String message = String.format("Failed to trigger pipeline [%s]", pipelineName); result.conflict(message, String.format("Pipeline %s is paused", pipelineName), id); } else { result.success(id); } } }
private boolean materialNotFound(String pipelineName, Map<String, String> revisions, OperationResult result) { for (String pipelineFingerprint : revisions.keySet()) { if (goConfigService.findMaterial(new CaseInsensitiveString(pipelineName), pipelineFingerprint) == null) { String message = String.format("material with fingerprint [%s] not found in pipeline [%s]", pipelineFingerprint, pipelineName); result.notFound(message, message, HealthStateType.general(HealthStateScope.forPipeline(pipelineName))); return true; } } return false; }
public void check(OperationResult result) { HealthStateType id = HealthStateType.general(HealthStateScope.forPipeline(pipelineName)); if (!securityService.hasOperatePermissionForStage(pipelineName, stageName, username)) { String message = String.format("Failed to trigger pipeline [%s]", pipelineName); result.forbidden(message, "User " + username + " does not have permission to schedule " + pipelineName + "/" + stageName, id); } else { result.success(id); } } }
private void showPipelineError(PipelineConfig pipelineConfig, Exception e, String msg, String description) { LOG.error(msg, e); serverHealthService.update( ServerHealthState.error(msg, description, HealthStateType.general(HealthStateScope.forPipeline(CaseInsensitiveString.str(pipelineConfig.name()))))); }
public void check(OperationResult result) { HealthStateType type = HealthStateType.general(HealthStateScope.forPipeline(CaseInsensitiveString.str(pipelineConfig.name()))); if (pipelineConfig.isFirstStageManualApproval()) { String message = String.format("Failed to trigger pipeline [%s]", pipelineConfig.name()); result.error(message, String.format("The first stage of pipeline \"%s\" has manual approval", pipelineConfig.name()), type); } else { result.success(type); } } }
public boolean validate(String pipelineName, Username username, OperationResult result) { if (!goConfigService.hasPipelineNamed(new CaseInsensitiveString(pipelineName))) { String pipelineNotKnown = String.format("Pipeline named [%s] is not known.", pipelineName); result.notFound(pipelineNotKnown, pipelineNotKnown, HealthStateType.general(HealthStateScope.GLOBAL)); return false; } if (!securityService.hasViewPermissionForPipeline(username, pipelineName)) { result.forbidden(NOT_AUTHORIZED_TO_VIEW_PIPELINE, NOT_AUTHORIZED_TO_VIEW_PIPELINE, HealthStateType.general(HealthStateScope.forPipeline(pipelineName))); return false; } return true; }
public void check(OperationResult result) { HealthStateType id = HealthStateType.general(HealthStateScope.forPipeline(pipelineIdentifier.getName())); if (stageService.isAnyStageActiveForPipeline(pipelineIdentifier)) { String description = String.format("Pipeline[name='%s', counter='%s', label='%s'] is still in progress", pipelineIdentifier.getName(), pipelineIdentifier.getCounter(), pipelineIdentifier.getLabel()); String message = String.format("Failed to trigger pipeline [%s]", pipelineIdentifier.getName()); result.error(message, description, id); } else { result.success(id); } } }
@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 doesPipelineExist(String pipelineName, LocalizedOperationResult result) { if (!getCurrentConfig().hasPipelineNamed(new CaseInsensitiveString(pipelineName))) { result.notFound(resourceNotFound("pipeline", pipelineName), general(forPipeline(pipelineName))); return false; } return true; }
private boolean pipelineDoesNotExist(String pipelineName, LocalizedOperationResult result) { CruiseConfig cruiseConfig = goConfigService.getCurrentConfig(); if (cruiseConfig.hasPipelineNamed(new CaseInsensitiveString(pipelineName))) { return false; } result.notFound(resourceNotFound("pipeline", pipelineName), general(forPipeline(pipelineName))); return true; }
@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")); } }
@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 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>"")); }
@Test public void shouldRemoveScopeWhenStageIsRemovedFromConfig() throws Exception { CruiseConfig config = GoConfigMother.pipelineHavingJob("blahPipeline", "blahStage", "blahJob", "fii", "baz"); assertThat(HealthStateScope.forPipeline("fooPipeline").isRemovedFromConfig(config),is(true)); assertThat(HealthStateScope.forPipeline("blahPipeline").isRemovedFromConfig(config),is(false)); assertThat(HealthStateScope.forStage("fooPipeline","blahStage").isRemovedFromConfig(config),is(true)); assertThat(HealthStateScope.forStage("blahPipeline","blahStageRemoved").isRemovedFromConfig(config),is(true)); assertThat(HealthStateScope.forStage("blahPipeline","blahStage").isRemovedFromConfig(config),is(false)); }
@Test public void shouldReturn202IfEverythingWorks() throws Exception { httpOperationResult.accepted("Request to schedule pipeline 'baboon' accepted","blah blah", HealthStateType.general(HealthStateScope.forPipeline("baboon"))); assertThat(httpOperationResult.httpCode(), is(202)); assertThat(httpOperationResult.canContinue(), is(true)); assertThat(httpOperationResult.message(), is("Request to schedule pipeline 'baboon' accepted")); }
@Test public void successShouldReturnTrueIfStatusIs2xx(){ assertThat(httpOperationResult.isSuccess(), is(true)); httpOperationResult.notAcceptable("not acceptable", HealthStateType.general(HealthStateScope.GLOBAL)); assertThat(httpOperationResult.isSuccess(), is(false)); httpOperationResult.ok("message"); assertThat(httpOperationResult.isSuccess(), is(true)); httpOperationResult.error("message", "desc", HealthStateType.general(HealthStateScope.GLOBAL)); assertThat(httpOperationResult.isSuccess(), is(false)); httpOperationResult.accepted("Request to schedule pipeline 'baboon' accepted", "blah blah", HealthStateType.general(HealthStateScope.forPipeline("baboon"))); assertThat(httpOperationResult.isSuccess(), is(true)); }
@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)); }