private Optional<Stage> getStageFromRequestParam(Request request, HttpOperationResult operationResult) { String pipelineName = request.params("pipeline_name"); String pipelineCounter = request.params("pipeline_counter"); String stageName = request.params("stage_name"); String stageCounter = request.params("stage_counter"); Stage stage = stageService.findStageWithIdentifier(pipelineName, Integer.parseInt(pipelineCounter), stageName, stageCounter, currentUsername().getUsername().toString(), operationResult); if (!operationResult.isSuccess()) { return Optional.empty(); } if (stage == null || stage instanceof NullStage) { String message = String.format("Stage '%s' with counter '%s' not found. Please make sure specified stage or stage run with specified counter exists.", stageName, stageCounter); operationResult.notFound("Not Found", message, HealthStateType.general(HealthStateScope.GLOBAL)); return Optional.empty(); } return Optional.ofNullable(stage); }
public void sendNotifications(StageIdentifier stageIdentifier, StageEvent event, Username cancelledBy) { Users users = userService.findValidSubscribers(stageIdentifier.stageConfigIdentifier()); if (users.isEmpty()) { return; } Stage stage = stageService.findStageWithIdentifier(stageIdentifier); Pipeline pipeline = pipelineService.fullPipelineById(stage.getPipelineId()); MaterialRevisions materialRevisions = pipeline.getMaterialRevisions(); String emailBody = new EmailBodyGenerator(materialRevisions, cancelledBy, systemEnvironment, stageIdentifier).getContent(); String subject = "Stage [" + stageIdentifier.stageLocator() + "]" + event.describe(); LOGGER.debug("Processing notification titled [{}]", subject); for (User user : users) { if (user.matchNotification(stageIdentifier.stageConfigIdentifier(), event, materialRevisions)) { StringBuilder emailWithSignature = new StringBuilder(emailBody) .append("\n\n") .append("Sent by Go on behalf of ") .append(user.getName()); SendEmailMessage sendEmailMessage = new SendEmailMessage(subject, emailWithSignature.toString(), user.getEmail()); emailNotificationTopic.post(sendEmailMessage); } } LOGGER.debug("Finished processing notification titled [{}]", subject); }
public String instanceByCounter(Request req, Response res) throws IOException { String pipelineName = req.params("pipeline_name"); String pipelineCounter = req.params("pipeline_counter"); String stageName = req.params("stage_name"); String stageCounter = req.params("stage_counter"); HttpOperationResult result = new HttpOperationResult(); Stage stageModel = stageService.findStageWithIdentifier(pipelineName, Integer.parseInt(pipelineCounter), stageName, stageCounter, currentUsername().getUsername().toString(), result); if (result.canContinue()) { return writerForTopLevelObject(req, res, writer -> StageRepresenter.toJSON(writer, stageModel)); } else { return renderHTTPOperationResult(result, req, res); } }
public Stage findStageWithIdentifier(String pipelineName, int pipelineCounter, String stageName, String stageCounter, String username, OperationResult result) { if (!goConfigService.currentCruiseConfig().hasPipelineNamed(new CaseInsensitiveString(pipelineName))) { String message = String.format("Pipeline '%s' not found", pipelineName); result.notFound("Not Found", message, HealthStateType.general(HealthStateScope.GLOBAL)); return null; } if (!securityService.hasViewPermissionForPipeline(Username.valueOf(username), pipelineName)) { result.forbidden("Unauthorized", NOT_AUTHORIZED_TO_VIEW_PIPELINE, HealthStateType.general(HealthStateScope.forPipeline(pipelineName))); return null; } Pipeline pipeline = pipelineDao.findPipelineByNameAndCounter(pipelineName, pipelineCounter); if (pipeline == null) { String message = String.format("Pipeline '%s' with counter '%s' not found", pipelineName, pipelineCounter); result.notFound("Not Found", message, HealthStateType.general(HealthStateScope.GLOBAL)); return null; } return findStageWithIdentifier(new StageIdentifier(pipelineName, pipelineCounter, stageName, stageCounter)); }
public void onMessage(final JobStatusMessage message) { if (message.getJobState().isCompleted()) { final Stage stage = stageService.findStageWithIdentifier(message.getStageIdentifier()); if (stage.isCompleted()) { stageStatusTopic.post(new StageStatusMessage(message.getStageIdentifier(), stage.stageState(), stage.getResult())); } elasticAgentPluginService.jobCompleted(stage.findJob(message.getJobIdentifier().getBuildName())); } } }