-
Notifications
You must be signed in to change notification settings - Fork 66
Feature: JupyterLab plugin #459
Changes from 4 commits
5cb6536
f7f8f66
4a5636d
c244e34
e8a36ab
127b237
eb0657c
ccad628
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .hdfs import * | ||
from .jupyter import * | ||
from .jupyter_lab import * | ||
from .rstudio_server import * |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .configuration import * |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
from aztk.models.plugins.plugin_configuration import PluginConfiguration, PluginPort, PluginRunTarget | ||
from aztk.models.plugins.plugin_file import PluginFile | ||
from aztk.utils import constants | ||
|
||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
class JupyterLabPlugin(PluginConfiguration): | ||
def __init__(self): | ||
super().__init__( | ||
name="jupyter_lab", | ||
ports=[ | ||
PluginPort( | ||
internal=8889, | ||
public=True, | ||
), | ||
], | ||
run_on=PluginRunTarget.All, | ||
execute="jupyter_lab.sh", | ||
files=[ | ||
PluginFile("jupyter_lab.sh", os.path.join(dir_path, "jupyter_lab.sh")), | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
# This custom script only works on images where jupyter is pre-installed on the Docker image | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should change all of the plugins to be self-contained. Not sure that should be done in this PR, but we will have to change it soon anyways. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, although this is no longer true since I'm install jupyter lab from conda. I copied the file over so that comment was unnecessary. |
||
# | ||
# This custom script has been tested to work on the following docker images: | ||
# - aztk/python:spark2.2.0-python3.6.2-base | ||
# - aztk/python:spark2.2.0-python3.6.2-gpu | ||
# - aztk/python:spark2.1.0-python3.6.2-base | ||
# - aztk/python:spark2.1.0-python3.6.2-gpu | ||
|
||
if [ "$IS_MASTER" = "1" ]; then | ||
conda install -c conda-force jupyterlab | ||
|
||
PYSPARK_DRIVER_PYTHON="/.pyenv/versions/${USER_PYTHON_VERSION}/bin/jupyter" | ||
JUPYTER_KERNELS="/.pyenv/versions/${USER_PYTHON_VERSION}/share/jupyter/kernels" | ||
|
||
# disable password/token on jupyter notebook | ||
jupyter lab --generate-config --allow-root | ||
JUPYTER_CONFIG='/.jupyter/jupyter_notebook_config.py' | ||
echo >> $JUPYTER_CONFIG | ||
echo -e 'c.NotebookApp.token=""' >> $JUPYTER_CONFIG | ||
echo -e 'c.NotebookApp.password=""' >> $JUPYTER_CONFIG | ||
|
||
# get master ip | ||
MASTER_IP=$(hostname -i) | ||
|
||
# remove existing kernels | ||
rm -rf $JUPYTER_KERNELS/* | ||
|
||
# set up jupyter to use pyspark | ||
mkdir $JUPYTER_KERNELS/pyspark | ||
touch $JUPYTER_KERNELS/pyspark/kernel.json | ||
cat << EOF > $JUPYTER_KERNELS/pyspark/kernel.json | ||
{ | ||
"display_name": "PySpark", | ||
"language": "python", | ||
"argv": [ | ||
"python", | ||
"-m", | ||
"ipykernel", | ||
"-f", | ||
"{connection_file}" | ||
], | ||
"env": { | ||
"SPARK_HOME": "$SPARK_HOME", | ||
"PYSPARK_PYTHON": "python", | ||
"PYSPARK_SUBMIT_ARGS": "--master spark://$MASTER_IP:7077 pyspark-shell" | ||
} | ||
} | ||
EOF | ||
|
||
# start jupyter notebook from /mnt - this is where we recommend you put your azure files mount point as well | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does jupyterlab have the same restriction as jupyter where you can't navigate up the directory structure? Right now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same limitation - you cannot navigate 'up' from /mnt. Since this is where we place samples it seems like a reasonable place to put it - where else do you think it could work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No that's fine, |
||
cd /mnt | ||
(PYSPARK_DRIVER_PYTHON=$PYSPARK_DRIVER_PYTHON PYSPARK_DRIVER_PYTHON_OPTS="lab --no-browser --port=8889 --allow-root" pyspark &) | ||
fi | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -27,6 +27,11 @@ def setup_node(): | |||
plugins.setup_plugins(is_master=True, is_worker=True) | ||||
scripts.run_custom_scripts(is_master=True, is_worker=True) | ||||
|
||||
#Write sentinel file on disk for host to know this is the master | ||||
path = os.environ['PWD'] + '/MASTER' | ||||
print('Writing master file to: {}'.format(path)) | ||||
f = open(path, 'w') | ||||
f.write(master_node.ip_address) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already done here: aztk/node_scripts/install/spark.py Line 50 in c244e34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||||
else: | ||||
setup_as_worker() | ||||
plugins.setup_plugins(is_master=False, is_worker=True) | ||||
|
@@ -42,7 +47,6 @@ def setup_as_master(): | |||
if os.environ["WORKER_ON_MASTER"] == "True": | ||||
spark.start_spark_worker() | ||||
|
||||
|
||||
def setup_as_worker(): | ||||
print("Setting up as worker.") | ||||
spark.setup_connection() | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be super pedantic, but I think this might be better as
jupyterlab
since they brand it as one word. I think we should also make plugins case insensitive (not in this pr, just in general).