Workflow LCM worklets
Workflow LCM would have default worklets in the framework
1) Jump worklet :- In the same workflow cahin, jump from any worklet to any other worklet in the workflow process.
2) State worklet :- State of the current workflow process.
3) Pass worklet :- Pause the execution of the current workflow process.
Change-Id: I4b7285c373e9211a0dc9fed58e69188e7bb53a2e
diff --git a/apps/workflow/api/src/main/java/org/onosproject/workflow/api/CustomLcmState.java b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/CustomLcmState.java
new file mode 100644
index 0000000..d879fc2
--- /dev/null
+++ b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/CustomLcmState.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2024-present Open Networking Foundation
+ *
+ * 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.onosproject.workflow.api;
+
+/**
+ * Custom State of LCM.
+ */
+public enum CustomLcmState {
+
+ /**
+ * Workflow lcm is pending state.
+ */
+ PENDING,
+
+ /**
+ * Workflow lcm is pending state.
+ */
+ PAUSED
+}
diff --git a/apps/workflow/api/src/main/java/org/onosproject/workflow/api/JumpWorklet.java b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/JumpWorklet.java
new file mode 100644
index 0000000..1336ac1
--- /dev/null
+++ b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/JumpWorklet.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2024-present Open Networking Foundation
+ *
+ * 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.onosproject.workflow.api;
+
+/**
+ * A class representing jump behavior in workflow.
+ */
+public class JumpWorklet extends AbstractBranchWorklet {
+
+ @Override
+ public boolean isBranch(WorkflowContext context) throws WorkflowException {
+ return true;
+ }
+}
+
diff --git a/apps/workflow/api/src/main/java/org/onosproject/workflow/api/PassWorklet.java b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/PassWorklet.java
new file mode 100644
index 0000000..bd0a472
--- /dev/null
+++ b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/PassWorklet.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2024-present Open Networking Foundation
+ *
+ * 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.onosproject.workflow.api;
+
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class PassWorklet extends AbstractWorklet {
+
+
+ protected static final Logger log = getLogger(PassWorklet.class);
+
+ @Override
+ public boolean needsProcess(WorkflowContext context) throws WorkflowException {
+ return true;
+ }
+
+ @Override
+ public void process(WorkflowContext context) throws WorkflowException {
+ log.info("Workflow-process: {}@{} ",
+ this.getClass().getSimpleName(), context.workplaceName());
+ context.completed();
+ }
+
+}
+
+
diff --git a/apps/workflow/api/src/main/java/org/onosproject/workflow/api/StateWorklet.java b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/StateWorklet.java
new file mode 100644
index 0000000..64a42e8
--- /dev/null
+++ b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/StateWorklet.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2024-present Open Networking Foundation
+ *
+ * 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.onosproject.workflow.api;
+
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class StateWorklet extends AbstractWorklet {
+
+ // Path for lcm state.
+ public static final String STATE_PATH = "/custom-state";
+
+ @StaticDataModel(path = STATE_PATH)
+ String state;
+
+ protected static final Logger log = getLogger(StateWorklet.class);
+
+ @Override
+ public boolean needsProcess(WorkflowContext context) throws WorkflowException {
+ return true;
+ }
+
+ @Override
+ public void process(WorkflowContext context) throws WorkflowException {
+ log.info("Workflow-process: {}@{} ",
+ this.getClass().getSimpleName(), context.workplaceName());
+ context.setLcmState(CustomLcmState.valueOf(state));
+ context.completed();
+ }
+}
+
+
diff --git a/apps/workflow/api/src/main/java/org/onosproject/workflow/api/WorkflowContext.java b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/WorkflowContext.java
index 836524d..ba5aa11 100644
--- a/apps/workflow/api/src/main/java/org/onosproject/workflow/api/WorkflowContext.java
+++ b/apps/workflow/api/src/main/java/org/onosproject/workflow/api/WorkflowContext.java
@@ -187,4 +187,13 @@
* @throws WorkflowException workflow exception
*/
public abstract <T> T getService(Class<T> serviceClass) throws WorkflowException;
+
+ /**
+ * Set custom lcm state of the workflow.
+ *
+ * @param lcmState custom lcm state
+ */
+ public void setLcmState(CustomLcmState lcmState) {
+ return;
+ }
}