@Override public List<Workflow> workflows(String componentId) throws IOException { return workflowStore.values().stream() .filter(w -> w.componentId().equals(componentId)) .collect(Collectors.toList()); }
private void printWorkflow(Workflow workflow, int cidLength, int widLength) { final String format = WORKFLOW_FORMAT .replaceAll("<cid-length>", String.valueOf(cidLength)) .replaceAll("<wid-length>", String.valueOf(widLength)); System.out.println(String.format(format, workflow.componentId(), workflow.workflowId())); }
@Override public void printWorkflows(List<Workflow> workflows) { final int cidLength = workflows.stream() .map(x -> x.componentId().length()) .max(Comparator.naturalOrder()) .orElse(1); final int widLength = workflows.stream() .map(x -> x.workflowId().length()) .max(Comparator.naturalOrder()) .orElse(1); printWorkflowHeader(cidLength, widLength); workflows.forEach(wf -> printWorkflow(wf, cidLength, widLength)); }
public static WorkflowId ofWorkflow(Workflow workflow) { return new AutoValue_WorkflowId(workflow.componentId(), workflow.workflowId()); }
@Override public void printWorkflow(Workflow wf, WorkflowState state) { System.out.println("Component: " + wf.componentId()); System.out.println(" Workflow: " + wf.id().id()); System.out.println(" Schedule: " + wf.configuration().schedule()); System.out.println(" Offset: " + wf.configuration().offset().orElse("")); System.out.println(" Image: " + wf.configuration().dockerImage().orElse("")); System.out.println(" Args: " + wf.configuration().dockerArgs().orElse(Collections.emptyList())); System.out.println(" TermLog: " + wf.configuration().dockerTerminationLogging()); System.out.println(" Secret: " + wf.configuration().secret().map(s -> s.name() + ':' + s.mountPath()).orElse("")); System.out.println(" Svc Acct: " + wf.configuration().serviceAccount().orElse("")); System.out.println("Resources: " + wf.configuration().resources()); System.out.println(" Env: " + Joiner.on(' ').withKeyValueSeparator('=').join(wf.configuration().env())); System.out.println(" Timeout: " + wf.configuration().runningTimeout().map(Duration::toString).orElse("")); System.out.println(" Commit: " + wf.configuration().commitSha().orElse("")); System.out.println(" Enabled: " + state.enabled().map(Object::toString).orElse("")); System.out.println(" Trig: " + state.nextNaturalTrigger().map(Object::toString).orElse("")); System.out.println("Ofst Trig: " + state.nextNaturalOffsetTrigger().map(Object::toString).orElse("")); }
@Override public void printWorkflow(Workflow wf, WorkflowState state) { System.out.println(Joiner.on(' ').join( wf.componentId(), wf.id().id(), wf.configuration().schedule(), wf.configuration().offset().orElse(""), wf.configuration().dockerImage().orElse(""), wf.configuration().dockerArgs().orElse(Collections.emptyList()), wf.configuration().dockerTerminationLogging(), wf.configuration().secret().map(s -> s.name() + ':' + s.mountPath()).orElse(""), wf.configuration().serviceAccount().map(Object::toString).orElse(""), wf.configuration().resources(), wf.configuration().env(), wf.configuration().runningTimeout().map(Duration::toString).orElse(""), wf.configuration().commitSha().orElse(""), state.enabled().map(Object::toString).orElse(""), state.nextNaturalTrigger().map(Object::toString).orElse(""), state.nextNaturalOffsetTrigger().map(Object::toString).orElse(""))); }
final Workflow created = future.toCompletableFuture().get(); cliOutput.printMessage("Workflow " + created.workflowId() + " in component " + created.componentId() + " created.");
@Override public WorkflowId store(Workflow workflow) throws IOException { final Key componentKey = DatastoreStorage.componentKey(tx.getDatastore().newKeyFactory(), workflow.componentId()); if (tx.get(componentKey) == null) { tx.put(Entity.newBuilder(componentKey).build()); } final String json = OBJECT_MAPPER.writeValueAsString(workflow); final Key workflowKey = DatastoreStorage.workflowKey(tx.getDatastore().newKeyFactory(), workflow.id()); final Optional<Entity> workflowOpt = DatastoreStorage.getOpt(tx, workflowKey); final Entity workflowEntity = DatastoreStorage.asBuilderOrNew(workflowOpt, workflowKey) .set(PROPERTY_WORKFLOW_JSON, StringValue.newBuilder(json).setExcludeFromIndexes(true).build()) .build(); tx.put(workflowEntity); return workflow.id(); }
@Override public WorkflowId storeWorkflowWithNextNaturalTrigger(Workflow workflow, TriggerInstantSpec triggerSpec) throws IOException { final Key componentKey = DatastoreStorage.componentKey(tx.getDatastore().newKeyFactory(), workflow.componentId()); if (tx.get(componentKey) == null) { tx.put(Entity.newBuilder(componentKey).build()); } final String json = OBJECT_MAPPER.writeValueAsString(workflow); final Key workflowKey = DatastoreStorage.workflowKey(tx.getDatastore().newKeyFactory(), workflow.id()); final Optional<Entity> workflowOpt = DatastoreStorage.getOpt(tx, workflowKey); final Builder entity = DatastoreStorage.asBuilderOrNew(workflowOpt, workflowKey) .set(PROPERTY_WORKFLOW_JSON, StringValue.newBuilder(json).setExcludeFromIndexes(true).build()) .set(PROPERTY_NEXT_NATURAL_TRIGGER, instantToTimestamp(triggerSpec.instant())) .set(PROPERTY_NEXT_NATURAL_OFFSET_TRIGGER, instantToTimestamp(triggerSpec.offsetInstant())); tx.put(entity.build()); return workflow.id(); }