-
Notifications
You must be signed in to change notification settings - Fork 33
pman command: search
This page describes the search
command to pman
. It is used to query a pman
service about processes that have been managed.
- This page assumes that
pman
is listening on:172.17.0.2:5010
. - Make sure that
pman
has been started (see here for more info):
pman --rawmode 1 --http --port 5010 --listeners 12
- This page assumes that a previous run has been managed with parameters
{ "action": "run",
"meta": {
"cmd": "cal 7 1970",
"auid": "rudolphpienaar",
"jid": "cal-job-1234",
"threaded": true
}
}
The msg
payload of the REST interaction with pman
is:
{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234",
"job": "0",
"when": "end",
"field": "stdout"
}
}
Assuming satisfied preconditions, let's search for information about a process. For example, let's ask for the stdout
of the app with jid
of cal-job-1234
:
purl --verb POST --raw --http 172.17.0.2:5010/api/v1/cmd --jsonwrapper 'payload' --msg \
'{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234",
"job": "0",
"when": "end",
"field": "stdout"
}
}' --quiet --jsonpprintindent 4
To use the dockerized version of purl
, and assuming a pman
on the given IP:
If you have cloned the source repo, you can cd
to the root directory and execute the docker helper scripts in the docker-bin
directory.
docker-bin/purl --verb POST --raw --http 172.17.0.2:5010/api/v1/cmd --jsonwrapper 'payload' --msg \
'{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234",
"job": "0",
"when": "end",
"field": "stdout"
}
}' --quiet --jsonpprintindent 4
The helper script just creates a docker run
command line string. You can run this string directly without using the helper script and directly calling the docker
app:
docker run --name pman -v /home:/Users --rm -ti fnndsc/pman purl --verb POST --raw --http 172.17.0.2:5010/api/v1/cmd --jsonwrapper 'payload' --msg \
'{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234",
"job": "0",
"when": "end",
"field": "stdout"
}
}' --quiet --jsonpprintindent 4
The pattern of meta
fields and values define the parameters of the search to perform. Here, we are searching the space of managed processes such that the jid
is cal-job-1234
and we are asking for the stdout
field of the process.
The job
and when
fields are related to how the underlying crunner
app actually runs a process. Jobs have two epochs, a start
and end
, and also a count. The first job is always job 0
and is only meaningful a compound statement, such as cmd0 ; cmd1; cmd2; cmd3; ... ; cmdN
.
The above returns a JSON string
{
"RESTverb": "POST",
"d_ret": {
"0": {
"20170303164938.122651_6e09943c-6fc0-45c8-b088-2394e5886b69": {
"end": {
"0": {
"endInfo": {
"0": {
"stdout": " July 1970 \nSu Mo Tu We Th Fr Sa \n 1 2 3 4 \n 5 6 7 8 9 10 11 \n12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 \n26 27 28 29 30 31 \n \n"
}
}
}
}
}
}
},
"payloadsize": 128,
"RESTheader": "POST /api/v1/cmd HTTP/1.1\r",
"meta": {
"when": "end",
"value": "cal-job-1234",
"key": "jid",
"job": "0",
"field": "stdout"
},
"receivedByServer": [
"POST /api/v1/cmd HTTP/1.1\r",
"Host: 172.17.0.2:5010\r",
"User-Agent: PycURL/7.43.0 libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3\r",
"Accept: */*\r",
"Content-type: application/vnd.collection+json\r",
"Content-Length: 128\r",
"\r",
"{\"payload\": {\"action\": \"search\", \"meta\": {\"key\": \"jid\", \"value\": \"cal-job-1234\", \"when\": \"end\", \"job\": \"0\", \"field\": \"stdout\"}}}"
],
"action": "search",
"status": true,
"path": "/api/v1/cmd"
}
Here, the stdout
is embedded in the d_ret
record. Notice that the formatting is lost, but we can regenerate this with some shell piping. Pipe the above through some grep
, awk
, and xargs
:
'{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234",
"job": "0",
"when": "end",
"field": "stdout"
}
}' --quiet --jsonpprintindent 4 |\
grep July | awk -F \: '{print $2}' | xargs -i% printf "%"
which results in
July 1970
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
The important points to note in this query are the meta
parameters to the search
command. Essentially we asked pman
to search for a hit with a jid
(job-ID) of cal-job-1234
(which was the jid
we specified when we contacted pman
originally). The job hit will contain a lot of information. We can prune this a bit by asking for a specific subset, specified by the job
, when
, and field
parameters as shown.
Using the purl
prefix, try the same query using
'{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234"
}
}' --quiet --jsonpprintindent 4
The above call returns the JSON string:
{
"meta": {
"jid": "cal-job-1234",
"threaded": true,
"cmd": "cal 7 1970",
"auid": "rudolphpienaar"
},
"status": true,
"path": "/api/v1/cmd",
"jobRootDir": "20170303164938.122651_6e09943c-6fc0-45c8-b088-2394e5886b69",
"receivedByServer": [
"POST /api/v1/cmd HTTP/1.1\r",
"Host: 172.17.0.2:5010\r",
"User-Agent: PycURL/7.43.0 libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3\r",
"Accept: */*\r",
"Content-type: application/vnd.collection+json\r",
"Content-Length: 128\r",
"\r",
"{\"payload\": {\"meta\": {\"jid\": \"cal-job-1234\", \"threaded\": true, \"cmd\": \"cal 7 1970\", \"auid\": \"rudolphpienaar\"}, \"action\": \"run\"}}"
],
"action": "run",
"payloadsize": 128,
"RESTverb": "POST",
"RESTheader": "POST /api/v1/cmd HTTP/1.1\r"
}
Using the core base call of
purl --verb POST --raw --http 172.17.0.2:5010/api/v1/cmd --jsonwrapper 'payload' --msg \
experiment with the following msg
payloads:
'{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234",
"job": "0",
"when": "end",
"field": "cmd"
}
}' --quiet --jsonpprintindent 4
'{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234",
"job": "0",
"when": "end",
"field": "returncode"
}
}' --quiet --jsonpprintindent 4
'{ "action": "search",
"meta": {
"key": "jid",
"value": "cal-job-1234",
"job": "0",
"when": "end",
"field": "auid"
}
}' --quiet --jsonpprintindent 4
--30--