fix: Add nodeInstallationDir

This commit is contained in:
1ambda 2017-03-31 22:50:17 +09:00
parent 11ef0ae8e6
commit 736acee02a
3 changed files with 23 additions and 30 deletions

View file

@ -115,6 +115,7 @@ public class ZeppelinServer extends Application {
*/
heliumBundleFactory = new HeliumBundleFactory(
conf,
null,
new File(conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO)),
new File(conf.getRelativeDir("lib/node_modules/zeppelin-tabledata")),
new File(conf.getRelativeDir("lib/node_modules/zeppelin-vis")),
@ -122,6 +123,7 @@ public class ZeppelinServer extends Application {
} else {
heliumBundleFactory = new HeliumBundleFactory(
conf,
null,
new File(conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO)),
new File(conf.getRelativeDir("zeppelin-web/src/app/tabledata")),
new File(conf.getRelativeDir("zeppelin-web/src/app/visualization")),

View file

@ -64,6 +64,7 @@ public class HeliumBundleFactory {
private final int FETCH_RETRY_MIN_TIMEOUT = 5000; // Milliseconds
private final FrontendPluginFactory frontEndPluginFactory;
private final File nodeInstallationDirectory;
private final File heliumLocalRepoDirectory;
private final File heliumBundleDirectory;
private final File heliumLocalModuleDirectory;
@ -75,18 +76,16 @@ public class HeliumBundleFactory {
private Gson gson;
private boolean nodeAndNpmInstalled = false;
String bundleCacheKey = "";
File currentCacheBundle;
ByteArrayOutputStream out = new ByteArrayOutputStream();
public HeliumBundleFactory(
ZeppelinConfiguration conf,
File nodeInstallationDir,
File moduleDownloadPath,
File tabledataModulePath,
File visualizationModulePath,
File spellModulePath) throws TaskRunnerException {
this(conf, moduleDownloadPath);
this(conf, nodeInstallationDir, moduleDownloadPath);
this.tabledataModulePath = tabledataModulePath;
this.visualizationModulePath = visualizationModulePath;
this.spellModulePath = spellModulePath;
@ -94,20 +93,21 @@ public class HeliumBundleFactory {
public HeliumBundleFactory(
ZeppelinConfiguration conf,
File nodeInstallationDir,
File moduleDownloadPath) throws TaskRunnerException {
this.heliumLocalRepoDirectory = new File(moduleDownloadPath, HELIUM_LOCAL_REPO);
this.heliumBundleDirectory = new File(heliumLocalRepoDirectory, HELIUM_BUNDLES_DIR);
this.heliumLocalModuleDirectory = new File(heliumLocalRepoDirectory, HELIUM_LOCAL_MODULE_DIR);
this.conf = conf;
this.defaultNpmRegistryUrl = conf.getHeliumNpmRegistry();
File installDirectory = heliumLocalRepoDirectory;
nodeInstallationDirectory = (nodeInstallationDir == null) ?
heliumLocalRepoDirectory : nodeInstallationDir;
frontEndPluginFactory = new FrontendPluginFactory(
heliumLocalRepoDirectory, installDirectory);
heliumLocalRepoDirectory, nodeInstallationDirectory);
gson = new Gson();
// TODO(1ambda): remove
currentCacheBundle = new File(heliumLocalRepoDirectory, HELIUM_BUNDLE_CACHE);
}
void installNodeAndNpm() {
@ -357,7 +357,7 @@ public class HeliumBundleFactory {
// 0. prepare directory
FrontendPluginFactory fpf = new FrontendPluginFactory(
bundleDir, heliumLocalRepoDirectory);
bundleDir, nodeInstallationDirectory);
// resources: webpack.js, package.json
String templateWebpackConfig = Resources.toString(
@ -507,16 +507,6 @@ public class HeliumBundleFactory {
}
}
public File getCurrentCacheBundle() {
synchronized (this) {
if (currentCacheBundle.isFile()) {
return currentCacheBundle;
} else {
return null;
}
}
}
private boolean isLocalPackage(HeliumPackage pkg) {
return (pkg.getArtifact().startsWith(".") || pkg.getArtifact().startsWith("/"));
}

View file

@ -22,6 +22,7 @@ import com.google.common.io.Resources;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
@ -38,6 +39,13 @@ public class HeliumBundleFactoryTest {
private File tmpDir;
private ZeppelinConfiguration conf;
private HeliumBundleFactory hbf;
static File nodeInstallationDir = new File(
System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_nodeCache");
@BeforeClass
static public void beforeAll() throws IOException {
FileUtils.deleteDirectory(nodeInstallationDir);
}
@Before
public void setUp() throws InstallationException, TaskRunnerException, IOException {
@ -52,6 +60,7 @@ public class HeliumBundleFactoryTest {
conf = new ZeppelinConfiguration();
hbf = new HeliumBundleFactory(conf,
nodeInstallationDir,
tmpDir,
new File(moduleDir, "tabledata"),
new File(moduleDir, "visualization"),
@ -67,17 +76,9 @@ 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,
HeliumBundleFactory.HELIUM_LOCAL_REPO + "/node/node").isFile());
assertTrue(new File(nodeInstallationDir, "/node/npm").isFile());
assertTrue(new File(nodeInstallationDir, "/node/node").isFile());
assertTrue(new File(nodeInstallationDir, "/node/yarn/dist/bin/yarn").isFile());
}
@Test