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()); }
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; }
String canaryExecutionId = pipeline.getId(); Stage compareJudgeResultsStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals("compareJudgeResults")) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage 'compareJudgeResults' in pipeline ID '" + canaryExecutionId + "'"));
.filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_JUDGE)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + CanaryStageNames.REFID_JUDGE + "' in pipeline ID '" + canaryExecutionId + "'")); .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 + "'")); .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_MIX_METRICS)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + CanaryStageNames.REFID_MIX_METRICS + "' in pipeline ID '" + canaryExecutionId + "'"));
@Nonnull public Stage stageByRef(String refId) { return stages .stream() .filter(it -> refId.equals(it.getRefId())) .findFirst() .orElseThrow(() -> new IllegalArgumentException(String.format("No stage with refId %s exists", refId))); }
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 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()); }
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); }
@VisibleForTesting Collection<String> upstreamImageIds(Stage sourceStage, Collection<String> consideredStageRefIds, String cloudProviderType) { List<Stage> ancestors = sourceStage.ancestors(); List<Stage> imageProvidingAncestorStages = ancestors.stream() .filter(stage -> { String cloudProvider = (String) stage.getContext().getOrDefault("cloudProvider", stage.getContext().get("cloudProviderType")); boolean consideredStageRefIdMatches = consideredStageRefIds == null || consideredStageRefIds.isEmpty() || consideredStageRefIds.contains(stage.getRefId()) || (stage.getParent() != null && consideredStageRefIds.contains(stage.getParent().getRefId())); return consideredStageRefIdMatches && (stage.getContext().containsKey("imageId") || stage.getContext().containsKey("amiDetails")) && cloudProviderType.equals(cloudProvider); }).collect(toList()); return imageProvidingAncestorStages.stream().map(it -> { if (it.getContext().containsKey("imageId")) { return (String) it.getContext().get("imageId"); } else { return (String) ((List<Map>) it.getContext().get("amiDetails")).get(0).get("imageId"); } }).collect(toList()); }
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; }
/** * Makes {@code next} depend on {@code previous} via its * {@link Stage#requisiteStageRefIds}. If either {@code next} or * {@code previous} are not yet present in the graph this method will add them. */ public void connect(@Nonnull Stage previous, @Nonnull Stage next) { add(previous); add(next); Set<String> requisiteStageRefIds = new HashSet<>(next.getRequisiteStageRefIds()); requisiteStageRefIds.add(previous.getRefId()); next.setRequisiteStageRefIds(requisiteStageRefIds); graph.putEdge(previous, next); }
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() ); }
String canaryExecutionId = pipeline.getId(); Stage compareJudgeResultsStage = pipeline.getStages().stream() .filter(stage -> stage.getRefId().equals("compareJudgeResults")) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage 'compareJudgeResults' in pipeline ID '" + canaryExecutionId + "'"));
protected Map<String, String> serializeStage(Stage stage) { String prefix = format("stage.%s.", stage.getId()); Map<String, String> map = new HashMap<>(); map.put(prefix + "refId", stage.getRefId()); map.put(prefix + "type", stage.getType()); map.put(prefix + "name", stage.getName());
.filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_JUDGE)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + CanaryStageNames.REFID_JUDGE + "' in pipeline ID '" + canaryExecutionId + "'")); .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 + "'")); .filter(stage -> stage.getRefId().equals(CanaryStageNames.REFID_MIX_METRICS)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unable to find stage '" + CanaryStageNames.REFID_MIX_METRICS + "' in pipeline ID '" + canaryExecutionId + "'"));