Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KOGITO-7257] Documenting workflow metainfo #531

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions serverlessworkflow/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ asciidoc:
kogito_sw_operator_examples_url: https://github.com/apache/incubator-kie-kogito-examples/tree/main/serverless-operator-examples
kogito_examples_url: https://github.com/apache/incubator-kie-kogito-examples.git
kogito_apps_url: https://github.com/apache/incubator-kie-kogito-apps/tree/main
kogito_runtimes_url: https://github.com/apache/incubator-kie-kogito-runtimes/tree/main
quarkus_cli_url: https://quarkus.io/guides/cli-tooling
spec_website_url: https://serverlessworkflow.io/
spec_doc_url: https://github.com/serverlessworkflow/specification/blob/0.8.x/specification.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,45 @@ You can find an example of event data filtering in the link:{kogito_sw_examples_
The previous example of the event filter copies the content of CloudEvent data `result` field into the workflow model `move` field.
--

== Workflow secrets, constants and context

As per specification, you can use link:{spec_doc_url}#workflow-constants[Workflow Constants] and link:{spec_doc_url}#workflow-secrets[Workflow Secrets] whenever an expression is accepted.
In {product_name} you can use `$SECRET` to access any configuration property, not just sensitive ones.
So, assuming you have added to your `application.properties` a line with the `myname=john` property, the following function will append the string `my name is john` to the `message` variable
----
{
"name": "secretMessage",
"type": "expression",
"operation": ".message |= \"my name is \"+$SECRET.my_name"
}
----

Besides constants and secrets, you might access contextual information of the running workflow by using the $WORKFLOW reserved word.
{product_name} supports the following contextual keys:
* `id`: The id of the running workflow definition
* `name`: The name of the running workflow definition
* `instanceId`: The id of the running workflow instance
* `headers`: Optional map containing the headers, if any, of the invocation that started the running workflow instance
* `prevActionResult`: In a `foreach` state, give access the result of the previous loop iteration output.
* `identity`: Quarkus security identity

Therefore, the following function, for a serverless workflow definition whose id is `expressionTest`, will append the string `worklow id is expressionTest` to the `message` variable

----
{
"name": "contextMessage",
"type": "expression",
"operation": ".message |= \"workflow id is \"+$WORKFLOW.id"
}
----

=== Customizing workflow context

In addition to the predefined keys mentioned previously, you can add your own keys to workflow context using Java Service Loader mechanism, by providing an implementation of class link:{kogito_runtimes_url}/kogito-serverless-workflow/kogito-serverless-workflow-utils/src/main/java/org/kie/kogito/serverless/workflow/utils/KogitoProcessContextResolverExtension.java[KogitoProcessContextResolverExtension]

This feature was used to add quarkus security identity support, you can check source code as reference link:{kogito_runtimes_url}/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow/src/main/java/org/kie/kogito/serverless/workflow/QuarkusKogitoProcessContextResolver.java[here].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domhanak based on your work to remove Quarkus citations throughout the doc sections, I think we should relocate this section Javi added. This is part of the "concepts" section, so we must not cite Quarkus here.

Copy link
Contributor Author

@fjtirado fjtirado Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardozanini Since the quarkus mention is just an example of how to add a new context variable, I think the usage is legit here. The reason I mention the quarkus related implementation of KogitoProcessContextResolverExtension is because is straightforward and therefore suitable as example, but if an issue, I can change by a link to the one I used for python support

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should mention Quarkus here. It's highly related to what we are trying to do. These concepts sections must be solely to working with workflows at the spec level and how our runtime handles it. We can move these paragraphs to a new section under Quarkus. This is a rich material that we must keep, it's just a matter of rearrangement. @domhanak wdyt?

Copy link
Contributor

@domhanak domhanak Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardozanini Agreed, I am noting this and can work on rearranging. Just let me know the order we do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess once we merge this, we can move in the PR you have opened #536


== Additional resources

* link:{jq_play} [JQ Play offline]
Expand Down
Loading