Skip to content

Instantly share code, notes, and snippets.

@rafaeltuelho
Last active November 22, 2021 18:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaeltuelho/1443caa82a990c5c5a1a430a2f84e3f7 to your computer and use it in GitHub Desktop.
Save rafaeltuelho/1443caa82a990c5c5a1a430a2f84e3f7 to your computer and use it in GitHub Desktop.
Update a SLA of a instantiated process in jBPM

Get Process Instance SLAs (Timers)

Returns all timers for a specified process instance.
GET /server/admin/containers/{containerId}/processes/instances/{processInstanceId}/timers

curl -X GET "http://localhost:8080/kie-server/services/rest/server/admin/containers/sla-test_1.0.0-SNAPSHOT/processes/instances/165/timers" -H "accept: application/json"

Response

{
  "timer-instance": [
    {
      "name": "[SLA]Application Review",
      "id": 2,
      "timer-id": 0,
      "activation-time": {
        "java.util.Date": 1616769367892
      },
      "last-fire-time": null,
      "next-fire-time": {
        "java.util.Date": 1617633367892
      },
      "delay": 864000000,
      "period": 0,
      "repeat-limit": -1,
      "process-instance-id": 165,
      "session-id": 228
    }
  ]
}

note that delay is represented in milliseconds.

In the above payload 864000000 = (next-fire-time - activation-time) = 10 days in milliseconds

Update a SLA after a process/case is already instantiated:

Updates a specified timer for a specified process instance
PUT /server/admin/containers/{containerId}/processes/instances/{processInstanceId}/timers/{timerId}

curl -X PUT "http://localhost:8080/kie-server/services/rest/server/admin/containers/sla-test_1.0.0-SNAPSHOT/processes/instances/165/timers/2?relative=true" \
-H "accept: application/json" \
-H "content-type: application/json" \
-d "{ \"period\" : 0, \"delay\" : 432000, \"repeatLimit\" : -1}"

delay is represented in seconds. 432000 = 5 days

Red Hat reference: https://access.redhat.com/solutions/1275113

Retrigger a specifc node inside the Case Instance

  • define a process or caseFile_ variable to hold the SLA Due Date as a parameter.
  • Update the process/case var
  • retrigger the node instance
Re-triggers a specified node instance for a specified process instance. If the node is not active in the process instance, it becomes active upon re-triggering.

PUT /server/admin/containers/{containerId}/processes/instances/{processInstanceId}/nodeinstances/{nodeInstanceId}

curl -X PUT "http://localhost:8080/kie-server/services/rest/server/admin/containers/sla-test_1.0.0-SNAPSHOT/processes/instances/9/nodeinstances/5" -H "accept: application/json"
@rafaeltuelho
Copy link
Author

notes from: https://issues.redhat.com/browse/BAPL-1247

SLA is tracked at node instance level and can already be retrieved using node instance query endpoints. Possible improvement could be to add this information on the Milestone data object returned from REST/JMS api.

When it comes to updating I am actually reluctant to allow to change the SLA itself as that could break the feature itself as users could actually constantly update the SLA currently there is no authorisation on node instance level and thus anyone would be able to do it.
Instead I'd recommend to use process admin API that allows to either retrigger or trigger new milestone node which would the reset/update SLA information that could be also based on variable values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment