Skip to content

pfcon command: hello

Max Murakami edited this page Oct 15, 2020 · 21 revisions

pfcon command: hello

Abstract

This page describes the hello command to pfcon. It is used to simply test if a pfcon service is running and responding to requests and talking to the remote backend services pman and pfioh.

Preconditions

  • A HOST_IP environment variable that denotes the IP of the host housing the service. In Linux, you can do:
export HOST_IP=$(ip route | grep -v docker | awk '{if(NF==11) print $9}' | head -n 1)
  • Make sure that pfcon has been started (see here for more info)
pfcon --forever --httpResponse
  • Make sure that the remote pman and pfioh services have been started.
  • Make sure that the internal pfcon dictionary variable Gd_internalvar has a valid entry for the pman and pfioh services (beyond the scope of this current page).

msg summary

The msg payload of the REST interaction with pfcon is:

 {  "action": "hello",
         "meta": {
                 "askAbout":     "sysinfo",
                 "echoBack":     "Hi there!",
                 "service":      "name/ip of machine hosting pman/pfioh"
         }
 } 

Pay particular attention to the service setting. More on this below.

hello

http calling syntax

Saying hello to pfcon using http:

http POST http://${HOST_IP}:5005/api/v1/cmd \
Content-Type:application/x-www-form-urlencoded \
Accept:application/vnd.collection+json \
payload:='{  "action": "hello",
    "meta": {
                "askAbout":     "sysinfo",
                "echoBack":      "Hi there!",
                "service":       "host"
            }
}'

Python example

from requests import posturl = 'http://pfcon:5005/api/v1/cmd' # adapt this
request_body = {
    'payload': {
        'action': 'hello',
        'meta': {
            'askAbout': 'sysinfo', 'echoBack': 'Hi there!', 'service': 'host'
        }
    }
}
headers = {'content-type': 'application/x-www-form-urlencoded'}
​
response = post(url, json=request_body, headers=headers)

print(f'Received response with content: {response.content}')

pfurl calling syntax

Assuming satisfied preconditions, let's say hello to pfcon. It will in turn ask each of pfioh and pman hello and return the response.

pfurl --verb POST --raw --http ${HOST_IP}:5005/api/v1/cmd   \
        --httpResponseBodyParse --jsonwrapper 'payload' --msg \
'{  "action": "hello",
    "meta": {
                "askAbout":     "sysinfo",
                "echoBack":      "Hi there!",
                "service":       "host"
            }
}'

Note the service setting in the pfurl JSON payload. This designates the internal pfcon configuration that describes the location/machine hosting the remote pman and pfioh services.

Hello Massachusetts Open Cloud (MOC):

First, set the pfcon proxy if this is being attempted from within a proxied environment:

pfurl --verb POST --raw \
      --http ${HOST_IP}:5005/api/v1/cmd \
      --httpResponseBodyParse \
      --jsonwrapper 'payload' \
      --msg \
'{  "action": "internalctl",
    "meta": {
                "var":     "/self",
                "set": {
                         "httpProxy": {
                             "httpSpec": "http://proxy.tch.harvard.edu:3128",
                             "use": true
                       }
                }
            }
}'

Set the authentication

pfurl --verb POST --raw \
      --http ${HOST_IP}:5005/api/v1/cmd \
      --httpResponseBodyParse \
      --jsonwrapper 'payload' \
      --msg \
'{  "action": "internalctl",
    "meta": {
                "var":     "/service/moc",
                "set":     {
                    "compute": {
                        "addr": "pman-radiology.k-apps.osh.massopen.cloud",
                        "baseURLpath": "api/v1/cmd/",
                        "status": "undefined",
                        "authToken": "{Bu7H)FyWp{,e<"
                    },
                    "data": {
                        "addr": "pfioh-radiology.k-apps.osh.massopen.cloud",
                        "baseURLpath": "api/v1/cmd/",
                        "status": "undefined",
                        "authToken": "{Bu7H)FyWp{,e<"
                    }
                }
            }
}'

Now call the service

pfurl --verb POST \
      --raw \
      --http ${HOST_IP}:5005/api/v1/cmd \
      --httpResponseBodyParse \
      --jsonwrapper 'payload' \
      --msg \
 '{  "action": "hello",
         "meta": {
                 "askAbout":     "sysinfo",
                 "echoBack":     "Hi there!",
                 "service":      "moc"
         }
 }' --quiet --jsonpprintindent 4 

return payload

A valid sample response body:

200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 7672

