private boolean isTopLevelStage(Stage stage) { return stage.getParentStageId() == null; }
@Override public void addStage(@Nonnull Stage stage) { if (stage.getSyntheticStageOwner() == null || stage.getParentStageId() == null) { throw new IllegalArgumentException("Only synthetic stages can be inserted ad-hoc"); } storeStageInternal(getRedisDelegate(stage), stage, true); }
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() ); }
execution.getStages().addAll( stages.stream() .filter(s -> s.getParentStageId() == null) .sorted(Comparator.comparing(Stage::getRefId)) .collect(Collectors.toList()) .filter(s -> s.getParentStageId() != null) .sorted(Comparator.comparing(Stage::getRefId)) .forEach(
private void storeStageInternal(RedisClientDelegate delegate, Stage stage, Boolean updateIndex) { String key = executionKey(stage); String indexKey = format("%s:stageIndex", key); Map<String, String> serializedStage = serializeStage(stage); List<String> keysToRemove = serializedStage.entrySet().stream() .filter(e -> e.getValue() == null) .map(Map.Entry::getKey) .collect(Collectors.toList()); serializedStage.values().removeIf(Objects::isNull); delegate.withTransaction(tx -> { tx.hmset(key, serializedStage); if (!keysToRemove.isEmpty()) { tx.hdel(key, keysToRemove.toArray(new String[0])); } if (updateIndex) { BinaryClient.LIST_POSITION pos = stage.getSyntheticStageOwner() == STAGE_BEFORE ? BEFORE : AFTER; tx.linsert(indexKey, pos, stage.getParentStageId(), stage.getId()); } tx.exec(); }); }
/** * A Stage is optional if it has an {@link OptionalStageEvaluator} in its * context that evaluates {@code false}. */ public static boolean isOptional(Stage stage, ContextParameterProcessor contextParameterProcessor) { Map stageEnabled = (Map) stage.getContext().get("stageEnabled"); String type = stageEnabled == null ? null : (String) stageEnabled.get("type"); String optionalType = type == null ? null : type.toLowerCase(); if (!OPTIONAL_STAGE_TYPES.containsKey(optionalType)) { if (stage.getSyntheticStageOwner() != null || stage.getParentStageId() != null) { Stage parentStage = stage .getExecution() .getStages() .stream() .filter(it -> it.getId().equals(stage.getParentStageId())) .findFirst() .orElseThrow(() -> new IllegalStateException(format("stage %s not found", stage.getParentStageId()))); return isOptional(parentStage, contextParameterProcessor); } return false; } try { return !stage.mapTo("/stageEnabled", OPTIONAL_STAGE_TYPES.get(optionalType)).evaluate(stage, contextParameterProcessor); } catch (InvalidExpression e) { log.warn("Unable to determine stage optionality, reason: {} (executionId: {}, stageId: {})", e.getMessage(), stage.getExecution().getId(), stage.getId()); return false; } }
r -> r.getStageBuilder() instanceof AcquireLockStage) .filter(r -> stage.getParentStageId() == null ? r.getStage().getParentStageId() == null : stage.getParentStageId().equals(r.getStage().getParentStageId())) .findFirst();
map.put(prefix + "status", stage.getStatus().name()); 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()