How can we build our REST API calls from Goldengate adminclient?

More often than not, I get a question about REST API documentation for GoldenGate and how we can use it to build automation, monitoring, and rest calls.

Well, the first part it’s not difficult, we can always get all the REST API latest information from the documentation available at: https://docs.oracle.com/en/middleware/goldengate/core/21.3/oggra/

We can also use “set debug on” within the adminclient tool to extract the REST APIs call at run time. What does that mean? Let’s look at the example below:

First I execute a simple “info all” command and I get the normal 6 column results with the status and lag information, just like we had with ggsci in the classic architecture. Then I execute “set debug on” and I repeated the “info all”. As we will be able to see, the adminclient will return all the calls made to GoldenGate in the REST APIs get format.

Pay attention to the “response” area of the GET commands:

OGG (http://localhost:9012 West) 2> info all
Program     Status      Group       Type             Lag at Chkpt  Time Since Chkpt

EXTRACT     RUNNING     EDEMO       INTEGRATED       00:00:00      00:00:08

OGG (http://localhost:9012 West) 3> set debug on
Command 3 succeeded: 'set debug on'

OGG (http://localhost:9012 West) 4> info all
--------------------------------------------------------------------------------
> GET /services/v2/extracts?threads=none
< Status 200
{
    "$schema": "api:standardResponse",
    "links": [
        {
            "rel": "canonical",
            "href": "http://localhost:9012/services/v2/extracts",
            "mediaType": "application/json"
        },
        {
            "rel": "self",
            "href": "http://localhost:9012/services/v2/extracts",
            "mediaType": "application/json"
        },
        {
            "rel": "describedby",
            "href": "http://localhost:9012/services/v2/metadata-catalog/extracts",
            "mediaType": "application/schema+json"
        }
    ],
    "messages": [],
    "response": {
        "$schema": "ogg:collection",
        "items": [
            {
                "links": [
                    {
                        "rel": "parent",
                        "href": "http://localhost:9012/services/v2/extracts",
                        "mediaType": "application/json"
                    },
                    {
                        "rel": "canonical",
                        "href": "http://localhost:9012/services/v2/extracts/EDEMO",
                        "mediaType": "application/json"
                    }
                ],
                "$schema": "ogg:collectionItem",
                "name": "EDEMO"
            }
        ]
    }
}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
> GET /services/v2/extracts/EDEMO
< Status 200
{
    "$schema": "api:standardResponse",
    "links": [
        {
            "rel": "canonical",
            "href": "http://localhost:9012/services/v2/extracts/EDEMO",
            "mediaType": "application/json"
        },
        {
            "rel": "self",
            "href": "http://localhost:9012/services/v2/extracts/EDEMO",
            "mediaType": "application/json"
        },
        {
            "rel": "describedby",
            "href": "http://localhost:9012/services/v2/metadata-catalog/extract",
            "mediaType": "application/schema+json"
        }
    ],
    "messages": [],
    "response": {
        "$schema": "ogg:extract",
        "credentials": {
            "alias": "cdb_west",
            "domain": "OracleGoldenGate"
        },
        "begin": "now",
        "intent": "Unidirectional",
        "encryptionProfile": "LocalWallet",
        "managedProcessSettings": "Default",
        "targets": [
            {
                "name": "e1",
                "sizeMB": 50,
                "sequenceLength": 9,
                "sequenceLengthFlip": false,
                "sequence": 0,
                "offset": 1267,
                "remote": false
            }
        ],
        "config": [
            "EXTRACT EDEMO",
            "USERIDALIAS cdb_west DOMAIN OracleGoldenGate",
            "EXTTRAIL e1",
            "--",
            "table west.hr.*;"
        ],
        "source": "tranlogs",
        "type": "Integrated",
        "registration": {
            "share": false,
            "containers": [
                "WEST"
            ],
            "csn": 4867551
        },
        "status": "running"
    }
}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
> GET /services/v2/extracts/EDEMO/info/status
< Status 200
{
    "$schema": "api:standardResponse",
    "links": [
        {
            "rel": "canonical",
            "href": "http://localhost:9012/services/v2/extracts/EDEMO/info/status",
            "mediaType": "application/json"
        },
        {
            "rel": "self",
            "href": "http://localhost:9012/services/v2/extracts/EDEMO/info/status",
            "mediaType": "application/json"
        },
        {
            "rel": "describedby",
            "href": "http://localhost:9012/services/v2/metadata-catalog/extractStatus",
            "mediaType": "application/schema+json"
        }
    ],
    "messages": [],
    "response": {
        "$schema": "ogg:extractStatus",
        "status": "running",
        "processId": 13560,
        "lastStarted": "2022-04-11T17:41:49.467Z",
        "lag": 0,
        "sinceLagReported": 5,
        "position": "0.5099541"
    }
}
--------------------------------------------------------------------------------
Program     Status      Group       Type             Lag at Chkpt  Time Since Chkpt

EXTRACT     RUNNING     EDEMO       INTEGRATED       00:00:00      00:00:05
--------------------------------------------------------------------------------
> GET /services/v2/replicats?threads=none
< Status 200
{
    "$schema": "api:standardResponse",
    "links": [
        {
            "rel": "canonical",
            "href": "http://localhost:9012/services/v2/replicats",
            "mediaType": "application/json"
        },
        {
            "rel": "self",
            "href": "http://localhost:9012/services/v2/replicats",
            "mediaType": "application/json"
        },
        {
            "rel": "describedby",
            "href": "http://localhost:9012/services/v2/metadata-catalog/replicats",
            "mediaType": "application/schema+json"
        }
    ],
    "messages": [],
    "response": {
        "$schema": "ogg:collection",
        "items": []
    }
}
--------------------------------------------------------------------------------
Command 4 succeeded: 'info all'

OGG (http://localhost:9012 West) 5>

With this information we can now create our REST API call:

1- The first one is to check general information about the extract with: GET /services/v2/extracts/EDEMO

curl  -k -u oggadmin:"WwelcomE##123" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X GET http://localhost:9012/services/v2/extracts/EDEMO | jq '.response'

Here is the output when executed in the host itself:

If you look at it, there is a lot of information about the extract in this output, from trail file to parameter file and even SCN info. It’s similar to an “info edemo details”, but with steroids. 🙂

2- The next one would check the lag/status with GET /services/v2/extracts/EDEMO/info/status:

curl  -k -u oggadmin:"WwelcomE##123" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X GET http://localhost:9012/services/v2/extracts/EDEMO/info/status  | jq '.response'

And the output would be:

Here the output shows us the status, lag, and position. This is great information to build a monitor based on lag.

This was just an example with “info all”, but you can do the same thing with all adminclient commands and we can enhance that in different ways. Give it a try and let me know what you think. Use your creativity and show me some cool stuff we can do with this.

I hope this helps.

Alex.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.