private List<String> getMetricSetListIds(Execution execution, String stagePrefix) { List<Stage> stages = execution.getStages(); return stages.stream() .filter(stage -> { String refId = stage.getRefId(); return refId != null && refId.startsWith(stagePrefix); }) .map(stage -> resolveMetricSetListId(stage)) .collect(Collectors.toList()); }
/** * Gets the run canary stages that contain the results */ @NotNull protected List<Stage> getRunCanaryStages(@Nonnull Stage stage) { // Collect the Run Canary Stages where the parent id is itself // Sorting by number after the # in the name return stage.getExecution().getStages().stream() .filter(s -> s.getType().equals(RunCanaryStage.STAGE_TYPE)) .sorted(Comparator.comparing(s -> Integer.valueOf(StringUtils.substringAfterLast(s.getName(), "#")))) .collect(Collectors.toList()); }
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); }
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); }
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; }
Execution pipeline = executionRepository.retrieve(Execution.ExecutionType.PIPELINE, executionId); String canaryExecutionId = pipeline.getId(); Stage compareJudgeResultsStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals("compareJudgeResults")) .findFirst() List<Stage> stagesWithException = pipeline.getStages().stream() .filter(stage -> stage.getContext().containsKey("exception")) .collect(Collectors.toList());
@Test public void test_that_getRunCanaryStages_returns_the_expected_sorted_list_of_stages_sorted_by_the_number_in_the_stage_name() { Stage stage = mock(Stage.class); Execution execution = mock(Execution.class); when(stage.getExecution()).thenReturn(execution); when(execution.getStages()).thenReturn(ImmutableList.of( new Stage(null, STAGE_TYPE, "foo #1", Maps.newHashMap(ImmutableMap.of("index", "0"))), new Stage(null, STAGE_TYPE, "foo #3", Maps.newHashMap(ImmutableMap.of("index", "2"))), new Stage(null, STAGE_TYPE, "foo #2", Maps.newHashMap(ImmutableMap.of("index", "1"))), new Stage(null, STAGE_TYPE, "foo #4", Maps.newHashMap(ImmutableMap.of("index", "3"))) )); List<Stage> actual = task.getRunCanaryStages(stage); for (int i = 0; i < 4; i++) { assertEquals(String.valueOf(i), actual.get(i).getContext().get("index")); } }
Stage judgeStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_JUDGE)) .findFirst() Map<String, Object> judgeOutputs = judgeStage.getOutputs(); Stage contextStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_SET_CONTEXT)) .findFirst() Map<String, Object> contextContext = contextStage.getContext(); Stage mixerStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_MIX_METRICS)) .findFirst() Map<String, String> stageStatus = pipeline.getStages() .stream() .collect(Collectors.toMap(Stage::getRefId, s -> s.getStatus().toString().toLowerCase())); Stage stageWithException = pipeline.getStages().stream() .filter(stage -> stage.getContext().containsKey("exception")) .findFirst()
.application(pipeline.getApplication()) .pipelineId(pipeline.getId()) .stageStatus(pipeline.getStages() .stream() .map(stage -> new StageMetadata(stage.getType(), stage.getName(), stage.getStatus())) pipeline.getStages().stream() .filter(stage -> stage.getType().equals(SetupAndExecuteCanariesStage.STAGE_TYPE)) .findFirst() pipeline.getStages().stream() .filter(stage -> stage.getType().equals(GenerateCanaryAnalysisResultStage.STAGE_TYPE)) .findFirst() pipeline.getStages().stream() .filter(stage -> stage.getContext().containsKey("exception")) .findFirst()
public PipelineBuilder withStage(String type, String name, Map<String, Object> context) { if (context.get("providerType") != null && !(Arrays.asList("aws", "titus")).contains(context.get("providerType"))) { type += "_" + context.get("providerType"); } pipeline.getStages().add(new Stage(pipeline, type, name, context)); return this; }
private List<String> getMetricSetListIds(Execution execution, String stagePrefix) { List<Stage> stages = execution.getStages(); return stages.stream() .filter(stage -> { String refId = stage.getRefId(); return refId != null && refId.startsWith(stagePrefix); }) .map(stage -> resolveMetricSetListId(stage)) .collect(Collectors.toList()); }
/** * Gets the run canary stages that contain the results */ @NotNull protected List<Stage> getRunCanaryStages(@Nonnull Stage stage) { // Collect the Run Canary Stages where the parent id is itself // Sorting by number after the # in the name return stage.getExecution().getStages().stream() .filter(s -> s.getType().equals(RunCanaryStage.STAGE_TYPE)) .sorted(Comparator.comparing(s -> Integer.valueOf(StringUtils.substringAfterLast(s.getName(), "#")))) .collect(Collectors.toList()); }
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); }
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"); }
@JsonIgnore public List<Stage> downstreamStages() { return getExecution() .getStages() .stream() .filter(it -> it.getRequisiteStageRefIds().contains(getRefId())) .collect(toList()); }
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); }
private void onStageStarted(StageStarted event) { Execution execution = retrieve(event); List<Stage> stages = execution.getStages(); stages .stream() .filter(it -> it.getId().equals(event.getStageId())) .findFirst() .ifPresent(stage -> delegate.beforeStage(persister, stage)); }
private void onStageComplete(StageComplete event) { Execution execution = retrieve(event); List<Stage> stages = execution.getStages(); stages .stream() .filter(it -> it.getId().equals(event.getStageId())) .findFirst() .ifPresent(stage -> delegate.afterStage(persister, stage)); }
private String generateRefId() { long offset = parent .getExecution() .getStages() .stream() .filter(i -> parent.getId().equals(i.getParentStageId()) && type == i.getSyntheticStageOwner()) .count(); return format( "%s%s%d", parent.getRefId(), type == STAGE_BEFORE ? "<" : ">", offset + graph.nodes().size() ); }