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 OpenShift Serverless Logic projects.

Prerequisites
  • You have setup your environment according minimal environment setup guide.

  • Install k9scli.io for easier inspection of your application resources in cluster. This is optional, you can use any tool you are fimiliar 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 you 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 Studo 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 OpenShift Serverless Logic project in local development mode.

  • Run the project.

kn workflow run
  • The Development UI wil be accesible 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 OpenShift Serverless Logic project into your local cluster.

  • 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/org.kie.kogito.kogito-quarkus-serverless-workflow-devui//workflowInstances

    # 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 worklow 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 needeed is the URL of your deployed worklow 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!

Configuring your Maven project to Red Hat build of Quarkus and OpenShift Serverless Logic

To use the Red Hat Build of Quarkus (RHBQ) libraries, you need to configure your local Maven installation.

Procedure
  1. To configure the Apache Maven settings.xml file and Quarkus extension registry client, follow the instructions in the Configuring the Maven settings.xml file for the online repository and Configuring Quarkus extension registry client.

  2. Complement the configured Apache Maven settings.xml file with the following profile to have access to the OpenShift Serverless Logic repository:

    Profile to access the OpenShift Serverless Logic repository
    <!-- Configure the OpenShift Serverless Logic Maven repository -->
    <profile>
      <id>red-hat-earlyaccess-maven-repository</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>red-hat-earlyaccess-maven-repository</id>
          <url>https://maven.repository.redhat.com/earlyaccess/all/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>red-hat-earlyaccess-maven-repository</id>
          <url>https://maven.repository.redhat.com/earlyaccess/all/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  3. Follow the instructions in the Red Hat Container Registry Authentication article to log in to the registry and use the OpenShift Serverless Logic images locally.