Using REST API to Configure Zeppelin Notebooks in the Data Science Refinery

Contributed by

4 min read

When it comes to setting up Zeppelin Notebooks in the MapR Data Science Refinery (DSR), you might find your interpreters or other settings need to be specially configured, depending on the user. Normally, users have to manually adjust these configurations every time a new notebook has been created for them. However, the other option is to automate this configuration process using the Zeppelin Notebook REST API.

Adding interpreter settings can be especially tricky. In this blog post, I have provided detailed, step-by-step instructions on how to add interpreters. These steps can also act as an introduction to using other endpoints to handle other configurations - for example, authenticating via an endpoint and taking the cookie information to be able to access the other endpoints.

  1. Run a curl command to get the cookie, using your login and password for your notebook. Replace your userName and password, and the Zeppelin notebook URL and port with your own information. The last JSESSIONID is what you need to copy for subsequent curl commands. To truly automate this step you might have to run a regex script to extract the JSESSIONID, but that is out of scope for this guide.
curl -i -k --data 'userName=mapr&password=mapr' -X POST https://10.20.30.142/api/login

Example output:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: authorization,Content-Type
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, HEAD, DELETE
X-FRAME-OPTIONS: SAMEORIGIN
Strict-Transport-Security: max-age=631138519
X-XSS-Protection: 1
Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Thu, 02-May-2019 20:56:57 GMT
Set-Cookie: JSESSIONID=8a5a59fb-fc7c-443f-a767-93e5f39a7cac; Path=/; HttpOnly
Set-Cookie: JSESSIONID=deleteMe; Path=/; Max-Age=0; Expires=Thu, 02-May-2019 20:56:57 GMT
Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Thu, 02-May-2019 20:56:57 GMT
Set-Cookie: JSESSIONID=0ed89550-8cf6-4c8d-8499-631cc2cb8556; Path=/; HttpOnly
Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Thu, 02-May-2019 20:57:00 GMT
Content-Type: application/json
Content-Length: 117
Server: Jetty(9.2.15.v20160210)
  1. Create a json file (I made a file called newinterpretersample.json) to hold the settings of your new interpreter, replacing the values below with your desired values:
{
  "name": "Markdown setting name",
  "group": "md",
  "properties": {
    "someprop": {
        "value": "sampleval",
        "type": "textarea"}
  },
  "interpreterGroup": [
    {
      "class": "org.apache.zeppelin.markdown.Markdown",
      "name": "md"
    }
  ],
  "dependencies": [
    {
      "groupArtifactVersion": "groupId:artifactId:version",
      "exclusions": [
        "groupId:artifactId"
      ]
    }
  ]
}
  1. Run this curl command, substituting the following:

    • your cookie information (which you copied from the first curl command)
    • json file (newinterpretersample.json, in this case)
    • the URL and port
curl -k -b 'JSESSIONID=0ed89550-8cf6-4c8d-8499-631cc2cb8556; Path=/; HttpOnly' -H "Content-Type: application/json" --data @newinterpretersample.json -X POST https://10.20.30.142:9995/api/interpreter/setting

You should now be able to log into the Zeppelin notebook and search for the interpreter "Markdown setting name." Note that since most of the values here are just for sample purposes only, the markdown interpreter might be poorly configured. Deleting the interpreter setting is just as easy via the REST API.

  1. To delete your interpreter setting, run this statement, making sure to include the URL of the interpreter (in this case, https://10.20.30.142:9995/api/interpreter/setting/Markdown%20setting%20name):
curl -k -b 'JSESSIONID=0ed89550-8cf6-4c8d-8499-631cc2cb8556; Path=/; HttpOnly' -H "Content-Type: application/json" -X DELETE https://10.20.30.142:9995/api/interpreter/setting/Markdown%20setting%20name

That's all there is to writing custom interpreter settings! For more information on other endpoints for Zeppelin consult the Apache Zeppelin pages here: http://zeppelin.apache.org/docs/0.8.0/usage/rest_api/. The API I specifically used can be found here: http://zeppelin.apache.org/docs/0.8.0/usage/rest_api/interpreter.html#create-a-new-interpreter-setting.

Note that this guide is for adding and overriding interpreter settings for interpreters that already are installed in the DSR image you are using. To add new interpreters to Zeppelin Notebook please consult http://zeppelin.apache.org/docs/0.8.0/development/writing_zeppelin_interpreter.html and when you have added the interpreter, create a new DSR image using the changes you made so future Zeppelin Notebooks will have the interpreter when the image is spun up.

Thank you for reading and have fun exploring!


This blog post was published August 01, 2019.
Categories

50,000+ of the smartest have already joined!

Stay ahead of the bleeding edge...get the best of Big Data in your inbox.


Get our latest posts in your inbox

Subscribe Now