Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package org.openworkflow.sdk.impl;

import org.openworkflow.sdk.impl.lifecycle.EventType;
import org.openworkflow.sdk.impl.lifecycle.LifeCycleEventType;

/**
* @see <a
* href="https://github.com/open-workflow-specification/specification/blob/main/dsl.md#lifecycle-events">Open
Expand All @@ -24,49 +27,50 @@ public final class LifecycleEvents {

private LifecycleEvents() {}

private static final String SPEC_PREFIX = "org.open-workflow-specification.";
private static final String SPEC_PREFIX = LifeCycleEventType.V8.prefix();

/** Notifies about the start of a task. */
public static final String TASK_STARTED = SPEC_PREFIX + "task.started.v1";
public static final String TASK_STARTED = SPEC_PREFIX + EventType.TASK_STARTED.type();

/** Notifies about the completion of a task's execution. */
public static final String TASK_COMPLETED = SPEC_PREFIX + "task.completed.v1";
public static final String TASK_COMPLETED = SPEC_PREFIX + EventType.TASK_COMPLETED.type();

/** Notifies about suspending a task's execution. */
public static final String TASK_SUSPENDED = SPEC_PREFIX + "task.suspended.v1";
public static final String TASK_SUSPENDED = SPEC_PREFIX + EventType.TASK_SUSPENDED.type();

/** Notifies about resuming a task's execution. */
public static final String TASK_RESUMED = SPEC_PREFIX + "task.resumed.v1";
public static final String TASK_RESUMED = SPEC_PREFIX + EventType.TASK_RESUMED.type();

/** Notifies about a task being faulted. */
public static final String TASK_FAULTED = SPEC_PREFIX + "task.faulted.v1";
public static final String TASK_FAULTED = SPEC_PREFIX + EventType.TASK_FAULTED.type();

/** Notifies about the cancellation of a task's execution. */
public static final String TASK_CANCELLED = SPEC_PREFIX + "task.cancelled.v1";
public static final String TASK_CANCELLED = SPEC_PREFIX + EventType.TASK_CANCELLED.type();

/** Notifies about retrying a task's execution. */
public static final String TASK_RETRIED = SPEC_PREFIX + "task.retried.v1";
public static final String TASK_RETRIED = SPEC_PREFIX + EventType.TASK_RETRIED.type();

/** Notifies about the start of a workflow. */
public static final String WORKFLOW_STARTED = SPEC_PREFIX + "workflow.started.v1";
public static final String WORKFLOW_STARTED = SPEC_PREFIX + EventType.WORKFLOW_STARTED.type();

/** Notifies about the completion of a workflow execution. */
public static final String WORKFLOW_COMPLETED = SPEC_PREFIX + "workflow.completed.v1";
public static final String WORKFLOW_COMPLETED = SPEC_PREFIX + EventType.WORKFLOW_COMPLETED.type();

/** Notifies about suspending a workflow execution. */
public static final String WORKFLOW_SUSPENDED = SPEC_PREFIX + "workflow.suspended.v1";
public static final String WORKFLOW_SUSPENDED = SPEC_PREFIX + EventType.WORKFLOW_SUSPENDED.type();

/** Notifies about resuming a workflow execution. */
public static final String WORKFLOW_RESUMED = SPEC_PREFIX + "workflow.resumed.v1";
public static final String WORKFLOW_RESUMED = SPEC_PREFIX + EventType.WORKFLOW_RESUMED.type();

/** Notifies about a workflow being faulted. */
public static final String WORKFLOW_FAULTED = SPEC_PREFIX + "workflow.faulted.v1";
public static final String WORKFLOW_FAULTED = SPEC_PREFIX + EventType.WORKFLOW_FAULTED.type();

/** Notifies about the cancellation of a workflow execution. */
public static final String WORKFLOW_CANCELLED = SPEC_PREFIX + "workflow.cancelled.v1";
public static final String WORKFLOW_CANCELLED = SPEC_PREFIX + EventType.WORKFLOW_CANCELLED.type();

/** Notifies about the change of a workflow's status phase. */
public static final String WORKFLOW_STATUS_CHANGED = SPEC_PREFIX + "workflow.status-changed.v1";
public static final String WORKFLOW_STATUS_CHANGED =
SPEC_PREFIX + EventType.WORKFLOW_STATUS_CHANGED.type();

