private String startPipeline(Map config) throws Exception { String json = kayentaObjectMapper.writeValueAsString(config); log.info("Requested pipeline: {}", json); Execution pipeline = executionLauncher.start(Execution.ExecutionType.PIPELINE, json); return pipeline.getId(); } }
public CanaryConfig getCanaryConfig(Execution pipeline) { Stage contextStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_SET_CONTEXT)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + CanaryStageNames.REFID_SET_CONTEXT + "' in pipeline ID '" + pipeline.getId() + "'")); Map<String, Object> context = contextStage.getContext(); Map<String, Object> canaryConfigMap = (Map<String, Object>)context.get("canaryConfig"); return objectMapper.convertValue(canaryConfigMap, CanaryConfig.class); }
private void handleStartupFailure(Execution execution, Throwable failure) { final String canceledBy = "system"; final String reason = "Failed on startup: " + failure.getMessage(); final ExecutionStatus status = ExecutionStatus.TERMINAL; log.error("Failed to start {} {}", execution.getType(), execution.getId(), failure); executionRepository.updateStatus(execution.getType(), execution.getId(), status); executionRepository.cancel(execution.getType(), execution.getId(), canceledBy, reason); }
public String getCanaryExecutionRequestFromJudgeContext(Execution pipeline) { Stage contextStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_JUDGE)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + CanaryStageNames.REFID_JUDGE + "' in pipeline ID '" + pipeline.getId() + "'")); Map<String, Object> context = contextStage.getContext(); return (String) context.get("canaryExecutionRequest"); }
public CanaryExecutionStatusResponse fromExecution(Execution pipeline) { String canaryExecutionId = pipeline.getId(); Stage contextStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_SET_CONTEXT)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + CanaryStageNames.REFID_SET_CONTEXT + "' in pipeline ID '" + canaryExecutionId + "'")); Map<String, Object> contextContext = contextStage.getContext(); String storageAccountName = (String)contextContext.get("storageAccountName"); return fromExecution(storageAccountName, pipeline); }
@Override public void processCompletedPipelineExecution(Execution execution) { CanaryAnalysisExecutionStatusResponse canaryAnalysisExecution = canaryAnalysisService .getCanaryAnalysisExecution(execution.getId()); applicationEventPublisher.publishEvent(new StandaloneCanaryAnalysisExecutionCompletedEvent(this, canaryAnalysisExecution)); } }
private void handleStartupFailure(Execution execution, Throwable failure) { final String canceledBy = "system"; final String reason = "Failed on startup: " + failure.getMessage(); final ExecutionStatus status = ExecutionStatus.TERMINAL; log.error("Failed to start {} {}", execution.getType(), execution.getId(), failure); executionRepository.updateStatus(execution.getType(), execution.getId(), status); executionRepository.cancel(execution.getType(), execution.getId(), canceledBy, reason); registry.counter(failureId).increment(); }
public CanaryExecutionRequest getCanaryExecutionRequest(Execution pipeline) { Stage contextStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_SET_CONTEXT)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + CanaryStageNames.REFID_SET_CONTEXT + "' in pipeline ID '" + pipeline.getId() + "'")); Map<String, Object> context = contextStage.getContext(); String canaryExecutionRequestJSON = (String)context.get("canaryExecutionRequest"); if (canaryExecutionRequestJSON == null) { canaryExecutionRequestJSON = getCanaryExecutionRequestFromJudgeContext(pipeline); } if (canaryExecutionRequestJSON == null) { return null; } CanaryExecutionRequest canaryExecutionRequest = null; try { canaryExecutionRequest = objectMapper.readValue(canaryExecutionRequestJSON, CanaryExecutionRequest.class); } catch (IOException e) { log.error("Cannot deserialize canaryExecutionRequest", e); throw new IllegalArgumentException("Cannot deserialize canaryExecutionRequest", e); } return canaryExecutionRequest; }
public Map getJudgeComparisonResults(@PathVariable String executionId) { Execution pipeline = executionRepository.retrieve(Execution.ExecutionType.PIPELINE, executionId); String canaryExecutionId = pipeline.getId(); Stage compareJudgeResultsStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals("compareJudgeResults"))
stage.getId(), stage.getExecution().getId(), canaryPipelineExecutionId, stage.getContext()); } catch (Exception e) { log.error("Failed to cancel stage (stageId: {}, executionId: {}), e: {}", stage.getId(), stage.getExecution().getId(), e.getMessage(), e); stage.getId(), stage.getExecution().getId(), stage.getContext());
return CanaryExecutionResponse.builder().canaryExecutionId(pipeline.getId()).build();
return CanaryExecutionResponse.builder().canaryExecutionId(pipeline.getId()).build();
.orElseThrow(() -> new IllegalArgumentException("No storage service was configured; unable to retrieve results.")); String canaryExecutionId = pipeline.getId(); .application((String)contextContext.get("application")) .parentPipelineExecutionId((String)contextContext.get("parentPipelineExecutionId")) .pipelineId(pipeline.getId()) .storageAccountName(storageAccountName); if (contextContext.containsKey("canaryConfigId")) {
stage.getExecution().getId(), Optional.ofNullable(context.getCanaryConfigId()).orElse(AD_HOC), request.getCanaryConfig(),
CanaryAnalysisExecutionStatusResponse.builder() .application(pipeline.getApplication()) .pipelineId(pipeline.getId()) .stageStatus(pipeline.getStages() .stream()
/** * Initiates the canary analysis execution Orca pipeline. * * @param canaryAnalysisConfig The configuration for the canary analysis execution. * @return Wrapper object around the execution id. */ public CanaryAnalysisExecutionResponse initiateCanaryAnalysisExecution(CanaryAnalysisConfig canaryAnalysisConfig) { String application = canaryAnalysisConfig.getApplication(); PipelineBuilder pipelineBuilder = new PipelineBuilder(application) .withName(CANARY_ANALYSIS_PIPELINE_NAME) .withPipelineConfigId(application + "-canary-analysis-referee-pipeline") .withStage( SetupAndExecuteCanariesStage.STAGE_TYPE, SetupAndExecuteCanariesStage.STAGE_DESCRIPTION, Maps.newHashMap(ImmutableMap.of( CANARY_ANALYSIS_CONFIG_CONTEXT_KEY, canaryAnalysisConfig ))); Execution pipeline = pipelineBuilder.withLimitConcurrent(false).build(); executionRepository.store(pipeline); try { executionLauncher.start(pipeline); } catch (Throwable t) { log.error("Failed to start pipeline", t); handleStartupFailure(pipeline, t); throw new RuntimeException("Failed to start the canary analysis pipeline execution"); } return CanaryAnalysisExecutionResponse.builder().canaryAnalysisExecutionId(pipeline.getId()).build(); }
@Override public int compare(Execution a, Execution b) { Long aBuildTime = Optional.ofNullable(a.getBuildTime()).orElse(0L); Long bBuildTime = Optional.ofNullable(b.getBuildTime()).orElse(0L); int buildCompare = aBuildTime.compareTo(bBuildTime); if (buildCompare == 0) { return a.getId().compareTo(b.getId()); } return buildCompare; } };
private Execution handleStartupFailure(Execution execution, Throwable failure) { final String canceledBy = "system"; final String reason = "Failed on startup: " + failure.getMessage(); final ExecutionStatus status = ExecutionStatus.TERMINAL; log.error("Failed to start {} {}", execution.getType(), execution.getId(), failure); executionRepository.updateStatus(execution.getType(), execution.getId(), status); executionRepository.cancel(execution.getType(), execution.getId(), canceledBy, reason); return executionRepository.retrieve(execution.getType(), execution.getId()); }
public StageStarted( @Nonnull Object source, @Nonnull Stage stage ) { this(source, stage.getExecution().getType(), stage.getExecution().getId(), stage.getId(), stage.getType(), stage.getName()); }