CDAP Lifecycle API: JSON Formatting Issues
CDAP’s PUT API for updating an application expects a proper JSON object under the “config” key for instance configuration info, but the GET API returns the JSON config data as a string under the “configuration” key. This is due to a longtime bug with the JSON output formatter. This article describes a workaround for this issue, providing simple scripts one can use for this purpose, in Node.js and Python.
Node.js
For now, we can workaround this issue using this Node.JS script, named test-json.js:
|
where package.json looks like this:
|
After npm install
has been run, the above script can be called, for example, like node test-json.js "http://vravish-012120-ashau-dev0-dot-usw1.datafusion.googleusercontent.com/api/v3/namespaces/default/apps/body-separator" $(gcloud auth print-access-token)
. The output will be properly formatted JSON, parsable with a tool like JQ, representing the application data in expected format.
Python
We also have a Python script, called clean-json.py:
|
The above script can be called like python clean-json.py "http://vravish-012120-ashau-dev0-dot-usw1.datafusion.googleusercontent.com/api/v3/namespaces/default/apps/body-separator" $(gcloud auth print-access-token) <OPTIONAL_FILE_NAME>
which will also return JSON output parsable with JQ. If the file name is not specified, then the script only prints to stdout; otherwise, it prints to stdout and the file, which doesn’t need to exist beforehand.