Repository: zeppelin Updated Branches: refs/heads/master dcee15afc -> e669895d9
[ZEPPELIN-2260] Skip node,npm install and bundle when no helium package is selected ### What is this PR for? 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 <m...@apache.org> Closes #2137 from Leemoonsoo/ZEPPELIN-2260 and squashes the following commits: 520ad3f [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/e669895d Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/e669895d Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/e669895d Branch: refs/heads/master Commit: e669895d9d3d9e02ea97151f45fd4bd745cfcc80 Parents: dcee15a Author: Lee moon soo <m...@apache.org> Authored: Tue Mar 14 17:48:40 2017 -0700 Committer: Lee moon soo <m...@apache.org> Committed: Fri Mar 17 00:23:37 2017 -0700 ---------------------------------------------------------------------- .../zeppelin/helium/HeliumBundleFactory.java | 28 ++++++++++++++++---- .../helium/HeliumBundleFactoryTest.java | 7 +++++ 2 files changed, 30 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/e669895d/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumBundleFactory.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumBundleFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumBundleFactory.java index de03195..e04f9ac 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumBundleFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumBundleFactory.java @@ -56,6 +56,7 @@ public class HeliumBundleFactory { private File visualizationModulePath; private File spellModulePath; private Gson gson; + private boolean nodeAndNpmInstalled = false; String bundleCacheKey = ""; File currentCacheBundle; @@ -82,11 +83,12 @@ public class HeliumBundleFactory { currentCacheBundle = new File(workingDirectory, HELIUM_BUNDLE_CACHE); gson = new Gson(); - installNodeAndNpm(); - configureLogger(); } - private void installNodeAndNpm() { + void installNodeAndNpm() { + if (nodeAndNpmInstalled) { + return; + } try { NPMInstaller npmInstaller = frontEndPluginFactory.getNPMInstaller(getProxyConfig()); npmInstaller.setNpmVersion(NPM_VERSION); @@ -95,6 +97,8 @@ public class HeliumBundleFactory { NodeInstaller nodeInstaller = frontEndPluginFactory.getNodeInstaller(getProxyConfig()); nodeInstaller.setNodeVersion(NODE_VERSION); nodeInstaller.install(); + configureLogger(); + nodeAndNpmInstalled = true; } catch (InstallationException e) { logger.error(e.getMessage(), e); } @@ -111,6 +115,20 @@ public class HeliumBundleFactory { public synchronized File buildBundle(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) { + currentCacheBundle.getParentFile().mkdirs(); + currentCacheBundle.delete(); + currentCacheBundle.createNewFile(); + bundleCacheKey = ""; + return currentCacheBundle; + } + } + + installNodeAndNpm(); + // package.json URL pkgUrl = Resources.getResource("helium/package.json"); String pkgJson = Resources.toString(pkgUrl, Charsets.UTF_8); @@ -380,7 +398,7 @@ public class HeliumBundleFactory { } } - 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(), @@ -393,8 +411,8 @@ public class HeliumBundleFactory { } 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/e669895d/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumBundleFactoryTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumBundleFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumBundleFactoryTest.java index 503cc07..28cba4c 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumBundleFactoryTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumBundleFactoryTest.java @@ -59,6 +59,13 @@ public class HeliumBundleFactoryTest { @Test public void testInstallNpm() throws InstallationException { + assertFalse(new File(tmpDir, + HeliumBundleFactory.HELIUM_LOCAL_REPO + "/node/npm").isFile()); + assertFalse(new File(tmpDir, + HeliumBundleFactory.HELIUM_LOCAL_REPO + "/node/node").isFile()); + + hbf.installNodeAndNpm(); + assertTrue(new File(tmpDir, HeliumBundleFactory.HELIUM_LOCAL_REPO + "/node/npm").isFile()); assertTrue(new File(tmpDir,