mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
feat: Support FRONTEND_INTERPRETER type in backend
This commit is contained in:
parent
940a8b7d36
commit
c02d00a473
12 changed files with 171 additions and 123 deletions
|
|
@ -103,5 +103,9 @@
|
|||
<outputDirectory>/lib/node_modules/zeppelin-tabledata</outputDirectory>
|
||||
<directory>../zeppelin-web/src/app/tabledata</directory>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<outputDirectory>/lib/node_modules/zeppelin-frontend-interpreter</outputDirectory>
|
||||
<directory>../zeppelin-web/src/app/frontend-interpreter</directory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ public class HeliumPackage {
|
|||
INTERPRETER,
|
||||
NOTEBOOK_REPO,
|
||||
APPLICATION,
|
||||
VISUALIZATION
|
||||
VISUALIZATION,
|
||||
FRONTEND_INTERPRETER
|
||||
}
|
||||
|
||||
public HeliumPackage(Type type,
|
||||
|
|
@ -80,6 +81,11 @@ public class HeliumPackage {
|
|||
return type;
|
||||
}
|
||||
|
||||
public static boolean isBundleType(Type type) {
|
||||
return (type == Type.VISUALIZATION ||
|
||||
type == Type.FRONTEND_INTERPRETER);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,22 +107,22 @@ public class HeliumRestApi {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Path("visualizations/load")
|
||||
@Path("bundle/load")
|
||||
@Produces("text/javascript")
|
||||
public Response visualizationLoad(@QueryParam("refresh") String refresh) {
|
||||
public Response bundleLoad(@QueryParam("refresh") String refresh) {
|
||||
try {
|
||||
File bundle;
|
||||
if (refresh != null && refresh.equals("true")) {
|
||||
bundle = helium.recreateVisualizationBundle();
|
||||
bundle = helium.recreateBundle();
|
||||
} else {
|
||||
bundle = helium.getVisualizationFactory().getCurrentBundle();
|
||||
bundle = helium.getBundleFactory().getCurrentCacheBundle();
|
||||
}
|
||||
|
||||
if (bundle == null) {
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
String visBundle = FileUtils.readFileToString(bundle);
|
||||
return Response.ok(visBundle).build();
|
||||
String stringifiedBundle = FileUtils.readFileToString(bundle);
|
||||
return Response.ok(stringifiedBundle).build();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
|
|
@ -160,15 +160,15 @@ public class HeliumRestApi {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Path("visualizationOrder")
|
||||
public Response getVisualizationPackageOrder() {
|
||||
List<String> order = helium.getVisualizationPackageOrder();
|
||||
@Path("bundleOrder")
|
||||
public Response getBundlePackageOrder() {
|
||||
List<String> order = helium.getBundlePackageOrder();
|
||||
return new JsonResponse(Response.Status.OK, order).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("visualizationOrder")
|
||||
public Response setVisualizationPackageOrder(String orderedPackageNameList) {
|
||||
@Path("bundleOrder")
|
||||
public Response setBundlePackageOrder(String orderedPackageNameList) {
|
||||
List<String> orderedList = gson.fromJson(
|
||||
orderedPackageNameList, new TypeToken<List<String>>(){}.getType());
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
|
|||
import org.apache.zeppelin.dep.DependencyResolver;
|
||||
import org.apache.zeppelin.helium.Helium;
|
||||
import org.apache.zeppelin.helium.HeliumApplicationFactory;
|
||||
import org.apache.zeppelin.helium.HeliumVisualizationFactory;
|
||||
import org.apache.zeppelin.helium.HeliumBundleFactory;
|
||||
import org.apache.zeppelin.interpreter.InterpreterFactory;
|
||||
import org.apache.zeppelin.interpreter.InterpreterOutput;
|
||||
import org.apache.zeppelin.notebook.Notebook;
|
||||
|
|
@ -102,7 +102,7 @@ public class ZeppelinServer extends Application {
|
|||
InterpreterOutput.limit = conf.getInt(ConfVars.ZEPPELIN_INTERPRETER_OUTPUT_LIMIT);
|
||||
|
||||
HeliumApplicationFactory heliumApplicationFactory = new HeliumApplicationFactory();
|
||||
HeliumVisualizationFactory heliumVisualizationFactory;
|
||||
HeliumBundleFactory heliumBundleFactory;
|
||||
|
||||
if (isBinaryPackage(conf)) {
|
||||
/* In binary package, zeppelin-web/src/app/visualization and zeppelin-web/src/app/tabledata
|
||||
|
|
@ -110,28 +110,30 @@ public class ZeppelinServer extends Application {
|
|||
* Check zeppelin/zeppelin-distribution/src/assemble/distribution.xml to see how they're
|
||||
* packaged into binary package.
|
||||
*/
|
||||
heliumVisualizationFactory = new HeliumVisualizationFactory(
|
||||
heliumBundleFactory = new HeliumBundleFactory(
|
||||
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")));
|
||||
new File(conf.getRelativeDir("lib/node_modules/zeppelin-vis")),
|
||||
new File(conf.getRelativeDir("lib/node_modules/zeppelin-frontend-interpreter")));
|
||||
} else {
|
||||
heliumVisualizationFactory = new HeliumVisualizationFactory(
|
||||
heliumBundleFactory = new HeliumBundleFactory(
|
||||
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")));
|
||||
new File(conf.getRelativeDir("zeppelin-web/src/app/visualization")),
|
||||
new File(conf.getRelativeDir("zeppelin-web/src/app/frontend-interpreter")));
|
||||
}
|
||||
|
||||
this.helium = new Helium(
|
||||
conf.getHeliumConfPath(),
|
||||
conf.getHeliumRegistry(),
|
||||
new File(
|
||||
conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO), "helium_registry_cache"),
|
||||
heliumVisualizationFactory,
|
||||
new File(conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO),
|
||||
"helium_registry_cache"),
|
||||
heliumBundleFactory,
|
||||
heliumApplicationFactory);
|
||||
|
||||
// create visualization bundle
|
||||
// create bundle
|
||||
try {
|
||||
heliumVisualizationFactory.bundle(helium.getVisualizationPackagesToBundle());
|
||||
heliumBundleFactory.buildBundle(helium.getBundlePackagesToBundle());
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
"build": "grunt pre-webpack-dist && webpack && grunt post-webpack-dist",
|
||||
"predev": "grunt pre-webpack-dev",
|
||||
"dev:server": "webpack-dev-server --hot",
|
||||
"visdev:server": "HELIUM_VIS_DEV=true webpack-dev-server --hot",
|
||||
"dev:helium": "HELIUM_BUNDLE_DEV=true webpack-dev-server --hot",
|
||||
"dev:watch": "grunt watch-webpack-dev",
|
||||
"dev": "npm-run-all --parallel dev:server dev:watch",
|
||||
"visdev": "npm-run-all --parallel visdev:server dev:watch",
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ module.exports = function makeWebpackConfig () {
|
|||
// Reference: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
HELIUM_VIS_DEV: process.env.HELIUM_VIS_DEV
|
||||
HELIUM_BUNDLE_DEV: process.env.HELIUM_BUNDLE_DEV
|
||||
}
|
||||
})
|
||||
)
|
||||
|
|
|
|||
|
|
@ -45,20 +45,20 @@ public class Helium {
|
|||
private final File registryCacheDir;
|
||||
|
||||
private final Gson gson;
|
||||
private final HeliumVisualizationFactory visualizationFactory;
|
||||
private final HeliumBundleFactory bundleFactory;
|
||||
private final HeliumApplicationFactory applicationFactory;
|
||||
|
||||
public Helium(
|
||||
String heliumConfPath,
|
||||
String registryPaths,
|
||||
File registryCacheDir,
|
||||
HeliumVisualizationFactory visualizationFactory,
|
||||
HeliumBundleFactory bundleFactory,
|
||||
HeliumApplicationFactory applicationFactory)
|
||||
throws IOException {
|
||||
this.heliumConfPath = heliumConfPath;
|
||||
this.registryPaths = registryPaths;
|
||||
this.registryCacheDir = registryCacheDir;
|
||||
this.visualizationFactory = visualizationFactory;
|
||||
this.bundleFactory = bundleFactory;
|
||||
this.applicationFactory = applicationFactory;
|
||||
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
|
|
@ -95,8 +95,8 @@ public class Helium {
|
|||
return applicationFactory;
|
||||
}
|
||||
|
||||
public HeliumVisualizationFactory getVisualizationFactory() {
|
||||
return visualizationFactory;
|
||||
public HeliumBundleFactory getBundleFactory() {
|
||||
return bundleFactory;
|
||||
}
|
||||
|
||||
private synchronized HeliumConf loadConf(String path) throws IOException {
|
||||
|
|
@ -145,14 +145,14 @@ public class Helium {
|
|||
Map<String, List<HeliumPackageSearchResult>> all = getAllPackageInfo();
|
||||
|
||||
// clear visualization display order
|
||||
List<String> packageOrder = heliumConf.getVisualizationDisplayOrder();
|
||||
List<String> packageOrder = heliumConf.getBundleDisplayOrder();
|
||||
List<String> clearedOrder = new LinkedList<>();
|
||||
for (String pkgName : packageOrder) {
|
||||
if (all.containsKey(pkgName)) {
|
||||
clearedOrder.add(pkgName);
|
||||
}
|
||||
}
|
||||
heliumConf.setVisualizationDisplayOrder(clearedOrder);
|
||||
heliumConf.setBundleDisplayOrder(clearedOrder);
|
||||
|
||||
// clear enabled package
|
||||
Map<String, String> enabledPackages = heliumConf.getEnabledPackages();
|
||||
|
|
@ -215,8 +215,8 @@ public class Helium {
|
|||
return null;
|
||||
}
|
||||
|
||||
public File recreateVisualizationBundle() throws IOException {
|
||||
return visualizationFactory.bundle(getVisualizationPackagesToBundle(), true);
|
||||
public File recreateBundle() throws IOException {
|
||||
return bundleFactory.buildBundle(getBundlePackagesToBundle(), true);
|
||||
}
|
||||
|
||||
public void enable(String name, String artifact) throws IOException {
|
||||
|
|
@ -231,8 +231,8 @@ public class Helium {
|
|||
heliumConf.enablePackage(name, artifact);
|
||||
|
||||
// if package is visualization, rebuild bundle
|
||||
if (pkgInfo.getPkg().getType() == HeliumPackage.Type.VISUALIZATION) {
|
||||
visualizationFactory.bundle(getVisualizationPackagesToBundle());
|
||||
if (HeliumPackage.isBundleType(pkgInfo.getPkg().getType())) {
|
||||
bundleFactory.buildBundle(getBundlePackagesToBundle());
|
||||
}
|
||||
|
||||
save();
|
||||
|
|
@ -247,9 +247,9 @@ public class Helium {
|
|||
|
||||
heliumConf.disablePackage(name);
|
||||
|
||||
HeliumPackageSearchResult pkg = getPackageInfo(name, artifact);
|
||||
if (pkg == null || pkg.getPkg().getType() == HeliumPackage.Type.VISUALIZATION) {
|
||||
visualizationFactory.bundle(getVisualizationPackagesToBundle());
|
||||
HeliumPackageSearchResult pkgInfo = getPackageInfo(name, artifact);
|
||||
if (pkgInfo == null || HeliumPackage.isBundleType(pkgInfo.getPkg().getType())) {
|
||||
bundleFactory.buildBundle(getBundlePackagesToBundle());
|
||||
}
|
||||
|
||||
save();
|
||||
|
|
@ -299,15 +299,15 @@ public class Helium {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get enabled visualization packages
|
||||
* Get enabled buildBundle packages
|
||||
*
|
||||
* @return ordered list of enabled visualization package
|
||||
* @return ordered list of enabled buildBundle package
|
||||
*/
|
||||
public List<HeliumPackage> getVisualizationPackagesToBundle() {
|
||||
public List<HeliumPackage> getBundlePackagesToBundle() {
|
||||
Map<String, List<HeliumPackageSearchResult>> allPackages = getAllPackageInfo();
|
||||
List<String> visOrder = heliumConf.getVisualizationDisplayOrder();
|
||||
List<String> visOrder = heliumConf.getBundleDisplayOrder();
|
||||
|
||||
List<HeliumPackage> orderedVisualizationPackages = new LinkedList<>();
|
||||
List<HeliumPackage> orderedBundlePackages = new LinkedList<>();
|
||||
|
||||
// add enabled packages in visOrder
|
||||
for (String name : visOrder) {
|
||||
|
|
@ -316,8 +316,8 @@ public class Helium {
|
|||
continue;
|
||||
}
|
||||
for (HeliumPackageSearchResult pkgInfo : versions) {
|
||||
if (pkgInfo.getPkg().getType() == HeliumPackage.Type.VISUALIZATION && pkgInfo.isEnabled()) {
|
||||
orderedVisualizationPackages.add(pkgInfo.getPkg());
|
||||
if (canBundle(pkgInfo)) {
|
||||
orderedBundlePackages.add(pkgInfo.getPkg());
|
||||
allPackages.remove(name);
|
||||
break;
|
||||
}
|
||||
|
|
@ -325,25 +325,30 @@ public class Helium {
|
|||
}
|
||||
|
||||
// add enabled packages not in visOrder
|
||||
for (List<HeliumPackageSearchResult> pkgs : allPackages.values()) {
|
||||
for (HeliumPackageSearchResult pkg : pkgs) {
|
||||
if (pkg.getPkg().getType() == HeliumPackage.Type.VISUALIZATION && pkg.isEnabled()) {
|
||||
orderedVisualizationPackages.add(pkg.getPkg());
|
||||
for (List<HeliumPackageSearchResult> pkgInfos : allPackages.values()) {
|
||||
for (HeliumPackageSearchResult pkgInfo : pkgInfos) {
|
||||
if (canBundle(pkgInfo)) {
|
||||
orderedBundlePackages.add(pkgInfo.getPkg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return orderedVisualizationPackages;
|
||||
return orderedBundlePackages;
|
||||
}
|
||||
|
||||
public boolean canBundle(HeliumPackageSearchResult pkgInfo) {
|
||||
return (pkgInfo.isEnabled() &&
|
||||
HeliumPackage.isBundleType(pkgInfo.getPkg().getType()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled package list in order
|
||||
* @return
|
||||
*/
|
||||
public List<String> getVisualizationPackageOrder() {
|
||||
public List<String> getBundlePackageOrder() {
|
||||
List orderedPackageList = new LinkedList<>();
|
||||
List<HeliumPackage> packages = getVisualizationPackagesToBundle();
|
||||
List<HeliumPackage> packages = getBundlePackagesToBundle();
|
||||
|
||||
for (HeliumPackage pkg : packages) {
|
||||
orderedPackageList.add(pkg.getName());
|
||||
|
|
@ -354,10 +359,10 @@ public class Helium {
|
|||
|
||||
public void setVisualizationPackageOrder(List<String> orderedPackageList)
|
||||
throws IOException {
|
||||
heliumConf.setVisualizationDisplayOrder(orderedPackageList);
|
||||
heliumConf.setBundleDisplayOrder(orderedPackageList);
|
||||
|
||||
// if package is visualization, rebuild bundle
|
||||
visualizationFactory.bundle(getVisualizationPackagesToBundle());
|
||||
// if package is visualization, rebuild buildBundle
|
||||
bundleFactory.buildBundle(getBundlePackagesToBundle());
|
||||
|
||||
save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,40 +36,47 @@ import java.util.*;
|
|||
/**
|
||||
* Load helium visualization
|
||||
*/
|
||||
public class HeliumVisualizationFactory {
|
||||
Logger logger = LoggerFactory.getLogger(HeliumVisualizationFactory.class);
|
||||
public class HeliumBundleFactory {
|
||||
Logger logger = LoggerFactory.getLogger(HeliumBundleFactory.class);
|
||||
private final String NODE_VERSION = "v6.9.1";
|
||||
private final String NPM_VERSION = "3.10.8";
|
||||
private final String DEFAULT_NPM_REGISTRY_URL = "http://registry.npmjs.org/";
|
||||
public static final String HELIUM_LOCAL_REPO = "helium-bundle";
|
||||
public static final String HELIUM_BUNDLE_CACHE = "helium.bundle.cache.js";
|
||||
public static final String HELIUM_BUNDLE = "helium.bundle.js";
|
||||
public static final String HELIUM_BUNDLES_VAR = "heliumBundles";
|
||||
|
||||
private final FrontendPluginFactory frontEndPluginFactory;
|
||||
private final File workingDirectory;
|
||||
private File tabledataModulePath;
|
||||
private File visualizationModulePath;
|
||||
private File frontendInterpreterModulePath;
|
||||
private Gson gson;
|
||||
|
||||
String bundleCacheKey = "";
|
||||
File currentBundle;
|
||||
File currentCacheBundle;
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
public HeliumVisualizationFactory(
|
||||
public HeliumBundleFactory(
|
||||
File moduleDownloadPath,
|
||||
File tabledataModulePath,
|
||||
File visualizationModulePath) throws TaskRunnerException {
|
||||
File visualizationModulePath,
|
||||
File frontendInterpreterModulePath) throws TaskRunnerException {
|
||||
this(moduleDownloadPath);
|
||||
this.tabledataModulePath = tabledataModulePath;
|
||||
this.visualizationModulePath = visualizationModulePath;
|
||||
this.frontendInterpreterModulePath = frontendInterpreterModulePath;
|
||||
}
|
||||
|
||||
public HeliumVisualizationFactory(File moduleDownloadPath) throws TaskRunnerException {
|
||||
this.workingDirectory = new File(moduleDownloadPath, "vis");
|
||||
public HeliumBundleFactory(File moduleDownloadPath) throws TaskRunnerException {
|
||||
this.workingDirectory = new File(moduleDownloadPath, HELIUM_LOCAL_REPO);
|
||||
File installDirectory = workingDirectory;
|
||||
|
||||
frontEndPluginFactory = new FrontendPluginFactory(
|
||||
workingDirectory, installDirectory);
|
||||
|
||||
currentBundle = new File(workingDirectory, "vis.bundle.cache.js");
|
||||
currentCacheBundle = new File(workingDirectory, HELIUM_BUNDLE_CACHE);
|
||||
gson = new Gson();
|
||||
installNodeAndNpm();
|
||||
configureLogger();
|
||||
|
|
@ -94,11 +101,11 @@ public class HeliumVisualizationFactory {
|
|||
return new ProxyConfig(proxy);
|
||||
}
|
||||
|
||||
public File bundle(List<HeliumPackage> pkgs) throws IOException {
|
||||
return bundle(pkgs, false);
|
||||
public File buildBundle(List<HeliumPackage> pkgs) throws IOException {
|
||||
return buildBundle(pkgs, false);
|
||||
}
|
||||
|
||||
public synchronized File bundle(List<HeliumPackage> pkgs, boolean forceRefresh)
|
||||
public synchronized File buildBundle(List<HeliumPackage> pkgs, boolean forceRefresh)
|
||||
throws IOException {
|
||||
// package.json
|
||||
URL pkgUrl = Resources.getResource("helium/package.json");
|
||||
|
|
@ -144,10 +151,10 @@ public class HeliumVisualizationFactory {
|
|||
}
|
||||
pkgJson = pkgJson.replaceFirst("DEPENDENCIES", dependencies.toString());
|
||||
|
||||
// check if we can use previous bundle or not
|
||||
if (cacheKeyBuilder.toString().equals(bundleCacheKey)
|
||||
&& currentBundle.isFile() && !forceRefresh) {
|
||||
return currentBundle;
|
||||
// check if we can use previous buildBundle or not
|
||||
if (cacheKeyBuilder.toString().equals(bundleCacheKey) &&
|
||||
currentCacheBundle.isFile() && !forceRefresh) {
|
||||
return currentCacheBundle;
|
||||
}
|
||||
|
||||
// webpack.config.js
|
||||
|
|
@ -165,14 +172,15 @@ public class HeliumVisualizationFactory {
|
|||
continue;
|
||||
}
|
||||
|
||||
String className = "vis" + idx++;
|
||||
String className = "bundles" + idx++;
|
||||
loadJsImport.append(
|
||||
"import " + className + " from \"" + moduleNameVersion[0] + "\"\n");
|
||||
|
||||
loadJsRegister.append("visualizations.push({\n");
|
||||
loadJsRegister.append(HELIUM_BUNDLES_VAR + ".push({\n");
|
||||
loadJsRegister.append("id: \"" + moduleNameVersion[0] + "\",\n");
|
||||
loadJsRegister.append("name: \"" + pkg.getName() + "\",\n");
|
||||
loadJsRegister.append("icon: " + gson.toJson(pkg.getIcon()) + ",\n");
|
||||
loadJsRegister.append("type: \"" + pkg.getType() + "\",\n");
|
||||
loadJsRegister.append("class: " + className + "\n");
|
||||
loadJsRegister.append("})\n");
|
||||
}
|
||||
|
|
@ -182,6 +190,38 @@ public class HeliumVisualizationFactory {
|
|||
FileUtils.write(new File(workingDirectory, "load.js"),
|
||||
loadJsImport.append(loadJsRegister).toString());
|
||||
|
||||
copyFrameworkModuleToInstallPath(npmPackageCopyFilter);
|
||||
|
||||
out.reset();
|
||||
try {
|
||||
npmCommand("install");
|
||||
npmCommand("run bundle");
|
||||
} catch (TaskRunnerException e) {
|
||||
throw new IOException(new String(out.toByteArray()));
|
||||
}
|
||||
|
||||
File heliumBundle = new File(workingDirectory, HELIUM_BUNDLE);
|
||||
if (!heliumBundle.isFile()) {
|
||||
throw new IOException(
|
||||
"Can't create bundle: \n" + new String(out.toByteArray()));
|
||||
}
|
||||
|
||||
WebpackResult result = getWebpackResultFromOutput(new String(out.toByteArray()));
|
||||
if (result.errors.length > 0) {
|
||||
heliumBundle.delete();
|
||||
throw new IOException(result.errors[0]);
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
currentCacheBundle.delete();
|
||||
FileUtils.moveFile(heliumBundle, currentCacheBundle);
|
||||
bundleCacheKey = cacheKeyBuilder.toString();
|
||||
}
|
||||
return currentCacheBundle;
|
||||
}
|
||||
|
||||
private void copyFrameworkModuleToInstallPath(FileFilter npmPackageCopyFilter)
|
||||
throws IOException {
|
||||
// install tabledata module
|
||||
File tabledataModuleInstallPath = new File(workingDirectory,
|
||||
"node_modules/zeppelin-tabledata");
|
||||
|
|
@ -212,32 +252,19 @@ public class HeliumVisualizationFactory {
|
|||
FileUtils.copyDirectory(visualizationModulePath, visModuleInstallPath, npmPackageCopyFilter);
|
||||
}
|
||||
|
||||
out.reset();
|
||||
try {
|
||||
npmCommand("install");
|
||||
npmCommand("run bundle");
|
||||
} catch (TaskRunnerException e) {
|
||||
throw new IOException(new String(out.toByteArray()));
|
||||
}
|
||||
// install frontend-interpreter module
|
||||
File frontendInterpreterModuleInstallPath = new File(workingDirectory,
|
||||
"node_modules/zeppelin-frontend-interpreter");
|
||||
if (frontendInterpreterModulePath != null) {
|
||||
if (frontendInterpreterModuleInstallPath.exists()) {
|
||||
FileUtils.deleteDirectory(frontendInterpreterModuleInstallPath);
|
||||
}
|
||||
|
||||
File visBundleJs = new File(workingDirectory, "vis.bundle.js");
|
||||
if (!visBundleJs.isFile()) {
|
||||
throw new IOException(
|
||||
"Can't create visualization bundle : \n" + new String(out.toByteArray()));
|
||||
FileUtils.copyDirectory(
|
||||
frontendInterpreterModulePath,
|
||||
frontendInterpreterModuleInstallPath,
|
||||
npmPackageCopyFilter);
|
||||
}
|
||||
|
||||
WebpackResult result = getWebpackResultFromOutput(new String(out.toByteArray()));
|
||||
if (result.errors.length > 0) {
|
||||
visBundleJs.delete();
|
||||
throw new IOException(result.errors[0]);
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
currentBundle.delete();
|
||||
FileUtils.moveFile(visBundleJs, currentBundle);
|
||||
bundleCacheKey = cacheKeyBuilder.toString();
|
||||
}
|
||||
return currentBundle;
|
||||
}
|
||||
|
||||
private WebpackResult getWebpackResultFromOutput(String output) {
|
||||
|
|
@ -277,10 +304,10 @@ public class HeliumVisualizationFactory {
|
|||
}
|
||||
}
|
||||
|
||||
public File getCurrentBundle() {
|
||||
public File getCurrentCacheBundle() {
|
||||
synchronized (this) {
|
||||
if (currentBundle.isFile()) {
|
||||
return currentBundle;
|
||||
if (currentCacheBundle.isFile()) {
|
||||
return currentCacheBundle;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ public class HeliumConf {
|
|||
Map<String, String> enabled = Collections.synchronizedMap(new HashMap<String, String>());
|
||||
|
||||
// enabled visualization package display order
|
||||
List<String> visualizationDisplayOrder = new LinkedList<>();
|
||||
List<String> bundleDisplayOrder = new LinkedList<>();
|
||||
|
||||
public Map<String, String> getEnabledPackages() {
|
||||
return new HashMap<>(enabled);
|
||||
|
|
@ -48,15 +48,15 @@ public class HeliumConf {
|
|||
enabled.remove(name);
|
||||
}
|
||||
|
||||
public List<String> getVisualizationDisplayOrder() {
|
||||
if (visualizationDisplayOrder == null) {
|
||||
public List<String> getBundleDisplayOrder() {
|
||||
if (bundleDisplayOrder == null) {
|
||||
return new LinkedList<String>();
|
||||
} else {
|
||||
return visualizationDisplayOrder;
|
||||
return bundleDisplayOrder;
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisualizationDisplayOrder(List<String> orderedPackageList) {
|
||||
visualizationDisplayOrder = orderedPackageList;
|
||||
public void setBundleDisplayOrder(List<String> orderedPackageList) {
|
||||
bundleDisplayOrder = orderedPackageList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "zeppelin-vis-bundle",
|
||||
"name": "zeppelin-helium-bundle",
|
||||
"main": "load",
|
||||
"scripts": {
|
||||
"bundle": "node/node node_modules/webpack/bin/webpack.js --display-error-details --json"
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ module.exports = {
|
|||
entry: ['./'],
|
||||
output: {
|
||||
path: './',
|
||||
filename: 'vis.bundle.js',
|
||||
filename: 'helium.bundle.js',
|
||||
},
|
||||
resolve: {
|
||||
root: __dirname + "/node_modules"
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ import java.util.List;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class HeliumVisualizationFactoryTest {
|
||||
public class HeliumBundleFactoryTest {
|
||||
private File tmpDir;
|
||||
private HeliumVisualizationFactory hvf;
|
||||
private HeliumBundleFactory hbf;
|
||||
|
||||
@Before
|
||||
public void setUp() throws InstallationException, TaskRunnerException {
|
||||
|
|
@ -46,9 +46,10 @@ public class HeliumVisualizationFactoryTest {
|
|||
String resDir = new File(res.getFile()).getParent();
|
||||
File moduleDir = new File(resDir + "/../../../../zeppelin-web/src/app/");
|
||||
|
||||
hvf = new HeliumVisualizationFactory(tmpDir,
|
||||
hbf = new HeliumBundleFactory(tmpDir,
|
||||
new File(moduleDir, "tabledata"),
|
||||
new File(moduleDir, "visualization"));
|
||||
new File(moduleDir, "visualization"),
|
||||
new File(moduleDir, "frontend-interpreter"));
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
@ -58,8 +59,10 @@ public class HeliumVisualizationFactoryTest {
|
|||
|
||||
@Test
|
||||
public void testInstallNpm() throws InstallationException {
|
||||
assertTrue(new File(tmpDir, "vis/node/npm").isFile());
|
||||
assertTrue(new File(tmpDir, "vis/node/node").isFile());
|
||||
assertTrue(new File(tmpDir,
|
||||
HeliumBundleFactory.HELIUM_LOCAL_REPO + "/node/npm").isFile());
|
||||
assertTrue(new File(tmpDir,
|
||||
HeliumBundleFactory.HELIUM_LOCAL_REPO + "/node/node").isFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -74,8 +77,9 @@ public class HeliumVisualizationFactoryTest {
|
|||
"license",
|
||||
"icon"
|
||||
);
|
||||
hvf.install(pkg);
|
||||
assertTrue(new File(tmpDir, "vis/node_modules/lodash").isDirectory());
|
||||
hbf.install(pkg);
|
||||
assertTrue(new File(tmpDir,
|
||||
HeliumBundleFactory.HELIUM_LOCAL_REPO + "/node_modules/lodash").isDirectory());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -92,12 +96,12 @@ public class HeliumVisualizationFactoryTest {
|
|||
);
|
||||
List<HeliumPackage> pkgs = new LinkedList<>();
|
||||
pkgs.add(pkg);
|
||||
File bundle = hvf.bundle(pkgs);
|
||||
File bundle = hbf.buildBundle(pkgs);
|
||||
assertTrue(bundle.isFile());
|
||||
long lastModified = bundle.lastModified();
|
||||
|
||||
// bundle again and check if it served from cache
|
||||
bundle = hvf.bundle(pkgs);
|
||||
// buildBundle again and check if it served from cache
|
||||
bundle = hbf.buildBundle(pkgs);
|
||||
assertEquals(lastModified, bundle.lastModified());
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +124,7 @@ public class HeliumVisualizationFactoryTest {
|
|||
);
|
||||
List<HeliumPackage> pkgs = new LinkedList<>();
|
||||
pkgs.add(pkg);
|
||||
File bundle = hvf.bundle(pkgs);
|
||||
File bundle = hbf.buildBundle(pkgs);
|
||||
assertTrue(bundle.isFile());
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +148,7 @@ public class HeliumVisualizationFactoryTest {
|
|||
pkgs.add(pkg);
|
||||
File bundle = null;
|
||||
try {
|
||||
bundle = hvf.bundle(pkgs);
|
||||
bundle = hbf.buildBundle(pkgs);
|
||||
// should throw exception
|
||||
assertTrue(false);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -185,8 +189,8 @@ public class HeliumVisualizationFactoryTest {
|
|||
List<HeliumPackage> pkgsV2 = new LinkedList<>();
|
||||
pkgsV2.add(pkgV2);
|
||||
|
||||
File bundle1 = hvf.bundle(pkgsV1);
|
||||
File bundle2 = hvf.bundle(pkgsV2);
|
||||
File bundle1 = hbf.buildBundle(pkgsV1);
|
||||
File bundle2 = hbf.buildBundle(pkgsV2);
|
||||
|
||||
assertNotSame(bundle1.lastModified(), bundle2.lastModified());
|
||||
}
|
||||
Loading…
Reference in a new issue