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

  1. Visit the tssc-dh project in the OpenShift Web Console.

  2. Click the plus (+) icon in the top navigation, and choose Import YAML.

  3. 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
  4. A new SonataFlow resource will appear in the Topology View. Click it and wait for the Pod to enter the Running status.

    sonataflow pod running
  5. Click the arrow next to the Pod on the Topology view, then visit the /q/dev-ui endpoint 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 sysout in our sample workflow. The Serverless Logic Operator uses kogito-codegen to generate Java code from your workflow definition and JSON schemas.
    sonataflow q dev ui

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.

  1. Click the Workflows link inside the Serverless Workflows Tools box.

  2. Click the Workflow Definitions tab. Workflow definitions including the new greeting workflow will be listed.

    quarkus devui workflows
  3. Click the play button under the Actions column for the greeting.

    quarkus devui start workflow
  4. 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.
  5. Return to the Workflow Instances tab. Your workflow run will be listed.

    quarkus devui workflow run
  6. Click the greeting link. The workflow run details are listed, showing that that the English branch was executed.

    quarkus devui workflow outline
  7. Scroll down and you’ll see that "Hello from JSON Workflow" is in the workflowdata output.

Edit the Workflow

  1. Return to the OpenShift Web Console, and return to the tssc-dh project’s Topology view.

  2. Edit the greeting SonataFlow by clicking the three dots on the SF item in the Topology view.

    quarkus devui edit sf
  3. Switch to the YAML editor.

  4. Update the Spanish entry in ChooseOnLanguage conditions to check for "Irish" and change the transition to "GreetInIrish"

  5. Find the corresponding GreetInSpanish state and change it to GreetInIrish.

  6. Additionally, change the data.greeting to Háigh ó JSON workflow,

    quarkus devui edit workflow
  7. Scroll down and click Save.

  8. 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.

    quarkus devui restarts

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:

  1. Open the OpenShift Web Console, and return to the tssc-dh project’s Topology view.

  2. Delete the greeting SonataFlow by clicking the three dots on the SF item in the Topology view, then clicking Delete SonataFlow.

    sonataflow greeting delete

Next, use the OpenShift Web Terminal to deploy the production version of the greeting workflow:

  1. Click the Web Terminal (>_) icon in the top navigation of the OpenShift Web Console.

  2. 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
  3. The new greeting service will appear in the Topology view.

    sonataflow helm install
  4. 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.

    rhdh workflow list

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

  1. Click the play button on the workflow in Red Hat Developer Hub.

  2. Select a language when prompted.

    sonataflow rhdh params
  3. Click Next, verify the parameters then click Run.

  4. A page showing workflow details will be shown. This includes the resulting Greeting Message determined by your chosen language.

    sonataflow rhdh complete

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.