Monday, November 2, 2015

How to use shell script variables and REST API to create Drill storage plugins

Env:

Drill 1.2

Goal:

How to use shell script variables and REST API to create Drill storage plugins

Solution:

In https://drill.apache.org/docs/plugin-configuration-basics/, here is an example to use REST API to create a sample Drill storage plugin:
curl -X POST -H "Content-Type: application/json" -d '{"name":"myplugin", "config": {"type": "file", "enabled": false, "connection": "file:///", "workspaces": { "root": { "location": "/", "writable": false, "defaultInputFormat": null}}, "formats": null}}' http://localhost:8047/storage/myplugin.json

If we want to add a variable, we can use shell script to do that. Since the content may be in the single or double quotes, the key here is to close the quotes firstly, and then insert into the variable.
For example, "writable" can be a variable -- true or false. Here is a shell script -- create_storage.sh:
curl -X POST -H "Content-Type: application/json" -d '{"name":"myplugin", "config": {"type": "file", "enabled": false, "connection": "file:///", "workspaces": { "root": { "location": "/", "writable": '"$1"', "defaultInputFormat": null}}, "formats": null}}' http://localhost:8047/storage/myplugin.json

Run it:
# ./create_storage.sh true
{
  "result" : "success"
}





No comments:

Post a Comment

Popular Posts