{
    "d_ret": {
        "sysinfo": {
            "platform": "Linux-4.10.0-26-generic-x86_64-with-Ubuntu-17.04-zesty",
            "hostname": "pangea",
            "cpu_percent": 7.6,
            "loadavg": [
                3.95,
                3.54,
                3.53
            ],
            "memory": [
                67429609472,
                56682147840,
                15.9,
                9461198848,
                52895141888,
                10287566848,
                2281156608,
                972627968,
                4100640768,
                537202688
            ],
            "system": "Linux",
            "cpucount": 24,
            "machine": "x86_64",
            "uname": [
                "Linux",
                "pangea",
                "4.10.0-26-generic",
                "#30-Ubuntu SMP Tue Jun 27 09:30:12 UTC 2017",
                "x86_64",
                "x86_64"
            ],
            "version": "#30-Ubuntu SMP Tue Jun 27 09:30:12 UTC 2017"
        }
    },
    "status": true,
    "d_remote": {
        "d_ret": {
            "megalodon-compute": {
                "d_ret": {
                    "megalodon-compute": {
                        "client_json_payload": "{\"payload\": {\"meta\": {\"echoBack\": \"Hi there!\", \"service\": \"megalodon\", \"askAbout\": \"sysinfo\"}, \"action\": \"hello\"}}",
                        "d_ret": {
                            "sysinfo": {
                                "hostname": "megalodon",
                                "machine": "x86_64",
                                "loadavg": [
                                    0.23,
                                    0.33,
                                    0.33
                                ],
                                "system": "Linux",
                                "cpu_percent": 4.7,
                                "memory": [
                                    67508088832,
                                    61551775744,
                                    8.8,
                                    5079625728,
                                    55537459200,
                                    6923558912,
                                    3967168512,
                                    1066659840,
                                    5824344064,
                                    125284352
                                ],
                                "cpucount": 8,
                                "version": "#28-Ubuntu SMP Wed Jun 14 08:14:34 UTC 2017",
                                "uname": [
                                    "Linux",
                                    "megalodon",
                                    "4.10.0-24-generic",
                                    "#28-Ubuntu SMP Wed Jun 14 08:14:34 UTC 2017",
                                    "x86_64",
                                    "x86_64"
                                ],
                                "platform": "Linux-4.10.0-24-generic-x86_64-with-Ubuntu-17.04-zesty"
                            },
                            "name": "pman",
                            "version": "1.2.0"
                        },
                        "meta": {
                            "service": "megalodon",
                            "echoBack": "Hi there!",
                            "askAbout": "sysinfo"
                        },
                        "status": true,
                        "client_json_len": 114,
                        "RESTheader": "POST //api/v1/cmd/ HTTP/1.1\r",
                        "path": "//api/v1/cmd",
                        "payloadsize": 114,
                        "receivedByServer": [
                            "POST //api/v1/cmd/ HTTP/1.1\r",
                            "Host: 10.23.131.183:5010\r",
                            "User-Agent: PycURL/7.43.0 libcurl/7.52.1 OpenSSL/1.0.2g zlib/1.2.11 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) librtmp/2.3\r",
                            "Accept: */*\r",
                            "Content-Length: 114\r",
                            "Content-Type: application/x-www-form-urlencoded\r",
                            "Via: 1.1 bdcnetsg1\r",
                            "Connection: Keep-Alive\r",
                            "X-BlueCoat-Via: c76e5a8a3a50519c\r",
                            "\r",
                            "{\"payload\": {\"meta\": {\"echoBack\": \"Hi there!\", \"service\": \"megalodon\", \"askAbout\": \"sysinfo\"}, \"action\": \"hello\"}}"
                        ],
                        "action": "hello",
                        "RESTverb": "POST"
                    }
                },
                "serviceName": "megalodon"
            },
            "megalodon-data": {
                "d_ret": {
                    "megalodon-data": {
                        "d_ret": {
                            "sysinfo": {
                                "hostname": "megalodon",
                                "machine": "x86_64",
                                "loadavg": [
                                    0.23,
                                    0.33,
                                    0.33
                                ],
                                "system": "Linux",
                                "cpu_percent": 4.7,
                                "memory": [
                                    67508088832,
                                    61551775744,
                                    8.8,
                                    5079625728,
                                    55537459200,
                                    6923558912,
                                    3967168512,
                                    1066659840,
                                    5824344064,
                                    125284352
                                ],
                                "cpucount": 8,
                                "version": "#28-Ubuntu SMP Wed Jun 14 08:14:34 UTC 2017",
                                "uname": [
                                    "Linux",
                                    "megalodon",
                                    "4.10.0-24-generic",
                                    "#28-Ubuntu SMP Wed Jun 14 08:14:34 UTC 2017",
                                    "x86_64",
                                    "x86_64"
                                ],
                                "platform": "Linux-4.10.0-24-generic-x86_64-with-Ubuntu-17.04-zesty"
                            },
                            "name": "pfioh",
                            "version": "1.2.9"
                        },
                        "status": true
                    }
                },
                "serviceName": "megalodon",
                "status": true
            }
        },
        "status": true,
        "serviceNameData": "megalodon",
        "serviceNameCompute": "megalodon"
    }
}

--30--