This is an automated email from the ASF dual-hosted git repository.
olehmykolaishyn pushed a commit to branch 2.5.1-tensor-jupyterlab
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git
The following commit(s) were added to refs/heads/2.5.1-tensor-jupyterlab by
this push:
new 543fca1 added tensor-jupyterlab folder and configuration file
543fca1 is described below
commit 543fca1f29a9a01b3b3e44074d7c7e454cfbf823
Author: oleh_mykolaishyn <[email protected]>
AuthorDate: Mon Feb 14 18:45:07 2022 +0200
added tensor-jupyterlab folder and configuration file
---
.../scripts/aws/tensor-jupyterlab_configure.py | 338 +++++++++++++++++++++
.../src/tensor-jupyterlab/fabfile.py | 254 ++++++++++++++++
.../scripts/configure_tensor-jupyterlab_node.py | 155 ++++++++++
3 files changed, 747 insertions(+)
diff --git
a/infrastructure-provisioning/src/general/scripts/aws/tensor-jupyterlab_configure.py
b/infrastructure-provisioning/src/general/scripts/aws/tensor-jupyterlab_configure.py
new file mode 100644
index 0000000..2a0d115
--- /dev/null
+++
b/infrastructure-provisioning/src/general/scripts/aws/tensor-jupyterlab_configure.py
@@ -0,0 +1,338 @@
+#!/usr/bin/python3
+
+# *****************************************************************************
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
******************************************************************************
+
+import argparse
+import datalab.fab
+import datalab.actions_lib
+import datalab.meta_lib
+import json
+import os
+import sys
+import traceback
+import subprocess
+from fabric import *
+from datalab.logger import logging
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--uuid', type=str, default='')
+args = parser.parse_args()
+
+if __name__ == "__main__":
+ instance_class = 'notebook'
+ try:
+ notebook_config = dict()
+ try:
+ notebook_config['exploratory_name'] =
os.environ['exploratory_name']
+ except:
+ notebook_config['exploratory_name'] = ''
+ notebook_config['service_base_name'] =
os.environ['conf_service_base_name']
+ notebook_config['project_name'] = os.environ['project_name']
+ notebook_config['endpoint_name'] = os.environ['endpoint_name']
+ notebook_config['instance_type'] =
os.environ['aws_notebook_instance_type']
+ notebook_config['key_name'] = os.environ['conf_key_name']
+ notebook_config['user_keyname'] = notebook_config['project_name']
+ notebook_config['network_type'] = os.environ['conf_network_type']
+ notebook_config['instance_name'] =
'{}-{}-{}-nb-{}-{}'.format(notebook_config['service_base_name'],
+
notebook_config['project_name'],
+
notebook_config['endpoint_name'],
+
notebook_config['exploratory_name'], args.uuid)
+ notebook_config['image_enabled'] = os.environ['conf_image_enabled']
+ notebook_config['shared_image_enabled'] =
os.environ['conf_shared_image_enabled']
+ if os.environ['conf_shared_image_enabled'] == 'false':
+ notebook_config['expected_image_name'] =
'{0}-{1}-{2}-{3}-notebook-image'.format(
+ notebook_config['service_base_name'],
+ notebook_config['project_name'],
+ notebook_config['endpoint_name'],
+ os.environ['application'])
+ else:
+ notebook_config['expected_image_name'] =
'{0}-{1}-{2}-notebook-image'.format(
+ notebook_config['service_base_name'],
+ notebook_config['endpoint_name'],
+ os.environ['application'])
+ notebook_config['notebook_image_name'] =
str(os.environ.get('notebook_image_name'))
+ notebook_config['role_profile_name'] = '{}-{}-{}-nb-de-profile'.format(
+ notebook_config['service_base_name'],
notebook_config['project_name'], notebook_config['endpoint_name'])
+ notebook_config['security_group_name'] =
'{}-{}-{}-nb-sg'.format(notebook_config['service_base_name'],
+
notebook_config['project_name'],
+
notebook_config['endpoint_name'])
+ notebook_config['tag_name'] =
'{}-tag'.format(notebook_config['service_base_name'])
+ notebook_config['datalab_ssh_user'] = os.environ['conf_os_user']
+ notebook_config['ip_address'] =
datalab.meta_lib.get_instance_ip_address(
+ notebook_config['tag_name'],
notebook_config['instance_name']).get('Private')
+
+ # generating variables regarding EDGE proxy on Notebook instance
+ instance_hostname =
datalab.meta_lib.get_instance_hostname(notebook_config['tag_name'],
+
notebook_config['instance_name'])
+ edge_instance_name =
'{}-{}-{}-edge'.format(notebook_config['service_base_name'],
+
notebook_config['project_name'], notebook_config['endpoint_name'])
+ edge_instance_hostname =
datalab.meta_lib.get_instance_hostname(notebook_config['tag_name'],
edge_instance_name)
+ edge_instance_private_ip =
datalab.meta_lib.get_instance_ip_address(notebook_config['tag_name'],
+
edge_instance_name).get('Private')
+ notebook_config['edge_instance_hostname'] =
datalab.meta_lib.get_instance_hostname(notebook_config['tag_name'],
+
edge_instance_name)
+ keyfile_name = "{}{}.pem".format(os.environ['conf_key_dir'],
os.environ['conf_key_name'])
+ edge_ip =
datalab.meta_lib.get_instance_ip_address(notebook_config['tag_name'],
edge_instance_name).get(
+ 'Private')
+ except Exception as err:
+ datalab.fab.append_result("Failed to generate variables dictionary.",
str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ try:
+ if os.environ['conf_os_family'] == 'debian':
+ notebook_config['initial_user'] = 'ubuntu'
+ notebook_config['sudo_group'] = 'sudo'
+ if os.environ['conf_os_family'] == 'redhat':
+ notebook_config['initial_user'] = 'ec2-user'
+ notebook_config['sudo_group'] = 'wheel'
+
+ logging.info('[CREATING DATALAB SSH USER]')
+ params = "--hostname {} --keyfile {} --initial_user {} --os_user {}
--sudo_group {}".format(
+ instance_hostname, "{}{}.pem".format(os.environ['conf_key_dir'],
os.environ['conf_key_name']),
+ notebook_config['initial_user'],
notebook_config['datalab_ssh_user'], notebook_config['sudo_group'])
+
+ try:
+ subprocess.run("~/scripts/{}.py {}".format('create_ssh_user',
params), shell=True, check=True)
+ except:
+ traceback.print_exc()
+ raise Exception
+ except Exception as err:
+ datalab.fab.append_result("Failed creating ssh user 'datalab'.",
str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ # configuring proxy on Notebook instance
+ try:
+ logging.info('[CONFIGURE PROXY ON TENSOR INSTANCE]')
+ additional_config = {"proxy_host": edge_instance_hostname,
"proxy_port": "3128"}
+ params = "--hostname {} --instance_name {} --keyfile {}
--additional_config '{}' --os_user {}"\
+ .format(instance_hostname, notebook_config['instance_name'],
keyfile_name, json.dumps(additional_config),
+ notebook_config['datalab_ssh_user'])
+ try:
+ subprocess.run("~/scripts/{}.py
{}".format('common_configure_proxy', params), shell=True, check=True)
+ except:
+ traceback.print_exc()
+ raise Exception
+ except Exception as err:
+ datalab.fab.append_result("Failed to configure proxy.", str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ # updating repositories & installing python packages
+ try:
+ logging.info('[INSTALLING PREREQUISITES TO TENSOR NOTEBOOK INSTANCE]')
+ params = "--hostname {} --keyfile {} --user {} --region {}
--edge_private_ip {}". \
+ format(instance_hostname, keyfile_name,
notebook_config['datalab_ssh_user'], os.environ['aws_region'],
+ edge_instance_private_ip)
+ try:
+ subprocess.run("~/scripts/{}.py
{}".format('install_prerequisites', params), shell=True, check=True)
+ except:
+ traceback.print_exc()
+ raise Exception
+ except Exception as err:
+ datalab.fab.append_result("Failed installing apps: apt & pip.",
str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ # installing and configuring TensorFlow and all dependencies
+ try:
+ logging.info('[CONFIGURE TENSORFLOW NOTEBOOK INSTANCE]')
+ params = "--hostname {0} --keyfile {1} " \
+ "--region {2} --os_user {3} " \
+ "--ip_address {4} --exploratory_name {5} --edge_ip {6}" \
+ .format(instance_hostname, keyfile_name,
+ os.environ['aws_region'],
notebook_config['datalab_ssh_user'],
+ notebook_config['ip_address'],
notebook_config['exploratory_name'], edge_ip)
+ try:
+ subprocess.run("~/scripts/{}.py
{}".format('configure_tensor_node', params), shell=True, check=True)
+ except:
+ traceback.print_exc()
+ raise Exception
+ except Exception as err:
+ datalab.fab.append_result("Failed to configure TensorFlow.", str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ try:
+ logging.info('[INSTALLING USERs KEY]')
+ additional_config = {"user_keyname": notebook_config['user_keyname'],
+ "user_keydir": os.environ['conf_key_dir']}
+ params = "--hostname {} --keyfile {} --additional_config '{}' --user
{}".format(
+ instance_hostname, keyfile_name, json.dumps(additional_config),
notebook_config['datalab_ssh_user'])
+ try:
+ subprocess.run("~/scripts/{}.py {}".format('install_user_key',
params), shell=True, check=True)
+ except:
+ traceback.print_exc()
+ raise Exception
+ except Exception as err:
+ datalab.fab.append_result("Failed installing users key.", str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ try:
+ logging.info('[SETUP USER GIT CREDENTIALS]')
+ params = '--os_user {} --notebook_ip {} --keyfile "{}"' \
+ .format(notebook_config['datalab_ssh_user'], instance_hostname,
keyfile_name)
+ try:
+ subprocess.run("~/scripts/{}.py {}".format('manage_git_creds',
params), shell=True, check=True)
+ except:
+ datalab.fab.append_result("Failed setup git credentials")
+ raise Exception
+ except Exception as err:
+ datalab.fab.append_result("Failed to setup git credentials.", str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ try:
+ logging.info('[POST CONFIGURING PROCESS]')
+ if notebook_config['notebook_image_name'] not in
[notebook_config['expected_image_name'], 'None', '']:
+ params = "--hostname {} --keyfile {} --os_user {} --nb_tag_name {}
--nb_tag_value {}" \
+ .format(instance_hostname, keyfile_name,
notebook_config['datalab_ssh_user'],
+ notebook_config['tag_name'],
notebook_config['instance_name'])
+ try:
+ subprocess.run("~/scripts/{}.py
{}".format('common_remove_remote_kernels', params), shell=True, check=True)
+ except:
+ traceback.print_exc()
+ raise Exception
+ except Exception as err:
+ datalab.fab.append_result("Failed to post configuring instance.",
str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ try:
+ logging.info('[SETUP EDGE REVERSE PROXY TEMPLATE]')
+ additional_info = {
+ 'instance_hostname': instance_hostname,
+ 'tensor': True
+ }
+ params = "--edge_hostname {} --keyfile {} --os_user {} --type {}
--exploratory_name {} --additional_info '{}'" \
+ .format(edge_instance_hostname, keyfile_name,
notebook_config['datalab_ssh_user'], 'jupyter',
+ notebook_config['exploratory_name'],
json.dumps(additional_info))
+ try:
+ subprocess.run("~/scripts/{}.py
{}".format('common_configure_reverse_proxy', params), shell=True, check=True)
+ except:
+ datalab.fab.append_result("Failed edge reverse proxy template")
+ raise Exception
+ except Exception as err:
+ datalab.fab.append_result("Failed to set edge reverse proxy
template.", str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+
+ if notebook_config['image_enabled'] == 'true':
+ try:
+ logging.info('[CREATING AMI]')
+ ami_id =
datalab.meta_lib.get_ami_id_by_name(notebook_config['expected_image_name'])
+ if ami_id == '' and notebook_config['shared_image_enabled'] ==
'false':
+ logging.info("Looks like it's first time we configure notebook
server. Creating image.")
+ try:
+ os.environ['conf_additional_tags'] =
'{2};project_tag:{0};endpoint_tag:{1};'.format(
+ os.environ['project_name'],
os.environ['endpoint_name'], os.environ['conf_additional_tags'])
+ except KeyError:
+ os.environ['conf_additional_tags'] =
'project_tag:{0};endpoint_tag:{1}'.format(
+ os.environ['project_name'],
os.environ['endpoint_name'])
+ image_id = datalab.actions_lib.create_image_from_instance(
+ tag_name=notebook_config['tag_name'],
instance_name=notebook_config['instance_name'],
+ image_name=notebook_config['expected_image_name'])
+ if image_id != '':
+ logging.info("Image was successfully created. It's ID is
{}".format(image_id))
+ else:
+ logging.info("Looks like it's first time we configure notebook
server. Creating image.")
+ try:
+ os.environ['conf_additional_tags'] =
'{};ami:shared;endpoint_tag:{};'.format(
+ os.environ['conf_additional_tags'],
os.environ['endpoint_name'])
+ except KeyError:
+ os.environ['conf_additional_tags'] =
'ami:shared;endpoint_tag:{}'.format(
+ os.environ['endpoint_name'])
+ image_id = datalab.actions_lib.create_image_from_instance(
+ tag_name=notebook_config['tag_name'],
instance_name=notebook_config['instance_name'],
+ image_name=notebook_config['expected_image_name'])
+ if image_id != '':
+ logging.info("Image was successfully created. It's ID is
{}".format(image_id))
+ except Exception as err:
+ datalab.fab.append_result("Failed creating image.", str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
+ try:
+ # generating output information
+ ip_address =
datalab.meta_lib.get_instance_ip_address(notebook_config['tag_name'],
+
notebook_config['instance_name']).get('Private')
+ dns_name =
datalab.meta_lib.get_instance_hostname(notebook_config['tag_name'],
notebook_config['instance_name'])
+ tensorboard_url = "http://" + ip_address + ":6006/"
+ jupyter_ip_url = "http://" + ip_address +
":8888/{}/".format(notebook_config['exploratory_name'])
+ jupyter_notebook_access_url =
"https://{}/{}/".format(notebook_config['edge_instance_hostname'],
+
notebook_config['exploratory_name'])
+ tensorboard_access_url =
"https://{}/{}-tensor/".format(notebook_config['edge_instance_hostname'],
+
notebook_config['exploratory_name'])
+ jupyter_ungit_access_url =
"https://{}/{}-ungit/".format(notebook_config['edge_instance_hostname'],
+
notebook_config['exploratory_name'])
+ ungit_ip_url = "http://" + ip_address +
":8085/{}-ungit/".format(notebook_config['exploratory_name'])
+ logging.info('[SUMMARY]')
+ logging.info("Instance name:
{}".format(notebook_config['instance_name']))
+ logging.info("Private DNS: {}".format(dns_name))
+ logging.info("Private IP: {}".format(ip_address))
+ logging.info("Instance ID:
{}".format(datalab.meta_lib.get_instance_by_name(notebook_config['tag_name'],
+
notebook_config['instance_name'])))
+ logging.info("Instance type:
{}".format(notebook_config['instance_type']))
+ logging.info("Key name: {}".format(notebook_config['key_name']))
+ logging.info("User key name:
{}".format(notebook_config['user_keyname']))
+ logging.info("AMI name:
{}".format(notebook_config['notebook_image_name']))
+ logging.info("Profile name:
{}".format(notebook_config['role_profile_name']))
+ logging.info("SG name:
{}".format(notebook_config['security_group_name']))
+ logging.info("TensorBoard URL: {}".format(tensorboard_url))
+ logging.info("TensorBoard log dir: /var/log/tensorboard")
+ logging.info("Jupyter URL: {}".format(jupyter_ip_url))
+ logging.info("Ungit URL: {}".format(ungit_ip_url))
+ logging.info('SSH access (from Edge node, via IP address): ssh -i
{0}.pem {1}@{2}'.format(
+ notebook_config['key_name'], notebook_config['datalab_ssh_user'],
ip_address))
+ logging.info('SSH access (from Edge node, via FQDN): ssh -i {0}.pem
{1}@{2}'.format(
+ notebook_config['key_name'], notebook_config['datalab_ssh_user'],
dns_name))
+
+ with open("/root/result.json", 'w') as result:
+ res = {"hostname": dns_name,
+ "ip": ip_address,
+ "instance_id":
datalab.meta_lib.get_instance_by_name(notebook_config['tag_name'],
+
notebook_config['instance_name']),
+ "master_keyname": os.environ['conf_key_name'],
+ "tensorboard_log_dir": "/var/log/tensorboard",
+ "notebook_name": notebook_config['instance_name'],
+ "notebook_image_name":
notebook_config['notebook_image_name'],
+ "Action": "Create new notebook server",
+ "exploratory_url": [
+ {"description": "Jupyter",
+ "url": jupyter_notebook_access_url},
+ {"description": "TensorBoard",
+ "url": tensorboard_access_url},
+ {"description": "Ungit",
+ "url": jupyter_ungit_access_url}#,
+ #{"description": "Jupyter (via tunnel)",
+ # "url": jupyter_ip_url},
+ #{"description": "TensorBoard (via tunnel)",
+ # "url": tensorboard_url},
+ #{"description": "Ungit (via tunnel)",
+ # "url": ungit_ip_url}
+ ]}
+ result.write(json.dumps(res))
+ except Exception as err:
+ datalab.fab.append_result("Error with writing results.", str(err))
+ datalab.actions_lib.remove_ec2(notebook_config['tag_name'],
notebook_config['instance_name'])
+ sys.exit(1)
diff --git a/infrastructure-provisioning/src/tensor-jupyterlab/fabfile.py
b/infrastructure-provisioning/src/tensor-jupyterlab/fabfile.py
new file mode 100644
index 0000000..b6d0e16
--- /dev/null
+++ b/infrastructure-provisioning/src/tensor-jupyterlab/fabfile.py
@@ -0,0 +1,254 @@
+#!/usr/bin/python3
+
+# *****************************************************************************
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
******************************************************************************
+
+import logging
+import os
+import sys
+import uuid
+import subprocess
+from datalab.actions_lib import *
+from datalab.fab import *
+from datalab.meta_lib import *
+
+
+# Main function for provisioning notebook server
+@task
+def run(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ notebook_config = dict()
+ notebook_config['uuid'] = str(uuid.uuid4())[:5]
+
+ try:
+ params = "--uuid {}".format(notebook_config['uuid'])
+ subprocess.run("~/scripts/{}.py {}".format('common_prepare_notebook',
params), shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed preparing Notebook node.", str(err))
+ sys.exit(1)
+
+ try:
+ params = "--uuid {}".format(notebook_config['uuid'])
+ subprocess.run("~/scripts/{}.py {}".format('tensor_configure',
params), shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed configuring Notebook node.", str(err))
+ sys.exit(1)
+
+
+# Main function for terminating exploratory environment
+@task
+def terminate(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'], os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+ try:
+ subprocess.run("~/scripts/{}.py".format('common_terminate_notebook'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed terminating Notebook node.", str(err))
+ sys.exit(1)
+
+
+# Main function for stopping notebook server
+@task
+def stop(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'], os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+ try:
+ subprocess.run("~/scripts/{}.py".format('common_stop_notebook'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed stopping Notebook node.", str(err))
+ sys.exit(1)
+
+
+# Main function for starting notebook server
+@task
+def start(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'], os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+ subprocess.run("~/scripts/{}.py".format('common_start_notebook'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed starting Notebook node.", str(err))
+ sys.exit(1)
+
+
+# Main function for configuring notebook server after deploying DataEngine
service
+@task
+def configure(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+ if os.environ['conf_resource'] == 'dataengine':
+
subprocess.run("~/scripts/{}.py".format('common_notebook_configure_dataengine'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed configuring dataengine on Notebook node.",
str(err))
+ sys.exit(1)
+
+
+# Main function for installing additional libraries for notebook
+@task
+def install_libs(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+ subprocess.run("~/scripts/{}.py".format('notebook_install_libs'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed installing additional libs for Notebook node.",
str(err))
+ sys.exit(1)
+
+
+# Main function for get available libraries for notebook
+@task
+def list_libs(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+ subprocess.run("~/scripts/{}.py".format('notebook_list_libs'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed get available libraries for notebook node.",
str(err))
+ sys.exit(1)
+
+
+# Main function for manage git credentials on notebook
+@task
+def git_creds(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+ subprocess.run("~/scripts/{}.py".format('notebook_git_creds'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed to manage git credentials for notebook node.",
str(err))
+ sys.exit(1)
+
+
+# Main function for creating image from notebook
+@task
+def create_image(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+
subprocess.run("~/scripts/{}.py".format('common_create_notebook_image'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed to create image from notebook node.", str(err))
+ sys.exit(1)
+
+
+# Main function for deleting existing notebook image
+@task
+def terminate_image(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+
subprocess.run("~/scripts/{}.py".format('common_terminate_notebook_image'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed to create image from notebook node.", str(err))
+ sys.exit(1)
+
+
+# Main function for reconfiguring Spark for notebook
+@task
+def reconfigure_spark(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+ subprocess.run("~/scripts/{}.py".format('notebook_reconfigure_spark'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed to reconfigure Spark for Notebook node.",
str(err))
+ sys.exit(1)
+
+# Main function for checking inactivity status
+@task
+def check_inactivity(ctx):
+ local_log_filename = "{}_{}_{}.log".format(os.environ['conf_resource'],
os.environ['project_name'],
+ os.environ['request_id'])
+ local_log_filepath = "/logs/" + os.environ['conf_resource'] + "/" +
local_log_filename
+ logging.basicConfig(format='%(levelname)-8s [%(asctime)s] %(message)s',
+ level=logging.DEBUG,
+ filename=local_log_filepath)
+
+ try:
+ subprocess.run("~/scripts/{}.py".format('notebook_inactivity_check'),
shell=True, check=True)
+ except Exception as err:
+ traceback.print_exc()
+ append_result("Failed to check inactivity status.", str(err))
+ sys.exit(1)
\ No newline at end of file
diff --git
a/infrastructure-provisioning/src/tensor-jupyterlab/scripts/configure_tensor-jupyterlab_node.py
b/infrastructure-provisioning/src/tensor-jupyterlab/scripts/configure_tensor-jupyterlab_node.py
new file mode 100644
index 0000000..3566518
--- /dev/null
+++
b/infrastructure-provisioning/src/tensor-jupyterlab/scripts/configure_tensor-jupyterlab_node.py
@@ -0,0 +1,155 @@
+#!/usr/bin/python3
+
+# *****************************************************************************
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
******************************************************************************
+
+import argparse
+import os
+import sys
+from datalab.actions_lib import *
+from datalab.common_lib import *
+from datalab.fab import *
+from datalab.notebook_lib import *
+from fabric import *
+from patchwork.files import exists
+from patchwork import files
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--hostname', type=str, default='')
+parser.add_argument('--keyfile', type=str, default='')
+parser.add_argument('--region', type=str, default='')
+parser.add_argument('--os_user', type=str, default='')
+parser.add_argument('--ip_address', type=str, default='')
+parser.add_argument('--exploratory_name', type=str, default='')
+parser.add_argument('--edge_ip', type=str, default='')
+args = parser.parse_args()
+
+spark_version = os.environ['notebook_spark_version']
+hadoop_version = os.environ['notebook_hadoop_version']
+tensorflow_version = os.environ['notebook_tensorflow_version']
+jupyter_version = os.environ['notebook_jupyter_version']
+nvidia_version = os.environ['notebook_nvidia_version']
+theano_version = os.environ['notebook_theano_version']
+keras_version = os.environ['notebook_keras_version']
+python_venv_version = os.environ['notebook_python_venv_version']
+python_venv_path =
'/opt/python/python{0}/bin/python{1}'.format(python_venv_version,
python_venv_version[:3])
+if args.region == 'cn-north-1':
+ spark_link = "http://mirrors.hust.edu.cn/apache/spark/spark-" +
spark_version + "/spark-" + spark_version + \
+ "-bin-hadoop" + hadoop_version + ".tgz"
+else:
+ spark_link = "https://archive.apache.org/dist/spark/spark-" +
spark_version + "/spark-" + spark_version + \
+ "-bin-hadoop" + hadoop_version + ".tgz"
+pyspark_local_path_dir = '/home/' + args.os_user +
'/.local/share/jupyter/kernels/pyspark_local/'
+py3spark_local_path_dir = '/home/' + args.os_user +
'/.local/share/jupyter/kernels/py3spark_local/'
+local_spark_path = '/opt/spark/'
+jars_dir = '/opt/jars/'
+templates_dir = '/root/templates/'
+files_dir = '/root/files/'
+jupyter_conf_file = '/home/' + args.os_user +
'/.local/share/jupyter/jupyter_notebook_config.py'
+gitlab_certfile = os.environ['conf_gitlab_certfile']
+cuda_version = os.environ['notebook_cuda_version']
+cuda_file_name = os.environ['notebook_cuda_file_name']
+cudnn_version = os.environ['notebook_cudnn_version']
+cudnn_file_name = os.environ['notebook_cudnn_file_name']
+
+
+##############
+# Run script #
+##############
+if __name__ == "__main__":
+ print("Configure connections")
+ global conn
+ conn = datalab.fab.init_datalab_connection(args.hostname, args.os_user,
args.keyfile)
+
+ # PREPARE DISK
+ print("Prepare .ensure directory")
+ try:
+ if not exists(conn,'/home/' + args.os_user + '/.ensure_dir'):
+ conn.sudo('mkdir /home/' + args.os_user + '/.ensure_dir')
+ except:
+ sys.exit(1)
+ print("Mount additional volume")
+ prepare_disk(args.os_user)
+
+ # INSTALL LANGUAGES
+ print("Install Java")
+ ensure_jre_jdk(args.os_user)
+ print("Install Python 3 modules")
+ ensure_python3_libraries(args.os_user)
+
+ # INSTALL PYTHON IN VIRTUALENV
+ print("Configure Python Virtualenv")
+ ensure_python_venv(python_venv_version)
+
+ # INSTALL TENSORFLOW AND OTHER DEEP LEARNING LIBRARIES
+ print("Install TensorFlow")
+ install_tensor(args.os_user, cuda_version, cuda_file_name,
+ cudnn_version, cudnn_file_name, tensorflow_version,
+ templates_dir, nvidia_version)
+ print("Install Theano")
+ install_theano(args.os_user, theano_version)
+ print("Installing Keras")
+ install_keras(args.os_user, keras_version)
+
+ # INSTALL JUPYTER NOTEBOOK
+ print("Install Jupyter")
+ configure_jupyter(args.os_user, jupyter_conf_file, templates_dir,
jupyter_version, args.exploratory_name)
+
+ # INSTALL SPARK AND CLOUD STORAGE JARS FOR SPARK
+ print("Install local Spark")
+ ensure_local_spark(args.os_user, spark_link, spark_version,
hadoop_version, local_spark_path )
+ print("Install storage jars")
+ ensure_local_jars(args.os_user, jars_dir)
+ print("Configure local Spark")
+ configure_local_spark(jars_dir, templates_dir)
+
+ # INSTALL JUPYTER KERNELS
+ #print("Install pyspark local kernel for Jupyter")
+ #ensure_pyspark_local_kernel(args.os_user, pyspark_local_path_dir,
templates_dir, spark_version)
+ print("Install py3spark local kernel for Jupyter")
+ ensure_py3spark_local_kernel(args.os_user, py3spark_local_path_dir,
templates_dir, spark_version, python_venv_path, python_venv_version)
+
+ # INSTALL UNGIT
+ print("Install nodejs")
+ install_nodejs(args.os_user)
+ print("Install Ungit")
+ install_ungit(args.os_user, args.exploratory_name, args.edge_ip)
+ if exists(conn, '/home/{0}/{1}'.format(args.os_user, gitlab_certfile)):
+ install_gitlab_cert(args.os_user, gitlab_certfile)
+
+ # INSTALL INACTIVITY CHECKER
+ print("Install inactivity checker")
+ install_inactivity_checker(args.os_user, args.ip_address)
+
+ # INSTALL OPTIONAL PACKAGES
+ print("Installing additional Python packages")
+ ensure_additional_python_libs(args.os_user)
+ if os.environ['conf_cloud_provider'] == 'aws':
+ print('Installing Pytorch')
+ ensure_pytorch(args.os_user)
+ print("Install Matplotlib")
+ ensure_matplot(args.os_user)
+
+ #POST INSTALLATION PROCESS
+ print("Updating pyOpenSSL library")
+ update_pyopenssl_lib(args.os_user)
+
+ conn.close()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]