Creating and running workflow projects using KN CLI and Visual Studio Code

This guide showcases using the Knative Workflow CLI plugin and Visual Studio code to create & run SonataFlow projects.

Prerequisites
  • You have set up your environment according to the minimal environment setup guide.

  • Install k9scli.io for easier inspection of your application resources in the cluster. This is optional, you can use any tool you are familiar with in this regard.

Creating a workflow project with Visual Studio Code and KN CLI

Use the create command with kn workflow to scaffold a new SonataFlow project.

  • Navigate to your development directory and create your project.

kn workflow create -n my-sonataflow-project
  • This will create a folder with name my-sonataflow-project and a sample workflow workflow.sw.json

cd ./my-sonataflow-project
  • Open the folder in Visual Studio Code and examine the created workflow.sw.json using our extension.

Now you can run the project and execute the workflow.

Running a Workflow project with Visual Studio Code and KN CLI

Use the run command with kn workflow to build and run the SonataFlow project in local development mode.

  • Run the project.

kn workflow run
  • The Development UI will be accessible at localhost:8080/q/dev

  • You can now work on your project. Any changes will be picked up by the hot reload feature.

  • See Workflow instances guide on how to run workflows via Development UI.

  • Once you are done developing your project navigate to the terminal that is running the kn workflow run command and hit Ctlr+C to stop the development environment.

To deploy the finished project to a local cluster, proceed to the next section.

Deploying a workflow project with Visual Studio Code and KN CLI

Use the deploy command with kn workflow to deploy the SonataFlow project into your local cluster.

  • Create a namespace for your application

kubectl create namespace my-sf-application
  • Deploy to cluster

kn workflow deploy --namespace my-sf-application
  • Using k9s cli you can examine your deployment.

  • In a separate bash instance create a port mapping:

    • Minikube

    • Kind

    minikube service hello --namespace my-sf-application --url
    • Use this URL to access your workflow instances using the Developer UI

      • <RETURNED_URL>/q/dev-ui/org.apache.kie.sonataflow.sonataflow-quarkus-devui/workflows

    # Execute
    kubectl get services -n my-sf-application
    
    # You should see output like this, note the ports
    NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)            AGE
    hello        ClusterIP   10.96.0.1    <none>        <RANDOM_PORT>/80   39s
    
    # Execute
    kubectl port-forward service/hello <RANDOM_PORT>:80 -n my-sf-application
  • To update the image, run the deploy again, note that this may take some time.

  • To stop the deployment, use the undeploy command:

kn workflow undeploy --namespace my-sf-application
  • You can validate your pod is terminating using k9s cli.

Testing your workflow application

To test your workflow application you can use any capable REST client out there. All that is needed is the URL of your deployed workflow project.

Prerequisites
Testing your workflow application
  • To test your workflow project, access the Swagger UI on <URL>/q/swagger-ui to examine available endpoints.

  • In order to execute the workflow once, run:

curl -X 'POST' \
  '<URL>/hello' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "workflowdata": {}
}'
  • To examine executed instance you can use the GraphQL UI by navigating to <URL>/q/graphl-ui.

Found an issue?

If you find an issue or any misleading information, please feel free to report it here. We really appreciate it!