public static WorkflowId parseKey(String key) { final int hashPos = key.indexOf('#'); if (hashPos < 1) { throw new IllegalArgumentException("Key must contain a hash '#' sign on position > 0"); } return create(key.substring(0, hashPos), key.substring(hashPos + 1)); } }
private Response<Workflow> workflow(String componentId, String id) { try { return storage.workflow(WorkflowId.create(componentId, id)) .map(Response::forPayload) .orElse(Response.forStatus(Status.NOT_FOUND)); } catch (IOException e) { throw Throwables.propagate(e); } }
private EventsPayload eventsForWorkflowInstance(String cid, String eid, String iid) { final WorkflowId workflowId = WorkflowId.create(cid, eid); final WorkflowInstance workflowInstance = WorkflowInstance.create(workflowId, iid); try { final Set<SequenceEvent> sequenceEvents = storage.readEvents(workflowInstance); final List<EventsPayload.TimestampedEvent> timestampedEvents = sequenceEvents.stream() .map(sequenceEvent -> EventsPayload.TimestampedEvent.create( sequenceEvent.event(), sequenceEvent.timestamp())) .collect(toList()); return EventsPayload.create(timestampedEvents); } catch (IOException e) { throw new RuntimeException(e); } } }
try { if (componentOpt.isPresent() && workflowOpt.isPresent()) { final WorkflowId workflowId = WorkflowId.create(componentOpt.get(), workflowOpt.get()); backfills = storage.backfillsForWorkflowId(showAll, workflowId).stream(); } else if (componentOpt.isPresent()) {
private WorkflowId parseWorkflowId(Entity workflow) { final String componentId = workflow.getKey().getAncestors().get(0).getName(); final String id = workflow.getKey().getName(); return WorkflowId.create(componentId, id); }
private WorkflowInstance parseWorkflowInstance(Entity activeWorkflowInstance) { final String componentId = activeWorkflowInstance.getString(PROPERTY_COMPONENT); final String workflowId = activeWorkflowInstance.getString(PROPERTY_WORKFLOW); final String parameter = activeWorkflowInstance.getString(PROPERTY_PARAMETER); return WorkflowInstance.create(WorkflowId.create(componentId, workflowId), parameter); }
private Response<WorkflowState> state(String componentId, String id) { try { return Response.forPayload(storage.workflowState(WorkflowId.create(componentId, id))); } catch (IOException e) { return Response .forStatus(Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Couldn't fetch state.")); } }
private Response<ByteString> deleteWorkflow(String cid, String wfid, AuthContext ac) { final WorkflowId workflowId = WorkflowId.create(cid, wfid); final Optional<Workflow> workflow; try { workflow = storage.workflow(workflowId); } catch (IOException e) { final String message = String.format("Couldn't read workflow %s. ", workflowId); LOG.warn(message, e); return Response.forStatus(Status.INTERNAL_SERVER_ERROR .withReasonPhrase("Error in internal storage")); } if (!workflow.isPresent()) { return Response.forStatus(Status.NOT_FOUND.withReasonPhrase("Workflow does not exist")); } // TODO: run in transaction workflowActionAuthorizer.authorizeWorkflowAction(ac, workflow.get()); try { storage.delete(workflowId); } catch (IOException e) { final String message = String.format("Couldn't remove workflow %s. ", workflowId); LOG.warn(message, e); return Response.forStatus(Status.INTERNAL_SERVER_ERROR .withReasonPhrase("Error in internal storage")); } workflowConsumer.accept(workflow, Optional.empty()); LOG.info("Workflow removed: {}", workflowId); return Response.forStatus(Status.NO_CONTENT); }
@Override public CompletionStage<Void> retryWorkflowInstance(String componentId, String workflowId, String parameter) { final Builder url = urlBuilder("scheduler", "retry"); final WorkflowInstance workflowInstance = WorkflowInstance.create( WorkflowId.create(componentId, workflowId), parameter); return execute(forUri(url, "POST", workflowInstance)) .thenApply(response -> null); }
@Override public CompletionStage<Void> haltWorkflowInstance(String componentId, String workflowId, String parameter) { final Builder url = urlBuilder("scheduler", "halt"); final WorkflowInstance workflowInstance = WorkflowInstance.create( WorkflowId.create(componentId, workflowId), parameter); return execute(forUri(url, "POST", workflowInstance)) .thenApply(response -> null); }
@Override public CompletionStage<Void> triggerWorkflowInstance(String componentId, String workflowId, String parameter, TriggerParameters triggerParameters, boolean allowFuture) { final TriggerRequest triggerRequest = TriggerRequest.of(WorkflowId.create(componentId, workflowId), parameter, triggerParameters); return execute( forUri(urlBuilder("scheduler", "trigger") .addQueryParameter("allowFuture", String.valueOf(allowFuture)), "POST", triggerRequest)) .thenApply(response -> null); }
String id, Request request) { final WorkflowId workflowId = WorkflowId.create(componentId, id); final String offset = request.parameter("offset").orElse(""); final int limit = request.parameter("limit").map(Integer::parseInt).orElse(DEFAULT_PAGE_LIMIT);
final WorkflowId workflowId = WorkflowId.create(componentId, id); workflowActionAuthorizer.authorizeWorkflowAction(ac, workflowId);
private Response<WorkflowInstanceExecutionData> instance( String componentId, String id, String instanceId) { final WorkflowId workflowId = WorkflowId.create(componentId, id); final WorkflowInstance workflowInstance = WorkflowInstance.create(workflowId, instanceId); try { final WorkflowInstanceExecutionData workflowInstanceExecutionData = storage.executionData(workflowInstance); return Response.forPayload(workflowInstanceExecutionData); } catch (ResourceNotFoundException e) { return Response.forStatus(Status.NOT_FOUND.withReasonPhrase(e.getMessage())); } catch (IOException e) { return Response.forStatus( Status.INTERNAL_SERVER_ERROR.withReasonPhrase("Couldn't fetch execution info.")); } }
final WorkflowId workflowId = WorkflowId.create(input.component(), input.workflow()); final Workflow workflow; try {
static Backfill entityToBackfill(Entity entity) throws IOException { final WorkflowId workflowId = WorkflowId.create(entity.getString(PROPERTY_COMPONENT), entity.getString(PROPERTY_WORKFLOW)); final BackfillBuilder builder = Backfill.newBuilder() .id(entity.getKey().getName()) .start(timestampToInstant(entity.getTimestamp(PROPERTY_START))) .end(timestampToInstant(entity.getTimestamp(PROPERTY_END))) .workflowId(workflowId) .concurrency((int) entity.getLong(PROPERTY_CONCURRENCY)) .nextTrigger(timestampToInstant(entity.getTimestamp(PROPERTY_NEXT_TRIGGER))) .schedule(Schedule.parse(entity.getString(PROPERTY_SCHEDULE))) .allTriggered(entity.getBoolean(PROPERTY_ALL_TRIGGERED)) .halted(entity.getBoolean(PROPERTY_HALTED)) .reverse(read(entity, PROPERTY_REVERSE, Boolean.FALSE)); if (entity.contains(PROPERTY_DESCRIPTION)) { builder.description(entity.getString(PROPERTY_DESCRIPTION)); } if (entity.contains(PROPERTY_TRIGGER_PARAMETERS)) { builder.triggerParameters(OBJECT_MAPPER.readValue( entity.getString(PROPERTY_TRIGGER_PARAMETERS), TriggerParameters.class)); } return builder.build(); }