Saltar a contenido

33. Kernel gateway

Esta app de la familia de Jupyter permite acceder a los sevicios del nucleo sin usar mensajes. En su lugar utiliza websocket y notebook-http ( revisar)

33.1 Instalación

En el caso de usar una imagen docker, añadimos al dockerfile las siguientes lineas:

# start from the jupyter image with R, Python, and Scala (Apache Toree) kernels pre-installed
FROM jupyter/all-spark-notebook

# install the kernel gateway
RUN pip install jupyter_kernel_gateway

# run kernel gateway on container start, not notebook server
EXPOSE 8888
CMD ["jupyter", "kernelgateway", "--KernelGatewayApp.ip=0.0.0.0", "--KernelGatewayApp.port=8888"]
Y se construye la imagen y ejecuta con:

docker build -t my/kernel-gateway .
docker run -it --rm -p 8888:8888 my/kernel-gateway

33.2 Modo jupyter-websocket

Es el modo por defecto. Se establece con el parámetro de la línea de comandos: KernelGatewayApp.api=kernel_gateway.jupyter_websocket

33.2.1 Recursos HTTP

El Api HTTP consiste en el kernel, sision, monitorización y recusos de metadatos, Se puede utilizar Swagger para acceder con API REST, segun se puede ver en el volcado del fichero swagger.yaml, un pequeño corte de este fichero:

swagger: '2.0'

info:
  title: Jupyter Kernel Gateway API
  description: The API for the Jupyter Kernel Gateway
  version: "5"
  contact:
    name: Jupyter Project
    url: https://jupyter.org

produces:
  - application/json
consumes:
  - application/json
parameters:
  kernel:
    name: kernel_id
    required: true
    in: path
    description: kernel uuid
    type: string
    format: uuid
  session:
    name: session
    required: true
    in: path
    description: session uuid
    type: string
    format: uuid
Se puede usar el Swagger UI para conectar con una instancia en ejecución del kernel apuntando a /api/swagger.json . Ver este paquete Python para clientes Swagger.

33.2.2 Recursos Websocket

El recurso /api/kernels/{kernel_id}/channels multiplexa los canales del protocolo de mensajes del nucleo de Jupyter a este único

Consultar las demos de cliente de NodeJs y Python

33.3 Enlaces