Sunday, June 25, 2023

Oracle Golden Gate 21.3 Microservice Architecture - Rest API interaction using cURL - Retrieve the deployment list

 In this blog, we will retrieve the deployment list using REST API (cURL) from our service manager:

What you need:

cURL (mostly installed in linux)

jq or mjson.tool from python

Assumption:

You already have installed OGG, made your first OGG deployment. If not refer to the below urls

OGG 21.3 MA - silent mode - installation

OGG 21.3 MA - silent mode - deployment

Let us retrieve the deployment list using cURL now:

Oracle ref: oracle reference note

Command: 

curl -u ggsca:ggsca \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X GET http://127.0.0.1:9100/services/v2/deployments

Command explaination:
-u <username>:<password> - is the service manager's admin username and password

Keep ASIS or dont change: <since this is the supported format for this request type>
-H "Content-Type: application/json" \
-H "Accept: application/json" \

-X mentions the type of request (CURD) : GET (retrieving info)

url : http://127.0.0.1:9100/services/<version>/deployments [allowed value: v2]


Actual output:

[oracle@vcentos79-oracle-sa1 ~]$curl -u ggsca:ggsca -H "Content-Type: application/json" -H "Accept: application/json" -X GET http://127.0.0.1:9100/services/v2/deployments
{"$schema":"api:standardResponse","links":[{"rel":"canonical","href":"http://127.0.0.1:9100/services/v2/deployments","mediaType":"application/json"},{"rel":"self","href":"http://127.0.0.1:9100/services/v2/deployments","mediaType":"application/json"},{"rel":"describedby","href":"http://127.0.0.1:9100/services/v2/metadata-catalog/versionDeployments","mediaType":"application/schema+json"}],"messages":[],"response":{"$schema":"ogg:collection","items":[{"links":[{"rel":"parent","href":"http://127.0.0.1:9100/services/v2/deployments","mediaType":"application/json"},{"rel":"canonical","href":"http://127.0.0.1:9100/services/v2/deployments/ServiceManager","mediaType":"application/json"}],"$schema":"ogg:collectionItem","name":"ServiceManager"},{"links":[{"rel":"parent","href":"http://127.0.0.1:9100/services/v2/deployments","mediaType":"application/json"},{"rel":"canonical","href":"http://127.0.0.1:9100/services/v2/deployments/oggdep01","mediaType":"application/json"}],"$schema":"ogg:collectionItem","name":"oggdep01"}]}}

To make it more readable:

A) using python -mjson.tool:

curl -u ggsca:ggsca \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X GET http://127.0.0.1:9100/services/v2/deployments | python -mjson.tool

Actual output:

[oracle@vcentos79-oracle-sa1 ~]$ curl -u ggsca:ggsca \
> -H "Content-Type: application/json" \
> -H "Accept: application/json" \
> -X GET http://127.0.0.1:9100/services/v2/deployments | python -mjson.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1024  100  1024    0     0  10125      0 --:--:-- --:--:-- --:--:-- 10138
{
    "$schema": "api:standardResponse",
    "links": [
        {
            "href": "http://127.0.0.1:9100/services/v2/deployments",
            "mediaType": "application/json",
            "rel": "canonical"
        },
        {
            "href": "http://127.0.0.1:9100/services/v2/deployments",
            "mediaType": "application/json",
            "rel": "self"
        },
        {
            "href": "http://127.0.0.1:9100/services/v2/metadata-catalog/versionDeployments",
            "mediaType": "application/schema+json",
            "rel": "describedby"
        }
    ],
    "messages": [],
    "response": {
        "$schema": "ogg:collection",
        "items": [
            {
                "$schema": "ogg:collectionItem",
                "links": [
                    {
                        "href": "http://127.0.0.1:9100/services/v2/deployments",
                        "mediaType": "application/json",
                        "rel": "parent"
                    },
                    {
                        "href": "http://127.0.0.1:9100/services/v2/deployments/ServiceManager",
                        "mediaType": "application/json",
                        "rel": "canonical"
                    }
                ],
                "name": "ServiceManager"
            },
            {
                "$schema": "ogg:collectionItem",
                "links": [
                    {
                        "href": "http://127.0.0.1:9100/services/v2/deployments",
                        "mediaType": "application/json",
                        "rel": "parent"
                    },
                    {
                        "href": "http://127.0.0.1:9100/services/v2/deployments/oggdep01",
                        "mediaType": "application/json",
                        "rel": "canonical"
                    }
                ],
                "name": "oggdep01"
            }
        ]
    }
}
[oracle@vcentos79-oracle-sa1 ~]$

B) Other option (jq):

curl -u ggsca:ggsca \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X GET http://127.0.0.1:9100/services/v2/deployments | jq

[oracle@vcentos79-oracle-sa1 ~]$ curl -u ggsca:ggsca \
> -H "Content-Type: application/json" \
> -H "Accept: application/json" \
> -X GET http://127.0.0.1:9100/services/v2/deployments | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1024  100  1024    0     0  13097      0 --:--:-- --:--:-- --:--:-- 13298
{
  "$schema": "api:standardResponse",
  "links": [
    {
      "rel": "canonical",
      "href": "http://127.0.0.1:9100/services/v2/deployments",
      "mediaType": "application/json"
    },
    {
      "rel": "self",
      "href": "http://127.0.0.1:9100/services/v2/deployments",
      "mediaType": "application/json"
    },
    {
      "rel": "describedby",
      "href": "http://127.0.0.1:9100/services/v2/metadata-catalog/versionDeployments",
      "mediaType": "application/schema+json"
    }
  ],
  "messages": [],
  "response": {
    "$schema": "ogg:collection",
    "items": [
      {
        "links": [
          {
            "rel": "parent",
            "href": "http://127.0.0.1:9100/services/v2/deployments",
            "mediaType": "application/json"
          },
          {
            "rel": "canonical",
            "href": "http://127.0.0.1:9100/services/v2/deployments/ServiceManager",
            "mediaType": "application/json"
          }
        ],
        "$schema": "ogg:collectionItem",
        "name": "ServiceManager"
      },
      {
        "links": [
          {
            "rel": "parent",
            "href": "http://127.0.0.1:9100/services/v2/deployments",
            "mediaType": "application/json"
          },
          {
            "rel": "canonical",
            "href": "http://127.0.0.1:9100/services/v2/deployments/oggdep01",
            "mediaType": "application/json"
          }
        ],
        "$schema": "ogg:collectionItem",
        "name": "oggdep01"
      }
    ]
  }
}
[oracle@vcentos79-oracle-sa1 ~]$

Notice we have 2 deployments:
http://127.0.0.1:9100/services/v2/deployments/ServiceManager
http://127.0.0.1:9100/services/v2/deployments/oggdep01

We are interested in oggdep01

Thank you!



No comments:

Post a Comment

Flashback data archive steps

 Objective: Ways to track DML changes in a table Detailed objective: We should be able to track the changes in the table at any point in tim...