Repository: zeppelin
Updated Branches:
  refs/heads/branch-0.7 bd334d024 -> 70ca8bdcb


[ZEPPELIN-2260] [branch-0.7] Skip node,npm install and bundle when no helium 
package is selected

### What is this PR for?
Apply #2137 to `branch-0.7`

Zeppelin 0.7.0 installs node and npm when it first starts for Helium package.
To be installed, or to failed to be installed due to network timeout, it takes 
some times.
We can just create empty file when no Helium package is enabled, instead of 
install npm and build bundle.
See discussion 
https://github.com/apache/zeppelin/pull/2095#issuecomment-285447619

### What type of PR is it?
Improvement

### Todos
* [x] - skip node,npm install and bundle package when no package is selected

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-2260

### How should this be tested?
When no package is selected (e.g. right after clean install Zeppelin), npm and 
node is no longer installed on startup.

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: Lee moon soo <[email protected]>

Closes #2138 from Leemoonsoo/ZEPPELIN-2260_branch-0.7 and squashes the 
following commits:

e8f0686 [Lee moon soo] Skip node,npm install and bundle when no helium package 
is selected


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/70ca8bdc
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/70ca8bdc
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/70ca8bdc

Branch: refs/heads/branch-0.7
Commit: 70ca8bdcbf6725562c7312d33afe6d6a8f1f507d
Parents: bd334d0
Author: Lee moon soo <[email protected]>
Authored: Tue Mar 14 17:56:51 2017 -0700
Committer: Lee moon soo <[email protected]>
Committed: Fri Mar 17 00:25:10 2017 -0700

----------------------------------------------------------------------
 .../helium/HeliumVisualizationFactory.java      | 27 ++++++++++++++++----
 .../helium/HeliumVisualizationFactoryTest.java  |  5 ++++
 2 files changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/70ca8bdc/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumVisualizationFactory.java
----------------------------------------------------------------------
diff --git 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumVisualizationFactory.java
 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumVisualizationFactory.java
index d6b9c61..316fc2a 100644
--- 
a/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumVisualizationFactory.java
+++ 
b/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumVisualizationFactory.java
@@ -51,6 +51,7 @@ public class HeliumVisualizationFactory {
   private File tabledataModulePath;
   private File visualizationModulePath;
   private Gson gson;
+  private boolean nodeAndNpmInstalled = false;
 
   String bundleCacheKey = "";
   File currentBundle;
@@ -75,11 +76,12 @@ public class HeliumVisualizationFactory {
 
     currentBundle = new File(workingDirectory, "vis.bundle.cache.js");
     gson = new Gson();
-    installNodeAndNpm();
-    configureLogger();
   }
 
-  private void installNodeAndNpm() {
+  void installNodeAndNpm() {
+    if (nodeAndNpmInstalled) {
+      return;
+    }
     try {
       NPMInstaller npmInstaller = 
frontEndPluginFactory.getNPMInstaller(getProxyConfig());
       npmInstaller.setNpmVersion(NPM_VERSION);
@@ -88,6 +90,8 @@ public class HeliumVisualizationFactory {
       NodeInstaller nodeInstaller = 
frontEndPluginFactory.getNodeInstaller(getProxyConfig());
       nodeInstaller.setNodeVersion(NODE_VERSION);
       nodeInstaller.install();
+      configureLogger();
+      nodeAndNpmInstalled = true;
     } catch (InstallationException e) {
       logger.error(e.getMessage(), e);
     }
@@ -104,6 +108,19 @@ public class HeliumVisualizationFactory {
 
   public synchronized File bundle(List<HeliumPackage> pkgs, boolean 
forceRefresh)
       throws IOException {
+    if (pkgs == null || pkgs.size() == 0) {
+      // when no package is selected, simply return an empty file instead of 
try bundle package
+      synchronized (this) {
+        currentBundle.getParentFile().mkdirs();
+        currentBundle.delete();
+        currentBundle.createNewFile();
+        bundleCacheKey = "";
+        return currentBundle;
+      }
+    }
+
+    installNodeAndNpm();
+
     // package.json
     URL pkgUrl = Resources.getResource("helium/package.json");
     String pkgJson = Resources.toString(pkgUrl, Charsets.UTF_8);
@@ -341,7 +358,7 @@ public class HeliumVisualizationFactory {
     }
   }
 
-  public synchronized void install(HeliumPackage pkg) throws 
TaskRunnerException {
+  synchronized void install(HeliumPackage pkg) throws TaskRunnerException {
     String commandForNpmInstallArtifact =
         String.format("install %s --fetch-retries=%d --fetch-retry-factor=%d " 
+
                         "--fetch-retry-mintimeout=%d", pkg.getArtifact(),
@@ -354,8 +371,8 @@ public class HeliumVisualizationFactory {
   }
 
   private void npmCommand(String args, Map<String, String> env) throws 
TaskRunnerException {
+    installNodeAndNpm();
     NpmRunner npm = frontEndPluginFactory.getNpmRunner(getProxyConfig(), 
DEFAULT_NPM_REGISTRY_URL);
-
     npm.execute(args, env);
   }
 

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/70ca8bdc/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumVisualizationFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumVisualizationFactoryTest.java
 
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumVisualizationFactoryTest.java
index e5a61ed..4f2ee9f 100644
--- 
a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumVisualizationFactoryTest.java
+++ 
b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumVisualizationFactoryTest.java
@@ -58,6 +58,11 @@ public class HeliumVisualizationFactoryTest {
 
   @Test
   public void testInstallNpm() throws InstallationException {
+    assertFalse(new File(tmpDir, "vis/node/npm").isFile());
+    assertFalse(new File(tmpDir, "vis/node/node").isFile());
+
+    hvf.installNodeAndNpm();
+
     assertTrue(new File(tmpDir, "vis/node/npm").isFile());
     assertTrue(new File(tmpDir, "vis/node/node").isFile());
   }

Reply via email to