zeppelin-api-interface v1.5.1
Zeppelin API interface
WebSocket Endpoint
Anonymous:
import { buildZeppelinWebsocket } from 'zeppelin-api-interface'
const zeppelinHost = `localhost:8000`
const wsEndpoint = `ws://${zeppelinHost}/ws`
const socket = buildZeppelinWebsocket(wsEndpoint)
// ...With login:
import { setHost, User, buildZeppelinWebsocket } from 'zeppelin-api-interface'
const zeppelinHost = `localhost:8000`
const wsEndpoint = `ws://${zeppelinHost}/ws`
const httpHost = `http://${zeppelinHost}/`
setHost(httpHost)
User.login(user, password).then(({ success, error, response }) => {
if (!success) window.alert("Login is not needed")
const credentials = response.body // { principal: '...', ticket: '...', roles: '[...]' }
const socket = buildZeppelinWebsocket(wsEndpoint, credentials)
// ...
})Then:
socket.on('error', err => {
console.error(`Error in WebSocket connection: ${JSON.stringify(err)}`)
})
socket.on('open', () => {
socket.getNotebookList() // The initial socket command
})
socket.on('send', (event, message) => {
if (message.op === 'PING') return
console.log('\uD83D\uDC5F <<', message.op, message.data || '')
})
socket.on('message', (event, message) => {
console.log('\uD83D\uDC5F >>', message.op, message.data || '')
actOnSocketMessage(message)
})In actOnSocketMessage you would manage the entire list of socket messages, while the list of possible socket commands is here.
REST Endpoints
Every function returns a promise of Object { success: boolean, response: Object | string, error?: string }.
success: the HTTP JSON call was successful or notresponse: the JSON in case of success, the body text in case of errorerror: the HTTP error returned from the server
The hostname can be set once, with setHost.
import { Notebook, Paragraph, setHost } from 'zeppelin-api-interface'
setHost('http://localhost:8080/') // In production it should be left to empty stringNotebooks
- Auto-documented source: index.js
- Zeppelin API Doc: Notebook API
// List all notebooks
Notebook.list().then(({ success, response, error }) => {
if (!success) return console.error(error) // Remember to always handle the error in some way
const notebooks = response.body
notebooks.forEach(notebook => {
console.log(`- Notebook name: "${notebook.name}" (ID: ${notebook.id})`))
})
})
// Create a notebook
Notebook.create('Test notebook 1').then(({ success, response, error }) => {
if (!success) return console.error(error) // Remember to always handle the error in some way
const createdNotebookId = response.body
console.log(`Created notebook with ID: ${createdNotebookId}`)
})If using Babel ES2017 or Node 7.6+, you can also use async/await syntax:
async function doApiCall() {
const { success, response, error } = await Notebook.create('Test notebook 2')
if (!success) return console.error(error) // Remember to always handle the error in some way
const createdNotebookId = response.body
console.log(`Created notebook with ID: ${createdNotebookId}`)
}Paragraphs
- Auto-documented source: index.js
- Zeppelin API Doc: Paragraph API
The methods are the same as in Notebook, with the exception of an additional notebookId parameter in first position.
The only difference is the Notebook.create method, which accepts an Object with the data for creation:
Paragraph.create(createdNotebookId, {
title: 'Test paragraph 1',
text: `%spark
println("Paragraph test run")
`
}).then(/* ... */)Running Paragraphs
- Auto-documented source: index.js
- Zeppelin API Doc: Paragraph Run
The ParagraphJobs namespace have methods to run, runSync, stop, stat (get status).
The runSync function does a run in a single HTTP call:
ParagraphJobs.runSync(createdNotebookId, createdParagraphId).then(({ success, response, error }) => {
if (!success) return console.error(error) // Remember to always handle the error in some way
const result = response.body // is { code: 'SUCCESS', msg: [ { type: 'TEXT', data: 'Paragraph test run\n' } ] }
})response.body.codecontains the paragraphtextcompilation status.response.body.msghas a representation of the result.
For longer data computations, an asynchronous run call will be necessary.
The implementation is there, but not yet tested.
Development
To release a new version run yarn release, it will guide to a new release.