@JsonIgnore public boolean isJoin() { return getRequisiteStageRefIds().size() > 1; }
@JsonIgnore public List<Stage> downstreamStages() { return getExecution() .getStages() .stream() .filter(it -> it.getRequisiteStageRefIds().contains(getRefId())) .collect(toList()); }
/** * Builds and returns the stages represented in the graph. This method is not * typically useful to implementors of {@link StageDefinitionBuilder}, it's used * internally and by tests. */ public @Nonnull Iterable<Stage> build() { requiredPrefix.ifPresent(prefix -> graph.nodes().forEach(it -> { if (it != prefix && it.getRequisiteStageRefIds().isEmpty()) { connect(prefix, it); } })); return graph.nodes(); }
/** * Sorts stages into order according to their refIds / requisiteStageRefIds. */ public static Stream<Stage> topologicalSort(Collection<Stage> stages) { List<Stage> unsorted = stages.stream().filter(it -> it.parentStageId == null).collect(toList()); ImmutableList.Builder<Stage> sorted = ImmutableList.builder(); Set<String> refIds = new HashSet<>(); while (!unsorted.isEmpty()) { List<Stage> sortable = unsorted.stream() .filter(it -> refIds.containsAll(it.getRequisiteStageRefIds())) .collect(toList()); if (sortable.isEmpty()) { throw new IllegalStateException( format( "Invalid stage relationships found %s", join(", ", stages.stream().map(it -> format("%s->%s", it.requisiteStageRefIds, it.refId)).collect(toList())) ) ); } sortable .forEach(it -> { unsorted.remove(it); refIds.add(it.refId); sorted.add(it); }); } return sorted.build().stream(); }
/** * 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); }
map.put(prefix + "syntheticStageOwner", stage.getSyntheticStageOwner() != null ? stage.getSyntheticStageOwner().name() : null); map.put(prefix + "parentStageId", stage.getParentStageId()); if (!stage.getRequisiteStageRefIds().isEmpty()) { map.put(prefix + "requisiteStageRefIds", stage.getRequisiteStageRefIds().stream() .collect(Collectors.joining(",")) );