private Trigger getTrigger() { return stage.getExecution().getTrigger(); }
/** * Enriches stage context if it supports strategies */ @SuppressWarnings("unchecked") public void resolveStrategyParams() { if (execution.getType() == PIPELINE) { Map<String, Object> parameters = Optional.ofNullable(execution.getTrigger()).map(Trigger::getParameters).orElse(emptyMap()); boolean strategy = false; if (parameters.get("strategy") != null) { strategy = (boolean) parameters.get("strategy"); } if (strategy) { context.put("cloudProvider", parameters.get("cloudProvider")); context.put("cluster", parameters.get("cluster")); context.put("credentials", parameters.get("credentials")); if (parameters.get("region") != null) { context.put("regions", singletonList(parameters.get("region"))); } else if (parameters.get("zone") != null) { context.put("zones", singletonList(parameters.get("zone"))); } } } }
private boolean isStrategy(Execution pipeline) { Trigger trigger = pipeline.getTrigger(); return "pipeline".equals(trigger.getType()) && trigger.isStrategy(); }
public LockManager.LockValue build() { final Optional<Execution> execution = Optional.ofNullable(stage).map(Stage::getExecution); final String application = Optional.ofNullable(this.application).orElseGet(() -> execution .map(Execution::getApplication) .orElse(null)); final String type = Optional.ofNullable(this.type).orElseGet(() -> execution .map(Execution::getType) .map(Execution.ExecutionType::toString) .orElse(null)); final String id = Optional.ofNullable(this.id).orElseGet(() -> { if (!execution.isPresent()) { return null; } Optional<Execution> next = execution; Execution rootExecution; do { rootExecution = next.get(); next = next .filter(e -> e.getTrigger() instanceof PipelineTrigger) .map(e -> ((PipelineTrigger) e.getTrigger()).getParentStage()) .map(Stage::getExecution); } while (next.isPresent()); return rootExecution.getId(); }); return new LockManager.LockValue(application, type, id); } }
public @Nonnull List<Artifact> getAllArtifacts(@Nonnull Execution execution) { // Get all artifacts emitted by the execution's stages; we'll sort the stages topologically, // then reverse the result so that artifacts from later stages will appear // earlier in the results. List<Artifact> emittedArtifacts = Stage.topologicalSort(execution.getStages()) .filter(s -> s.getOutputs().containsKey("artifacts")) .flatMap( s -> (Stream<Artifact>) ((List) s.getOutputs().get("artifacts")) .stream() .map(a -> a instanceof Map ? objectMapper.convertValue(a, Artifact.class) : a) ).collect(Collectors.toList()); Collections.reverse(emittedArtifacts); // Get all artifacts in the parent pipeline's trigger; these artifacts go at the end of the list, // after any that were emitted by the pipeline List<Artifact> triggerArtifacts = objectMapper.convertValue(execution.getTrigger().getArtifacts(), new TypeReference<List<Artifact>>() {}); emittedArtifacts.addAll(triggerArtifacts); return emittedArtifacts; }
private String render(String templateString, Execution pipeline) { DefaultRenderContext rc = new DefaultRenderContext(pipeline.getApplication(), null, mapper.convertValue(pipeline.getTrigger(), Map.class)); return renderer.render(templateString, rc); }
public Map<String, Object> buildExecutionContext(Stage stage, boolean includeStageContext) { Map<String, Object> augmentedContext = new HashMap<>(); if (includeStageContext) { augmentedContext.putAll(stage.getContext()); } if (stage.getExecution().getType() == PIPELINE) { augmentedContext.put("trigger", mapper.convertValue( stage.getExecution().getTrigger(), new TypeReference<Map<String, Object>>() {}) ); augmentedContext.put("execution", stage.getExecution()); } return augmentedContext; }
public Map<String, Object> findTargetPackage(boolean allowMissingPackageInstallation) { Map<String, Object> stageContext = new HashMap<>(); // copy the context since we may modify it in createAugmentedRequest stageContext.putAll(stage.getContext()); if (stage.getExecution().getType() == PIPELINE) { Map trigger = mapper.convertValue(stage.getExecution().getTrigger(), Map.class); Map buildInfoCurrentExecution = null; if (stageContext.get("buildInfo") != null) { // package was built as part of the pipeline buildInfoCurrentExecution = mapper.convertValue(stageContext.get("buildInfo"), Map.class); } if (buildInfoCurrentExecution == null || (buildInfoCurrentExecution.get("artifacts") != null && !((Collection) buildInfoCurrentExecution.get("artifacts")).isEmpty())) { Map<String, Object> upstreamBuildInfo = findBuildInfoInUpstreamStage(stage, packageFilePatterns); if (!upstreamBuildInfo.isEmpty()) { buildInfoCurrentExecution = upstreamBuildInfo; } } if (buildInfoCurrentExecution == null) { buildInfoCurrentExecution = emptyMap(); } return createAugmentedRequest(trigger, buildInfoCurrentExecution, stageContext, allowMissingPackageInstallation); } // A package could only have been produced as part of a pipeline, // so if this is not a pipeline return the unchanged context. return stageContext; }
@Override public void taskGraph( @Nonnull Stage stage, @Nonnull TaskNode.Builder builder) { builder.withTask("suspendExecutionDuringTimeWindow", SuspendExecutionDuringTimeWindowTask.class); try { JitterConfig jitter = stage.mapTo("/restrictedExecutionWindow/jitter", JitterConfig.class); if (jitter.enabled && jitter.maxDelay > 0) { if (jitter.skipManual && stage.getExecution().getTrigger().getType().equals("manual")) { return; } long waitTime = ThreadLocalRandom.current().nextLong(jitter.minDelay, jitter.maxDelay + 1); stage.setContext(contextWithWait(stage.getContext(), waitTime)); builder.withTask("waitForJitter", WaitTask.class); } } catch (IllegalArgumentException e) { // Do nothing } }
map.put("origin", execution.getOrigin()); map.put("source", mapper.writeValueAsString(execution.getSource())); map.put("trigger", mapper.writeValueAsString(execution.getTrigger())); map.put("systemNotifications", mapper.writeValueAsString(execution.getSystemNotifications())); } catch (JsonProcessingException e) {
private Execution checkForCorrelatedExecution(Execution execution) { if (execution.getTrigger().getCorrelationId() == null) { return null; } Trigger trigger = execution.getTrigger(); try { Execution o = executionRepository.retrieveByCorrelationId( execution.getType(), trigger.getCorrelationId() ); log.info("Found pre-existing " + execution.getType() + " by correlation id (id: " + o.getId() + ", correlationId: " + trigger.getCorrelationId() + ")"); return o; } catch (ExecutionNotFoundException e) { // Swallow } return null; }
String user = stage.getExecution().getTrigger().getUser();
}); if (execution.getTrigger().getCorrelationId() != null) { c.set( format("correlation:%s", execution.getTrigger().getCorrelationId()), execution.getId() );