Startup project

This section shows how to create a simple Serverless Workflow using Serverless Logic Web Tools.

A basic workflow

  1. Open the Serverless Logic Web Tools in your browser.

  2. Select YAML button in the Create pane image::02_webtool.png[alt]

  3. Change the workflow name with order image::02_new_swf.png[alt]

  4. Click the text Create a Serverless Workflow and select Serverless Workflow Example: a simple template is generated.

The workflow editor is split in two panes: the text editor and the visual representation of the workflow.

At the moment there is no way to graphically edit the workflow, the user can edit the yaml file on the left side and see the diagram changes on the right. When the user clicks on a node of the graph, the cursor in the text editor is moved to the corresponding section of the yaml definition.

Change the template to match the following:

id: order
version: "1.0"
specVersion: "0.8"
name: Order Workflow
description: Order Workflow Sample
functions:
  - name: printMessage
    type: custom
    operation: sysout
start: Order Received
states:
  - name: Order Received
    type: operation
    actions:
      - name: printAction
        functionRef:
          refName: printMessage
          arguments:
            message: '"Order received: " + .orderId'
    end: true

Let’s analyze the content:

  • At the beginning there are some identification details: the unique id, version, name, description and the specVersion.

  • The start attribute point to the first state in the flow Order Received.

  • functions are a set of reusable definitions for service invocations or expression evaluation. In this example, printMessage is a custom function which print a message in the log.

  • states contains a set of states which are the building block of the workflow logic.

The workflow logic is pretty straightforward: when the workflow starts the Order Received state is executed then it ends. However, there are some other aspects:

  • The workflow is started with an input message that is copied in the internal workflow state.

  • The Order Received state invokes the printMessage function: it’s worth noticing that .orderId is a jq expression to read the workflow state. In other word, it expect to find orderId in the workflow state.

To learn more about Serverless Workflow notation and semantic don’t hesitate to read the official specification document which is really clear and accessible: https://github.com/serverlessworkflow/specification/blob/0.8.x/specification.md

Run the workflow

You can easily run your first workflow in your OpenShift environment:

  1. Locate the Try on OpenShift button at the top right of the page and select it.

  2. Select Setup…​

    try openshift
  3. In the OpenShift setting page select Add connection button

  4. Fill in the OpenShift connection details:

    1. Namespace (project): Use the namespace provided by the proctor (if you are running this tutorial on your own, create a new namespace and use it)

    2. To retrieve the values for Host and Token:

      1. Open the OpenShift console in a different browser window.

      2. In the top right corner select the username and the Copy login command entry.

        oc command
      3. After the login process, select Dysplay token link to get a command line that resemble the following:

        oc login --token=sha256~VPMhRtYqHghxlRLWD5X92lg3ZIxr0V7dYYcP5DWxJq4 --server=https://api.ocp4.dmshift.eu:6443
      4. Copy the string after --token into the Token field in the other browser window.

      5. Likewise, copy the string after --server into the Host field in the other browser window.

      6. Select Enable Dev Mode option.

        02 dev mode
      7. Finally, select the Connect button, you should see the following confirmation message:

        connection ok

Now that the OpenShift connection is up, you need to reopen the workflow:

  1. Go back on the main page clicking on the top banner:

    home
  2. From the left navigation menu select Recent Models.

  3. Select order to open again the workflow designer.

  4. Select again Try on OpenShift button and then Upload "order" to Dev Mode.

    upload
  5. Wait for the confirmation message and select Go to Serverless Workflow Dev UI ↗ to open the Dev UI in a new browser tab.

    Dev UI

From Dev UI you can trigger a new workflow instance and inspect its execution:

  1. Select Workflow Definitions

  2. Click on the arrow button in corresponding to the order row.

    Workflow definitions
  3. Fill in the Start Workflow Data edit box with the following JSON payload:

    {"orderId":"order-123"}
  4. Select the Start button below.

You should get a confirmation message stating that your workflow instance was triggered.

CONGRATULATION!!! Your first Serverless Workflow was executed as expected!

Inspect the workflow execution

To inspect the workflow execution just triggered select Go to workflow list at the bottom of the confirmation message.

Workflow definitions

In the Workflow Instances page, select the first instance in the list:

Workflow list

In this Workflow Details page, you can inspect all the details of the workflow execution from the following boxes:

  • Diagram: the serverless workflow diagram is shown, with completed nodes colored green.

  • Timeline: the main workflow tasks, listed in order of execution.

  • Details: the workflow instance metadata.

  • Variables: the internal state of the workflow instance.

Finally, have a look at the Monitoring page charts on your own!