Go Posts

A Simple RHPAM-Application Integration with Multi User Approval Workflow

On this article, im trying to create a simple Leave Approval System which is deployed as microservices. So basically there are two different application, one Golang app as Frontend, and RHPAM (Red Hat Process Automation Manager) as Backend, and both are communicating by using a simple REST API.

Basically there are two users involved here, one is adminUser as requester, and spv02 as approver. As approver, spv02 can either accept or reject the requested leave. Easiest way to described the approval workflow is perhaps described in below image,

Lets start by creating two user on RHPAM,

adminUser / password
spv02 / password

Import project from github (code is at the end of this article), build and deployed it to KIE.

Now lets start with creating an entry form,

The touch-point between frontend and pam on this ui is RHPAM’s “process instances” API, and im adding a correlation-key which is a unique business primary key.

curl -L -X POST 'http://localhost:8080/kie-server/services/rest/server/containers/approval_system_1.0.1-SNAPSHOT/processes/approval/instances/correlation/TL-3422' \
-H 'Authorization: Basic YWRtaW5Vc2VyOnBhc3N3b3Jk' \
-H 'Content-Type: application/json' \
--data-raw '{
    "application": {
        "com.myspace.approval_system.Request": {
            "days": 9,
            "purpose":"Sick Leave"

Next step is displaying all leave request that have been made by this corresponding user, we can capture this by using server queries API, given a specific username as initiator parameter,

curl -L -X GET 'http://localhost:8080/kie-server/services/rest/server/queries/processes/instances?initiator=adminUser&page=0&pageSize=10&sortOrder=true&status=1&status=2&status=3' \
-H 'Accept: application/json' \
-H 'Authorization: Basic YWRtaW5Vc2VyOnBhc3N3b3Jk'

Moving forward, now we are seeing from approval’s point of view, first we need to display what are the tasks which are assign to this user.

curl -L -X GET 'http://localhost:8080/kie-server/services/rest/server/queries/tasks/instances/owners?page=0&pageSize=10&sortOrder=true&sort=taskId' \
-H 'Accept: application/json' \
-H 'Authorization: Basic c3B2MDI6cGFzc3dvcmQ='

And the ability to Approve or Reject a specific request, there are two APIs which are involved here. That is one API for starting the task, and another one to complete it. Make sure you differentiate parameters on “approved” field, use “false” for Rejecting request, and “true” for Accepting request.

curl -L -X PUT 'http://localhost:8080/kie-server/services/rest/server/containers/approval_system_1.0.1-SNAPSHOT/tasks/6/states/started' \
-H 'Authorization: Basic c3B2MDI6cGFzc3dvcmQ='
curl -L -X PUT 'http://localhost:8080/kie-server/services/rest/server/containers/approval_system_1.0.1-SNAPSHOT/tasks/6/states/completed' \
-H 'Authorization: Basic c3B2MDI6cGFzc3dvcmQ=' \
-H 'Content-Type: application/json' \
--data-raw '{
    "approved": false

And here are my repositories on Github,

frontend : 

backend :

Have fun playing with RHPAM 🙂

Go and DataDog Part 1 : Simple Go HTTP Monitoring with DataDog

Today im trying to share a simple GoLang HTTP monitoring using DataDog APM. On this example im using trial version of DataDog for testing purpose, but on production im using enterprise version. Shouldnt be so much difference between those two.

Okay, after we register on DataDog website, we can start with installing DataDog agent on our server.


Im using Ubuntu Server, so my installation command is like below,

DD_API_KEY=<your datadog api key> bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/datadog-agent/master/cmd/agent/install_script.sh)"

After our installation runs well, we need to configure APM first

vi /etc/datadog-agent/datadog.yaml

with below configuration,

   enabled: true

we can start our Datadog-agent using below command,

sudo datadog-agent start

and check its status using

sudo datadog-agent status

Next is writing our code, im using Go’s simple htttp package

package main

import (
    httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http" // In order to instrument the http library

func main() {
     defer tracer.Stop()
     mux := httptrace.NewServeMux() // init the http tracer
     mux.HandleFunc("/", handle) // use the tracer to handle the urls     
     log.Println("Listening on port 8099")	 
     log.Fatal(http.ListenAndServe(":8099", mux)) // use the tracer to start the http server

func handle(w http.ResponseWriter, r *http.Request) {     
     fmt.Fprint(w, "Hello world!")

we can simulate http request to our server with a simple command,

curl -v

We can see the result on our Datadog dashboard below,

and the detailed view for each url,

Hopefully it helps 😀