Developing, Managing, and Running Workflows
In this section you’ll learn how to:
-
Develop a workflow on OpenShift or Kubernetes using the SonataFlow development profile.
-
Deploy workflows on OpenShift via Helm using a pre-built example.
-
Run a workflow using Orchestrator in Red Hat Developer Hub.
Developing Workflows on OpenShift
It’s impractical to cover all aspects of development for SonataFlow and Serverless Workflow in this module, however you’ll get hands on with a basic example that demonstrates a basic Operator-based development flow. After this, you’ll learn how to make the workflow available in Red Hat Developer Hub.
To learn about developing workflows locally using the kn CLI and the workflow extension for it, view the relevant SonataFlow documentation.
|
Create a Workflow in Dev Mode
-
Visit the tssc-dh project in the OpenShift Web Console.
-
Click the plus (+) icon in the top navigation, and choose Import YAML.
-
Paste the following YAML and click create:
apiVersion: sonataflow.org/v1alpha08 kind: SonataFlow metadata: namespace: tssc-dh name: greeting annotations: # Setting the profile to dev mode allows us to run the underlying # Quarkus server in dev mode - meaning we can use the dev UI to # test and debug the workflow sonataflow.org/profile: dev sonataflow.org/description: Greeting example on OpenShift! sonataflow.org/version: 0.0.1 app.kubernetes.io/part-of: sonataflow-platform spec: flow: start: ChooseOnLanguage functions: - name: greetFunction type: custom operation: sysout states: - name: ChooseOnLanguage type: switch dataConditions: - condition: "${ .language == \"English\" }" transition: GreetInEnglish - condition: "${ .language == \"Spanish\" }" transition: GreetInSpanish defaultCondition: GreetInEnglish - name: GreetInEnglish type: inject data: greeting: "Hello from JSON Workflow, " transition: GreetPerson - name: GreetInSpanish type: inject data: greeting: "Saludos desde JSON Workflow, " transition: GreetPerson - name: GreetPerson type: operation actions: - name: greetAction functionRef: refName: greetFunction arguments: message: ".greeting+.name" end: true -
A new SonataFlow resource will appear in the Topology View. Click it and wait for the Pod to enter the Running status.
-
Click the arrow next to the Pod on the Topology view, then visit the
/q/dev-uiendpoint to view the Quarkus Dev UI. Alternatively, this link will take your directly to your Dev UI.Quarkus is the application framework that exposes REST endpoints, performs validation, and even provides extensions such as sysoutin our sample workflow. The Serverless Logic Operator uses kogito-codegen to generate Java code from your workflow definition and JSON schemas.
An important part of the SonataFlow workflow CR you deployed is the sonataflow.org/profile annotation that’s set to dev. This annotation instructs the Serverless Logic Operator to start the Quarkus application (that’s hosting the workflow) in development mode. That’s why the Quarkus Dev UI is available.
Experimenting with the Quarkus Dev UI
Use the Quarkus Dev UI to test a workflow.
-
Click the Workflows link inside the Serverless Workflows Tools box.
-
Click the Workflow Definitions tab. Workflow definitions including the new greeting workflow will be listed.
-
Click the play button under the Actions column for the greeting.
-
Enter the following JSON in the Start Workflow Data, then click Start:
{ "language": "English"}You can expand the up arrow (this ^ icon) at the bottom of the Quarkus Dev UI to expand a pane showing the application logs. This provides additional insight into the workflow’s execution. -
Return to the Workflow Instances tab. Your workflow run will be listed.
-
Click the greeting link. The workflow run details are listed, showing that that the English branch was executed.
-
Scroll down and you’ll see that "Hello from JSON Workflow" is in the
workflowdataoutput.
Edit the Workflow
-
Return to the OpenShift Web Console, and return to the tssc-dh project’s Topology view.
-
Edit the greeting SonataFlow by clicking the three dots on the SF item in the Topology view.
-
Switch to the YAML editor.
-
Update the Spanish entry in
ChooseOnLanguageconditions to check for "Irish" and change thetransitionto "GreetInIrish" -
Find the corresponding
GreetInSpanishstate and change it toGreetInIrish. -
Additionally, change the
data.greetingtoHáigh ó JSON workflow,
-
Scroll down and click Save.
-
Next, visit the Pod logs of the greeting Pod. Notice that it restarts Quarkus? You should see the Quarkus logo printed - indicating a restart of the framework.
Test the workflow again, but pass the "Irish" as the language and observe the results.
Integrate a Workflow with Orchestrator
When it’s time to deploy a production-ready workflow, you need to build it into a container image and run it using the gitops profile. This is outlined in the SonataFlow Deployment Profiles Guide. In this section you’ll use a pre-built image to save time.
| The source code and scripts to build this sample workflow can be found in redhat-ads-tech/orchestrator-workflows on GitHub. |
Install a Production-Ready Workflow
To start, delete the development version of the greeting workflow:
-
Open the OpenShift Web Console, and return to the tssc-dh project’s Topology view.
-
Delete the greeting SonataFlow by clicking the three dots on the SF item in the Topology view, then clicking Delete SonataFlow.
Next, use the OpenShift Web Terminal to deploy the production version of the greeting workflow:
-
Click the Web Terminal (>_) icon in the top navigation of the OpenShift Web Console.
-
Launch a terminal in the popup using the default settings. Once the terminal starts, run these commands:
-
Set the current project context to tssc-dh:
oc project tssc-dh -
Add a Helm repository that contains sample workflows:
helm repo add workflows https://redhat-ads-tech.github.io/orchestrator-workflows/ -
Install the greeting workflow:
helm install greeting-workflow workflows/greeting -n tssc-dh
-
-
The new greeting service will appear in the Topology view.
-
Additionally, if you log into {rhdh_url}[Red Hat Developer Hub^] (using
{rhdh_user}/{rhdh_user_password}) you’ll now see that Greeting workflow is listed.
|
If the greeting workflow doesn’t appear in the Red Hat Developer Hub UI, delete the Red Hat Developer Hub Pod to force a refresh of the workflows. Failing that, check the logs and verify the Pods are all healthy. |
Run the Workflow
-
Click the play button on the workflow in Red Hat Developer Hub.
-
Select a language when prompted.
-
Click Next, verify the parameters then click Run.
-
A page showing workflow details will be shown. This includes the resulting Greeting Message determined by your chosen language.
This is a very simple workflow example, but it demonstrates how SonataFlow-based workflows are integrated with Red Hat Developer Hub using the Orchestrator feature.
If you’re wondering how the parameters screen was generated, you can see the dataInputSchema referenced here, and the JSONSchema file(s) in the same directory.
Additionally, this production-ready workflow is run in the gitops profile and is deploying by a pre-built container image per the SonataFlow best-practices referenced earlier.