/**
* CloudEvent extension attribute carried by every lifecycle event, holding the {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -61,6 +62,7 @@
import org.openworkflow.sdk.impl.executors.TaskExecutorFactory;
import org.openworkflow.sdk.impl.expressions.ExpressionFactory;
import org.openworkflow.sdk.impl.expressions.RuntimeDescriptor;
import org.openworkflow.sdk.impl.lifecycle.LifeCycleEventType;
import org.openworkflow.sdk.impl.lifecycle.WorkflowExecutionCompletableListener;
import org.openworkflow.sdk.impl.lifecycle.WorkflowExecutionListener;
import org.openworkflow.sdk.impl.lifecycle.WorkflowExecutionListenerAdapter;
Expand Down Expand Up @@ -116,6 +118,7 @@ public class WorkflowApplication implements AutoCloseable {
private final ScheduledExecutorService schedulerExecutorService;
private final Set<String> allowedCommands;
private final Map<Class<?>, ServiceLoader<?>> servicesLoaded = new ConcurrentHashMap<>();
private final Set<LifeCycleEventType> lifeCycleEventTypes;

private WorkflowApplication(Builder builder) {
this.taskFactory = builder.taskFactory;
Expand Down Expand Up @@ -152,6 +155,7 @@ private WorkflowApplication(Builder builder) {
this.lifeCycleCloudEventFactory = builder.lifeCycleCloudEventFactory;
this.schedulerExecutorService = builder.schedulerExecutorService;
this.allowedCommands = Collections.unmodifiableSet(builder.allowedCommands);
this.lifeCycleEventTypes = builder.lifeCycleEventTypes;
}

public TaskExecutorFactory taskFactory() {
Expand Down Expand Up @@ -280,6 +284,7 @@ public SchemaValidator getValidator(SchemaInline inline) {
private CronResolverFactory cronResolverFactory;
private ScheduledExecutorService schedulerExecutorService;
private Set<String> allowedCommands = new HashSet<>();
private Set<LifeCycleEventType> lifeCycleEventTypes;

private Builder() {
ServiceLoader.load(NamedWorkflowAdditionalObject.class)
Expand Down Expand Up @@ -458,6 +463,11 @@ public Builder withCronResolverFactory(CronResolverFactory cronResolverFactory)
return this;
}

public Builder withLifeCycleEventTypes(Set<LifeCycleEventType> lifeCycleEventTypes) {
this.lifeCycleEventTypes = lifeCycleEventTypes;
return this;
}

public WorkflowApplication build() {
if (executorFactory == null) {
executorFactory = new DefaultExecutorServiceFactory();
Expand Down Expand Up @@ -565,7 +575,9 @@ public CronResolver parseCron(String cron) {
if (authProviderFactory == null) {
authProviderFactory = DefaultAuthProviderFactory.factory();
}

if (lifeCycleEventTypes == null) {
lifeCycleEventTypes = EnumSet.of(LifeCycleEventType.V8);
}
return new WorkflowApplication(this);
}

Expand Down Expand Up @@ -710,6 +722,10 @@ public Set<String> allowedCommands() {
return allowedCommands;
}

public Set<LifeCycleEventType> lifeCycleEventTypes() {
return lifeCycleEventTypes;
}

@SuppressWarnings("unchecked")
public <T extends Comparable<?>> List<T> serviceLoadedClasses(Class<T> clazz) {
ServiceLoader<?> serviceLoader = servicesLoaded.computeIfAbsent(clazz, ServiceLoader::load);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@
*/
package org.openworkflow.sdk.impl.lifecycle;

import org.openworkflow.sdk.impl.LifecycleEvents;

public enum EventType {
TASK_STARTED(LifecycleEvents.TASK_STARTED),
TASK_COMPLETED(LifecycleEvents.TASK_COMPLETED),
TASK_SUSPENDED(LifecycleEvents.TASK_SUSPENDED),
TASK_RESUMED(LifecycleEvents.TASK_RESUMED),
TASK_FAULTED(LifecycleEvents.TASK_FAULTED),
TASK_CANCELLED(LifecycleEvents.TASK_CANCELLED),
TASK_RETRIED(LifecycleEvents.TASK_RETRIED),
WORKFLOW_STARTED(LifecycleEvents.WORKFLOW_STARTED),
WORKFLOW_COMPLETED(LifecycleEvents.WORKFLOW_COMPLETED),
WORKFLOW_SUSPENDED(LifecycleEvents.WORKFLOW_SUSPENDED),
WORKFLOW_RESUMED(LifecycleEvents.WORKFLOW_RESUMED),
WORKFLOW_FAULTED(LifecycleEvents.WORKFLOW_FAULTED),
WORKFLOW_CANCELLED(LifecycleEvents.WORKFLOW_CANCELLED),
WORKFLOW_STATUS_CHANGED(LifecycleEvents.WORKFLOW_STATUS_CHANGED);
TASK_STARTED("task.started.v1"),
TASK_COMPLETED("task.completed.v1"),
TASK_SUSPENDED("task.suspended.v1"),
TASK_RESUMED("task.resumed.v1"),
TASK_FAULTED("task.faulted.v1"),
TASK_CANCELLED("task.cancelled.v1"),
TASK_RETRIED("task.retried.v1"),
WORKFLOW_STARTED("workflow.started.v1"),
WORKFLOW_COMPLETED("workflow.completed.v1"),
WORKFLOW_SUSPENDED("workflow.suspended.v1"),
WORKFLOW_RESUMED("workflow.resumed.v1"),
WORKFLOW_FAULTED("workflow.faulted.v1"),
WORKFLOW_CANCELLED("workflow.cancelled.v1"),
WORKFLOW_STATUS_CHANGED("workflow.status-changed.v1");

private final String lifecycleId;

public String type() {
return this.lifecycleId;
}

@Override
public String toString() {
return this.lifecycleId;
return LifeCycleEventType.V8.fullEventType(this.lifecycleId);
}

EventType(String lifecycleId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020-Present The Open Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openworkflow.sdk.impl.lifecycle;

public enum LifeCycleEventType {
V8("org.open-workflow-specification."),
V7("io.serverlessworkflow.");

private String prefix;

public String prefix() {
return prefix;
}

public String fullEventType(String eventType) {
return prefix + eventType;
}

private LifeCycleEventType(String prefix) {
this.prefix = prefix;
}
}
Loading
Loading