@ApiOperation(value = "Cancel a pipeline execution") @RequestMapping(value = "/{executionId}/cancel", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.ACCEPTED) void cancel(@PathVariable String executionId) { log.info("Cancelling pipeline execution {}...", executionId); Execution pipeline = executionRepository.retrieve(Execution.ExecutionType.PIPELINE, executionId); if (pipeline.getStatus().isComplete()) { log.debug("Not changing status of pipeline execution {} to CANCELED since execution is already completed: {}", executionId, pipeline.getStatus()); return; } executionRepository.cancel(Execution.ExecutionType.PIPELINE, executionId); executionRepository.updateStatus(Execution.ExecutionType.PIPELINE, executionId, ExecutionStatus.CANCELED); }
.orElseThrow(() -> new IllegalArgumentException("Unable to find stage 'compareJudgeResults' in pipeline ID '" + canaryExecutionId + "'")); Map<String, Object> compareJudgeResultsOutputs = compareJudgeResultsStage.getOutputs(); Boolean isComplete = pipeline.getStatus().isComplete(); String pipelineStatus = pipeline.getStatus().toString().toLowerCase(); ImmutableMap.Builder<String, Object> comparisonResult = ImmutableMap.builder();
@ApiOperation(value = "Cancel a pipeline execution") @RequestMapping(value = "/{executionId}/cancel", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.ACCEPTED) void cancel(@PathVariable String executionId) { log.info("Cancelling pipeline execution {}...", executionId); Execution pipeline = executionRepository.retrieve(Execution.ExecutionType.PIPELINE, executionId); if (pipeline.getStatus().isComplete()) { log.debug("Not changing status of pipeline execution {} to CANCELED since execution is already completed: {}", executionId, pipeline.getStatus()); return; } executionRepository.cancel(Execution.ExecutionType.PIPELINE, executionId); executionRepository.updateStatus(Execution.ExecutionType.PIPELINE, executionId, ExecutionStatus.CANCELED); }
@Override public @Nonnull List<Execution> retrieveBufferedExecutions() { List<Observable<Execution>> observables = allRedisDelegates().stream() .map(d -> Arrays.asList( retrieveObservable(PIPELINE, allBufferedExecutionsKey(PIPELINE), queryAllScheduler, d), retrieveObservable(ORCHESTRATION, allBufferedExecutionsKey(ORCHESTRATION), queryAllScheduler, d) )) .flatMap(List::stream) .collect(Collectors.toList()); return Observable.merge(observables) .filter(e -> e.getStatus() == BUFFERED) .toList() .toBlocking().single(); }
boolean hasCompletedExecution(PinnedServerGroupTag pinnedServerGroupTag) { try { Execution execution = executionRepository.retrieve( pinnedServerGroupTag.executionType, pinnedServerGroupTag.executionId ); return execution.getStatus().isComplete(); } catch (ExecutionNotFoundException e) { return true; } catch (Exception e) { log.warn("Unable to determine status of execution (executionId: {})", pinnedServerGroupTag.executionId, e); errorsCounter.increment(); return false; } }
@Override public @Nonnull List<Execution> retrievePipelinesForPipelineConfigIdsBetweenBuildTimeBoundary( @Nonnull List<String> pipelineConfigIds, long buildTimeStartBoundary, long buildTimeEndBoundary, ExecutionCriteria executionCriteria ) { List<Execution> executions = new ArrayList<>(); allRedisDelegates() .forEach(d -> { List<Execution> pipelines = getPipelinesForPipelineConfigIdsBetweenBuildTimeBoundaryFromRedis( d, pipelineConfigIds, buildTimeStartBoundary, buildTimeEndBoundary ); executions.addAll(pipelines); }); return executions.stream() .filter( it -> { if (executionCriteria.getStatuses().isEmpty()) { return true; } else { return executionCriteria.getStatuses().contains(it.getStatus()); } }) .collect(Collectors.toList()); }
@Override public Boolean call(Execution execution) { if (!COMPLETED_STATUSES.contains(execution.getStatus().toString())) { return false; } long startTime = execution.getStartTime() == null ? execution.getBuildTime() : execution.getStartTime(); return startTime <= (Instant.ofEpochMilli(clock.millis()).minus(thresholdDays, ChronoUnit.DAYS).toEpochMilli()); } };
.orElseThrow(() -> new IllegalArgumentException("Unable to find stage 'compareJudgeResults' in pipeline ID '" + canaryExecutionId + "'")); Map<String, Object> compareJudgeResultsOutputs = compareJudgeResultsStage.getOutputs(); Boolean isComplete = pipeline.getStatus().isComplete(); String pipelineStatus = pipeline.getStatus().toString().toLowerCase(); ImmutableMap.Builder<String, Object> comparisonResult = ImmutableMap.builder();
@Override public @Nonnull Observable<Execution> retrieve( @Nonnull ExecutionType type, @Nonnull ExecutionCriteria criteria ) { List<Observable<Execution>> observables = allRedisDelegates() .stream() .map(d -> { Observable<Execution> observable = all(type, d); if (!criteria.getStatuses().isEmpty()) { observable = observable.filter(execution -> criteria.getStatuses().contains(execution.getStatus())); } if (criteria.getPageSize() > 0) { observable = observable.limit(criteria.getPageSize()); } return observable; } ) .collect(Collectors.toList()); return Observable.merge(observables); }
@Override public void afterExecution(Persister persister, Execution execution, ExecutionStatus executionStatus, boolean wasSuccessful) { if (!execution.getStatus().isSuccessful()) { // only want to cleanup executions that successfully completed return; } List<Stage> stages = execution.getStages(); stages.forEach(it -> { if (it.getContext().containsKey("targetReferences")) { // remove `targetReferences` as it's large and unnecessary after a pipeline has completed it.getContext().remove("targetReferences"); persister.save(it); } }); }
map.put("endTime", execution.getEndTime() != null ? execution.getEndTime().toString() : null); map.put("startTimeExpiry", execution.getStartTimeExpiry() != null ? String.valueOf(execution.getStartTimeExpiry()) : null); map.put("status", execution.getStatus().name()); map.put("authentication", mapper.writeValueAsString(execution.getAuthentication())); map.put("paused", mapper.writeValueAsString(execution.getPaused()));
@Override public @Nonnull Execution retrieveOrchestrationForCorrelationId( @Nonnull String correlationId) throws ExecutionNotFoundException { String key = format("correlation:%s", correlationId); return getRedisDelegate(key).withCommandsClient(correlationRedis -> { String orchestrationId = correlationRedis.get(key); if (orchestrationId != null) { Execution orchestration = retrieveInternal( getRedisDelegate(orchestrationKey(orchestrationId)), ORCHESTRATION, orchestrationId); if (!orchestration.getStatus().isComplete()) { return orchestration; } correlationRedis.del(key); } throw new ExecutionNotFoundException( format("No Orchestration found for correlation ID %s", correlationId) ); }); }
@Nonnull @Override public Execution retrievePipelineForCorrelationId(@Nonnull String correlationId) throws ExecutionNotFoundException { String key = format("pipelineCorrelation:%s", correlationId); return getRedisDelegate(key).withCommandsClient(correlationRedis -> { String pipelineId = correlationRedis.get(key); if (pipelineId != null) { Execution pipeline = retrieveInternal( getRedisDelegate(pipelineKey(pipelineId)), PIPELINE, pipelineId ); if (!pipeline.getStatus().isComplete()) { return pipeline; } correlationRedis.del(key); } throw new ExecutionNotFoundException( format("No Pipeline found for correlation ID %s", correlationId) ); }); }
c.sadd(appKey(execution.getType(), execution.getApplication()), execution.getId()); if (execution.getStatus() == BUFFERED) { c.sadd(allBufferedExecutionsKey(execution.getType()), execution.getId()); } else {