This is an automated email from the ASF dual-hosted git repository.

mykolabodnar pushed a commit to branch DLAB-1570
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit b21492767c1578bdc2f6b20019e91f6b665f108e
Author: Mykola_Bodnar1 <[email protected]>
AuthorDate: Thu Feb 27 16:34:43 2020 +0200

    [DLAB-1570]: Rarely notebook creation fails on stage of 'npm' installation 
fixed
---
 .../src/general/lib/os/debian/common_lib.py        | 24 ++++++++++++++++++++++
 .../src/general/lib/os/fab.py                      |  6 +++---
 .../src/ssn/scripts/configure_ui.py                |  3 ++-
 3 files changed, 29 insertions(+), 4 deletions(-)

diff --git 
a/infrastructure-provisioning/src/general/lib/os/debian/common_lib.py 
b/infrastructure-provisioning/src/general/lib/os/debian/common_lib.py
index c4f8ff4..ff8018f 100644
--- a/infrastructure-provisioning/src/general/lib/os/debian/common_lib.py
+++ b/infrastructure-provisioning/src/general/lib/os/debian/common_lib.py
@@ -27,6 +27,30 @@ import sys
 import os
 import time
 
+def manage_npm_pkg(command):
+    try:
+        npm_count = 0
+        installed = False
+        npm_registry_first = ['https://registry.npmjs.org/', 
'https://registry.npmjs.com/']
+        while not installed:
+            if npm_count > 60:
+                print("NPM registry is not available, please try later")
+                sys.exit(1)
+            else:
+                try:
+                    if npm_count % 2 == 0:
+                        sudo('npm config set registry 
{}'.format(npm_registry_first[0]))
+                    else:
+                        sudo('npm config set registry 
{}'.format(npm_registry_first[1]))
+                    sudo('npm {}'.format(command))
+                    installed = True
+                except:
+                    npm_count += 1
+                    time.sleep(50)
+    except:
+        sys.exit(1)
+
+
 def manage_pkg(command, environment, requisites):
     try:
         allow = False
diff --git a/infrastructure-provisioning/src/general/lib/os/fab.py 
b/infrastructure-provisioning/src/general/lib/os/fab.py
index a1e1a16..a13daa7 100644
--- a/infrastructure-provisioning/src/general/lib/os/fab.py
+++ b/infrastructure-provisioning/src/general/lib/os/fab.py
@@ -32,7 +32,7 @@ from dlab.actions_lib import *
 import dlab.actions_lib
 import re
 import traceback
-from dlab.common_lib import manage_pkg
+from dlab.common_lib import *
 
 
 def ensure_pip(requisites):
@@ -499,10 +499,10 @@ def ensure_toree_local_kernel(os_user, toree_link, 
scala_kernel_path, files_dir,
             sys.exit(1)
 
 
-def install_ungit(os_user, notebook_name, edge_ip):
+def (os_user, notebook_name, edge_ip):
     if not exists('/home/{}/.ensure_dir/ungit_ensured'.format(os_user)):
         try:
-            sudo('npm -g install 
ungit@{}'.format(os.environ['notebook_ungit_version']))
+            manage_npm_pkg('-g install 
ungit@{}'.format(os.environ['notebook_ungit_version']))
             put('/root/templates/ungit.service', '/tmp/ungit.service')
             sudo("sed -i 's|OS_USR|{}|' /tmp/ungit.service".format(os_user))
             http_proxy = run('echo $http_proxy')
diff --git a/infrastructure-provisioning/src/ssn/scripts/configure_ui.py 
b/infrastructure-provisioning/src/ssn/scripts/configure_ui.py
index ad3b7ed..e38adda 100644
--- a/infrastructure-provisioning/src/ssn/scripts/configure_ui.py
+++ b/infrastructure-provisioning/src/ssn/scripts/configure_ui.py
@@ -31,6 +31,7 @@ import os
 import traceback
 from dlab.ssn_lib import *
 from dlab.fab import *
+from common_lib.py import *
 
 parser = argparse.ArgumentParser()
 parser.add_argument('--hostname', type=str, default='')
@@ -149,7 +150,7 @@ def build_ui():
                      '\'use_ldap\': false'))
 
             sudo('echo "N" | npm install')
-            sudo('npm run build.prod')
+            manage_npm_pkg('run build.prod')
             sudo('sudo chown -R {} {}/*'.format(args.os_user, args.dlab_path))
 
         # Building Back-end


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to