@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) ); }); }
protected Execution retrieveInternal(RedisClientDelegate delegate, ExecutionType type, String id) throws ExecutionNotFoundException { String key = executionKey(type, id); String indexKey = format("%s:stageIndex", key); boolean exists = delegate.withCommandsClient(c -> { return c.exists(key); }); if (!exists) { throw new ExecutionNotFoundException("No " + type + " found for " + id); } final Map<String, String> map = new HashMap<>(); final List<String> stageIds = new ArrayList<>(); delegate.withTransaction(tx -> { Response<Map<String, String>> execResponse = tx.hgetAll(key); Response<List<String>> indexResponse = tx.lrange(indexKey, 0, -1); tx.exec(); map.putAll(execResponse.get()); if (!indexResponse.get().isEmpty()) { stageIds.addAll(indexResponse.get()); } else { stageIds.addAll(extractStages(map)); } }); Execution execution = new Execution(type, id, map.get("application")); return buildExecution(execution, map, stageIds); }
@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) ); }); }
/** * If {@code executionId} is set, it will be retrieved. Otherwise, {@code pipelineConfigId} will be used to find the * newest pipeline execution for that configuration. * @param executionId An explicit pipeline execution id. * @param pipelineConfigId A pipeline configuration id. Ignored if {@code executionId} is set. * @return The pipeline * @throws IllegalArgumentException if neither executionId or pipelineConfigId are provided * @throws ExecutionNotFoundException if no execution could be found */ public Execution retrievePipelineOrNewestExecution(@Nullable String executionId, @Nullable String pipelineConfigId) throws ExecutionNotFoundException { if (executionId != null) { // Use an explicit execution return executionRepository.retrieve(PIPELINE, executionId); } else if (pipelineConfigId != null) { // No executionId set - use last execution ExecutionRepository.ExecutionCriteria criteria = new ExecutionRepository.ExecutionCriteria().setPageSize(1); try { return executionRepository.retrievePipelinesForPipelineConfigId(pipelineConfigId, criteria) .toSingle() .toBlocking() .value(); } catch (NoSuchElementException e) { throw new ExecutionNotFoundException("No pipeline execution could be found for config id " + pipelineConfigId + ": " + e.getMessage()); } } else { throw new IllegalArgumentException("Either executionId or pipelineConfigId have to be set."); } }
protected ImmutablePair<String, RedisClientDelegate> fetchKey(String id) { ImmutablePair<String, RedisClientDelegate> pair = redisClientDelegate.withCommandsClient(c -> { if (c.exists(pipelineKey(id))) { return ImmutablePair.of(pipelineKey(id), redisClientDelegate); } else if (c.exists(orchestrationKey(id))) { return ImmutablePair.of(orchestrationKey(id), redisClientDelegate); } return ImmutablePair.nullPair(); }); if (pair.getLeft() == null && previousRedisClientDelegate.isPresent()) { RedisClientDelegate delegate = previousRedisClientDelegate.get(); pair = delegate.withCommandsClient(c -> { if (c.exists(pipelineKey(id))) { return ImmutablePair.of(pipelineKey(id), delegate); } else if (c.exists(orchestrationKey(id))) { return ImmutablePair.of(orchestrationKey(id), delegate); } return null; }); } if (pair.getLeft() == null) { throw new ExecutionNotFoundException("No execution found with id " + id); } return pair; }