npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zeppelin-api-interface

v1.5.1

Published

A JS API interface for REST/WebSocket endpoints of Apache Zeppelin

Downloads

8

Readme

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 not
  • response: the JSON in case of success, the body text in case of error
  • error: 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 string

Notebooks

// 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

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

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.code contains the paragraph text compilation status.
  • response.body.msg has 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.