mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
connect visualization factory with restapi
This commit is contained in:
parent
4b21252def
commit
a5a935bb2a
11 changed files with 350 additions and 68 deletions
|
|
@ -17,12 +17,11 @@
|
|||
|
||||
package org.apache.zeppelin.rest;
|
||||
|
||||
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.zeppelin.helium.Helium;
|
||||
import org.apache.zeppelin.helium.HeliumApplicationFactory;
|
||||
import org.apache.zeppelin.helium.HeliumPackage;
|
||||
import org.apache.zeppelin.helium.HeliumVisualizationFactory;
|
||||
import org.apache.zeppelin.notebook.Note;
|
||||
import org.apache.zeppelin.notebook.Notebook;
|
||||
import org.apache.zeppelin.notebook.Paragraph;
|
||||
|
|
@ -34,6 +33,7 @@ import javax.ws.rs.*;
|
|||
import javax.ws.rs.core.Response;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Helium Rest Api
|
||||
|
|
@ -44,21 +44,14 @@ public class HeliumRestApi {
|
|||
Logger logger = LoggerFactory.getLogger(HeliumRestApi.class);
|
||||
|
||||
private Helium helium;
|
||||
private HeliumApplicationFactory applicationFactory;
|
||||
private HeliumVisualizationFactory visualizationFactory;
|
||||
private Notebook notebook;
|
||||
private Gson gson = new Gson();
|
||||
|
||||
public HeliumRestApi() {
|
||||
}
|
||||
|
||||
public HeliumRestApi(Helium helium,
|
||||
HeliumApplicationFactory heliumApplicationFactory,
|
||||
HeliumVisualizationFactory heliumVisualizationFactory,
|
||||
Notebook notebook) {
|
||||
public HeliumRestApi(Helium helium, Notebook notebook) {
|
||||
this.helium = helium;
|
||||
this.applicationFactory = heliumApplicationFactory;
|
||||
this.visualizationFactory = heliumVisualizationFactory;
|
||||
this.notebook = notebook;
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +101,7 @@ public class HeliumRestApi {
|
|||
}
|
||||
HeliumPackage pkg = gson.fromJson(heliumPackage, HeliumPackage.class);
|
||||
|
||||
String appId = applicationFactory.loadAndRun(pkg, paragraph);
|
||||
String appId = helium.getApplicationFactory().loadAndRun(pkg, paragraph);
|
||||
return new JsonResponse(Response.Status.OK, "", appId).build();
|
||||
}
|
||||
|
||||
|
|
@ -116,12 +109,54 @@ public class HeliumRestApi {
|
|||
@Path("visualizations/load")
|
||||
@Produces("text/javascript")
|
||||
public Response visualizationLoad() {
|
||||
List<HeliumPackage> packages = helium.getVisualizationPackagesToBundle();
|
||||
|
||||
try {
|
||||
String visBundle = FileUtils.readFileToString(new File("/tmp/npm/vis.bundle.js"));
|
||||
return Response.ok(visBundle).build();
|
||||
File bundle = helium.getVisualizationFactory().getCurrentBundle();
|
||||
if (bundle == null) {
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
String visBundle = FileUtils.readFileToString(bundle);
|
||||
return Response.ok(visBundle).build();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
|
||||
// returning error will prevent zeppelin front-end render any notebook.
|
||||
// visualization load fail doesn't need to block notebook rendering work.
|
||||
// so it's better return ok instead of any error.
|
||||
return Response.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("enable/{packageName}")
|
||||
public Response enablePackage(@PathParam("packageName") String packageName,
|
||||
String artifact) {
|
||||
try {
|
||||
helium.enable(packageName, artifact);
|
||||
return new JsonResponse(Response.Status.OK).build();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return Response.serverError().build();
|
||||
return new JsonResponse(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
} catch (TaskRunnerException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return new JsonResponse(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("disable/{packageName}")
|
||||
public Response enablePackage(@PathParam("packageName") String packageName) {
|
||||
try {
|
||||
helium.disable(packageName);
|
||||
return new JsonResponse(Response.Status.OK).build();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return new JsonResponse(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
} catch (TaskRunnerException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return new JsonResponse(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,8 +83,6 @@ public class ZeppelinServer extends Application {
|
|||
public static Server jettyWebServer;
|
||||
public static NotebookServer notebookWsServer;
|
||||
public static Helium helium;
|
||||
public static HeliumApplicationFactory heliumApplicationFactory;
|
||||
public static HeliumVisualizationFactory heliumVisualizationFactory;
|
||||
|
||||
private SchedulerFactory schedulerFactory;
|
||||
private InterpreterFactory replFactory;
|
||||
|
|
@ -100,11 +98,16 @@ public class ZeppelinServer extends Application {
|
|||
this.depResolver = new DependencyResolver(
|
||||
conf.getString(ConfVars.ZEPPELIN_INTERPRETER_LOCALREPO));
|
||||
|
||||
this.helium = new Helium(conf.getHeliumConfPath(), conf.getHeliumDefaultLocalRegistryPath());
|
||||
this.heliumApplicationFactory = new HeliumApplicationFactory();
|
||||
this.heliumVisualizationFactory = new HeliumVisualizationFactory(
|
||||
HeliumApplicationFactory heliumApplicationFactory = new HeliumApplicationFactory();
|
||||
HeliumVisualizationFactory heliumVisualizationFactory = new HeliumVisualizationFactory(
|
||||
new File(conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO)));
|
||||
|
||||
this.helium = new Helium(
|
||||
conf.getHeliumConfPath(),
|
||||
conf.getHeliumDefaultLocalRegistryPath(),
|
||||
heliumVisualizationFactory,
|
||||
heliumApplicationFactory);
|
||||
|
||||
|
||||
this.schedulerFactory = new SchedulerFactory();
|
||||
this.replFactory = new InterpreterFactory(conf, notebookWsServer,
|
||||
|
|
@ -338,8 +341,7 @@ public class ZeppelinServer extends Application {
|
|||
NotebookRepoRestApi notebookRepoApi = new NotebookRepoRestApi(notebookRepo, notebookWsServer);
|
||||
singletons.add(notebookRepoApi);
|
||||
|
||||
HeliumRestApi heliumApi = new HeliumRestApi(helium, heliumApplicationFactory,
|
||||
heliumVisualizationFactory, notebook);
|
||||
HeliumRestApi heliumApi = new HeliumRestApi(helium, notebook);
|
||||
singletons.add(heliumApi);
|
||||
|
||||
InterpreterRestApi interpreterApi = new InterpreterRestApi(replFactory);
|
||||
|
|
|
|||
|
|
@ -19,13 +19,33 @@
|
|||
HeliumCtrl.$inject = ['$scope', '$rootScope', '$http', 'baseUrlSrv', 'ngToast'];
|
||||
|
||||
function HeliumCtrl($scope, $rootScope, $http, baseUrlSrv, ngToast) {
|
||||
$scope.packageInfos = [];
|
||||
$scope.packageInfos = {};
|
||||
$scope.defaultVersions = {};
|
||||
|
||||
var buildDefaultVersionListToDisplay = function(packageInfos) {
|
||||
var defaultVersions = {};
|
||||
// show enabled version if any version of package is enabled
|
||||
for (var name in packageInfos) {
|
||||
var pkgs = packageInfos[name];
|
||||
for (var pkg in pkgs) {
|
||||
if (pkg.enabled) {
|
||||
defaultVersions[name] = pkg;
|
||||
}
|
||||
}
|
||||
|
||||
// show first available version if package is not enabled
|
||||
if (!defaultVersions[name]) {
|
||||
defaultVersions[name] = pkgs[0];
|
||||
}
|
||||
}
|
||||
$scope.defaultVersions = defaultVersions;
|
||||
};
|
||||
|
||||
var getAllPackageInfo = function() {
|
||||
$http.get(baseUrlSrv.getRestApiBase() + '/helium/all').
|
||||
success(function(data, status) {
|
||||
console.log('Packages %o', data);
|
||||
$scope.packageInfos = data.body;
|
||||
buildDefaultVersionListToDisplay($scope.packageInfos);
|
||||
}).
|
||||
error(function(data, status) {
|
||||
console.log('Can not load package info %o %o', status, data);
|
||||
|
|
@ -37,5 +57,25 @@
|
|||
};
|
||||
|
||||
init();
|
||||
|
||||
$scope.enable = function(name, artifact) {
|
||||
$http.post(baseUrlSrv.getRestApiBase() + '/helium/enable/' + name, artifact).
|
||||
success(function(data, status) {
|
||||
getAllPackageInfo();
|
||||
}).
|
||||
error(function(data, status) {
|
||||
console.log('Failed to enable package %o %o', name, artifact);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.disable = function(name) {
|
||||
$http.post(baseUrlSrv.getRestApiBase() + '/helium/disable/' + name).
|
||||
success(function(data, status) {
|
||||
getAllPackageInfo();
|
||||
}).
|
||||
error(function(data, status) {
|
||||
console.log('Failed to disable package %o', name);
|
||||
});
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -25,21 +25,23 @@ limitations under the License.
|
|||
|
||||
<div class="box width-full">
|
||||
<div class="row"
|
||||
ng-repeat="packageInfo in packageInfos"
|
||||
ng-repeat="(pkgName, pkgInfo) in defaultVersions"
|
||||
style="margin-bottom:20px">
|
||||
<div class="col-md-12">
|
||||
<div style="height:25px">
|
||||
<div style="float:left;width:20px;height:20px"
|
||||
ng-bind-html=packageInfo.pkg.icon></div>
|
||||
<b style="float:left">{{packageInfo.pkg.name}}</b>
|
||||
<div ng-show="!packageInfo.enabled"
|
||||
ng-bind-html=pkgInfo.pkg.icon></div>
|
||||
<b style="float:left">{{pkgName}}</b>
|
||||
<div ng-show="!pkgInfo.enabled"
|
||||
ng-click="enable(pkgName, pkgInfo.pkg.artifact)"
|
||||
class="btn btn-success btn-xs"
|
||||
style="float:right">Enable</div>
|
||||
<div ng-show="packageInfo.enabled"
|
||||
<div ng-show="pkgInfo.enabled"
|
||||
ng-click="disable(pkgName)"
|
||||
class="btn btn-info btn-xs"
|
||||
style="float:right">Disable</div>
|
||||
</div>
|
||||
{{packageInfo.pkg.description}}
|
||||
{{pkgInfo.pkg.description}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import './app/notebook/paragraph/paragraph.controller.js';
|
|||
import './app/notebook/paragraph/result/result.controller.js';
|
||||
import './app/search/result-list.controller.js';
|
||||
import './app/notebookRepos/notebookRepos.controller.js';
|
||||
import './app/helium/helium.controller.js';
|
||||
import './components/arrayOrderingSrv/arrayOrdering.service.js';
|
||||
import './components/clipboard/clipboard.controller.js';
|
||||
import './components/navbar/navbar.controller.js';
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.zeppelin.helium;
|
||||
|
||||
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
|
@ -32,10 +33,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Manages helium packages
|
||||
|
|
@ -48,10 +46,19 @@ public class Helium {
|
|||
private final String heliumConfPath;
|
||||
private final String defaultLocalRegistryPath;
|
||||
private final Gson gson;
|
||||
private final HeliumVisualizationFactory visualizationFactory;
|
||||
private final HeliumApplicationFactory applicationFactory;
|
||||
|
||||
public Helium(String heliumConfPath, String defaultLocalRegistryPath) throws IOException {
|
||||
public Helium(
|
||||
String heliumConfPath,
|
||||
String defaultLocalRegistryPath,
|
||||
HeliumVisualizationFactory visualizationFactory,
|
||||
HeliumApplicationFactory applicationFactory)
|
||||
throws IOException, TaskRunnerException {
|
||||
this.heliumConfPath = heliumConfPath;
|
||||
this.defaultLocalRegistryPath = defaultLocalRegistryPath;
|
||||
this.visualizationFactory = visualizationFactory;
|
||||
this.applicationFactory = applicationFactory;
|
||||
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.setPrettyPrinting();
|
||||
|
|
@ -60,6 +67,7 @@ public class Helium {
|
|||
gson = builder.create();
|
||||
|
||||
heliumConf = loadConf(heliumConfPath);
|
||||
visualizationFactory.bundle(getVisualizationPackagesToBundle());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,6 +91,14 @@ public class Helium {
|
|||
}
|
||||
}
|
||||
|
||||
public HeliumApplicationFactory getApplicationFactory() {
|
||||
return applicationFactory;
|
||||
}
|
||||
|
||||
public HeliumVisualizationFactory getVisualizationFactory() {
|
||||
return visualizationFactory;
|
||||
}
|
||||
|
||||
private synchronized HeliumConf loadConf(String path) throws IOException {
|
||||
File heliumConfFile = new File(path);
|
||||
if (!heliumConfFile.isFile()) {
|
||||
|
|
@ -116,30 +132,92 @@ public class Helium {
|
|||
FileUtils.writeStringToFile(heliumConfFile, jsonString);
|
||||
}
|
||||
|
||||
public List<HeliumPackageSearchResult> getAllPackageInfo() {
|
||||
List<HeliumPackageSearchResult> list = new LinkedList<>();
|
||||
public Map<String, List<HeliumPackageSearchResult>> getAllPackageInfo() {
|
||||
Map<String, String> enabledPackageInfo = heliumConf.getEnabledPackages();
|
||||
|
||||
Map<String, List<HeliumPackageSearchResult>> map = new HashMap<>();
|
||||
synchronized (registry) {
|
||||
for (HeliumRegistry r : registry) {
|
||||
try {
|
||||
for (HeliumPackage pkg : r.getAll()) {
|
||||
list.add(new HeliumPackageSearchResult(r.name(), pkg));
|
||||
String name = pkg.getName();
|
||||
String artifact = enabledPackageInfo.get(name);
|
||||
boolean enabled = (artifact != null && artifact.equals(pkg.getArtifact()));
|
||||
|
||||
if (!map.containsKey(name)) {
|
||||
map.put(name, new LinkedList<HeliumPackageSearchResult>());
|
||||
}
|
||||
map.get(name).add(new HeliumPackageSearchResult(r.name(), pkg, enabled));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
||||
// sort version (artifact)
|
||||
for (String name : map.keySet()) {
|
||||
List<HeliumPackageSearchResult> packages = map.get(name);
|
||||
Collections.sort(packages, new Comparator<HeliumPackageSearchResult>() {
|
||||
@Override
|
||||
public int compare(HeliumPackageSearchResult o1, HeliumPackageSearchResult o2) {
|
||||
return o1.getPkg().getArtifact().compareTo(o2.getPkg().getArtifact());
|
||||
}
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public void enable(HeliumPackage pkg) {
|
||||
public HeliumPackageSearchResult getPackageInfo(String name, String artifact) {
|
||||
Map<String, List<HeliumPackageSearchResult>> infos = getAllPackageInfo();
|
||||
List<HeliumPackageSearchResult> packages = infos.get(name);
|
||||
if (artifact == null) {
|
||||
return packages.get(0);
|
||||
} else {
|
||||
for (HeliumPackageSearchResult pkg : packages) {
|
||||
if (pkg.getPkg().getArtifact().equals(artifact)) {
|
||||
return pkg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void disable(HeliumPackage pkg) {
|
||||
public void enable(String name, String artifact) throws IOException, TaskRunnerException {
|
||||
HeliumPackageSearchResult pkgInfo = getPackageInfo(name, artifact);
|
||||
|
||||
// no package found.
|
||||
if (pkgInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// enable package
|
||||
heliumConf.enablePackage(name, artifact);
|
||||
|
||||
// if package is visualization, rebuild bundle
|
||||
if (pkgInfo.getPkg().getType() == HeliumPackage.Type.VISUALIZATION) {
|
||||
visualizationFactory.bundle(getVisualizationPackagesToBundle());
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
public void disable(String name) throws IOException, TaskRunnerException {
|
||||
String artifact = heliumConf.getEnabledPackages().get(name);
|
||||
|
||||
if (artifact == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
heliumConf.disablePackage(name);
|
||||
HeliumPackageSearchResult pkg = getPackageInfo(name, artifact);
|
||||
if (pkg == null || pkg.getPkg().getType() == HeliumPackage.Type.VISUALIZATION) {
|
||||
visualizationFactory.bundle(getVisualizationPackagesToBundle());
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
public HeliumPackageSuggestion suggestApp(Paragraph paragraph) {
|
||||
HeliumPackageSuggestion suggestion = new HeliumPackageSuggestion();
|
||||
|
|
@ -162,20 +240,61 @@ public class Helium {
|
|||
allResources = ResourcePoolUtils.getAllResources();
|
||||
}
|
||||
|
||||
for (HeliumPackageSearchResult pkg : getAllPackageInfo()) {
|
||||
ResourceSet resources = ApplicationLoader.findRequiredResourceSet(
|
||||
pkg.getPkg().getResources(),
|
||||
paragraph.getNote().getId(),
|
||||
paragraph.getId(),
|
||||
allResources);
|
||||
if (resources == null) {
|
||||
continue;
|
||||
} else {
|
||||
suggestion.addAvailablePackage(pkg);
|
||||
for (List<HeliumPackageSearchResult> pkgs : getAllPackageInfo().values()) {
|
||||
for (HeliumPackageSearchResult pkg : pkgs) {
|
||||
if (pkg.getPkg().getType() == HeliumPackage.Type.APPLICATION && pkg.isEnabled()) {
|
||||
ResourceSet resources = ApplicationLoader.findRequiredResourceSet(
|
||||
pkg.getPkg().getResources(),
|
||||
paragraph.getNote().getId(),
|
||||
paragraph.getId(),
|
||||
allResources);
|
||||
if (resources == null) {
|
||||
continue;
|
||||
} else {
|
||||
suggestion.addAvailablePackage(pkg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suggestion.sort();
|
||||
return suggestion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled visualization packages
|
||||
*
|
||||
* @return ordered list of enabled visualization package
|
||||
*/
|
||||
public List<HeliumPackage> getVisualizationPackagesToBundle() {
|
||||
Map<String, List<HeliumPackageSearchResult>> allPackages = getAllPackageInfo();
|
||||
List<String> visOrder = heliumConf.getVisualizationDisplayOrder();
|
||||
|
||||
List<HeliumPackage> orderedVisualizationPackages = new LinkedList<>();
|
||||
|
||||
// add enabled packages in visOrder
|
||||
for (String name : visOrder) {
|
||||
List<HeliumPackageSearchResult> versions = allPackages.get(name);
|
||||
for (HeliumPackageSearchResult pkgInfo : versions) {
|
||||
if (pkgInfo.getPkg().getType() == HeliumPackage.Type.VISUALIZATION && pkgInfo.isEnabled()) {
|
||||
orderedVisualizationPackages.add(pkgInfo.getPkg());
|
||||
allPackages.remove(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return orderedVisualizationPackages;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@
|
|||
*/
|
||||
package org.apache.zeppelin.helium;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Helium config. This object will be persisted to conf/heliumc.conf
|
||||
|
|
@ -25,6 +24,13 @@ import java.util.List;
|
|||
public class HeliumConf {
|
||||
List<HeliumRegistry> registry = new LinkedList<>();
|
||||
|
||||
// enabled packages {name, version}
|
||||
Map<String, String> enabled = Collections.synchronizedMap(new HashMap<String, String>());
|
||||
|
||||
// enabled visualization package display order
|
||||
List<String> visualizationDisplayOrder = new LinkedList<>();
|
||||
|
||||
|
||||
public List<HeliumRegistry> getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
|
@ -33,5 +39,35 @@ public class HeliumConf {
|
|||
this.registry = registry;
|
||||
}
|
||||
|
||||
// enabled visualization
|
||||
public Map<String, String> getEnabledPackages() {
|
||||
return new HashMap<>(enabled);
|
||||
}
|
||||
|
||||
public void enablePackage(HeliumPackage pkg) {
|
||||
enablePackage(pkg.getName(), pkg.getArtifact());
|
||||
}
|
||||
|
||||
public void enablePackage(String name, String artifact) {
|
||||
enabled.put(name, artifact);
|
||||
}
|
||||
|
||||
public void disablePackage(HeliumPackage pkg) {
|
||||
disablePackage(pkg.getName());
|
||||
}
|
||||
|
||||
public void disablePackage(String name) {
|
||||
enabled.remove(name);
|
||||
}
|
||||
|
||||
public List<String> getVisualizationDisplayOrder() {
|
||||
return visualizationDisplayOrder;
|
||||
}
|
||||
|
||||
public void setVisualizationDisplayOrder(List<HeliumPackage> orderedPackageList) {
|
||||
List<String> order = new LinkedList<>();
|
||||
for (HeliumPackage pkg : orderedPackageList) {
|
||||
order.add(pkg.getName());
|
||||
}
|
||||
visualizationDisplayOrder = order;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,15 +22,17 @@ package org.apache.zeppelin.helium;
|
|||
public class HeliumPackageSearchResult {
|
||||
private final String registry;
|
||||
private final HeliumPackage pkg;
|
||||
private final boolean enabled;
|
||||
|
||||
/**
|
||||
* Create search result item
|
||||
* @param registry registry name
|
||||
* @param pkg package information
|
||||
*/
|
||||
public HeliumPackageSearchResult(String registry, HeliumPackage pkg) {
|
||||
public HeliumPackageSearchResult(String registry, HeliumPackage pkg, boolean enabled) {
|
||||
this.registry = registry;
|
||||
this.pkg = pkg;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getRegistry() {
|
||||
|
|
@ -40,4 +42,8 @@ public class HeliumPackageSearchResult {
|
|||
public HeliumPackage getPkg() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@ public class HeliumVisualizationFactory {
|
|||
private File tabledataModulePath;
|
||||
private File visualizationModulePath;
|
||||
|
||||
String bundleCacheKey = "";
|
||||
File currentBundle;
|
||||
|
||||
public HeliumVisualizationFactory(
|
||||
File moduleDownloadPath,
|
||||
File tabledataModulePath,
|
||||
|
|
@ -63,6 +66,7 @@ public class HeliumVisualizationFactory {
|
|||
frontEndPluginFactory = new FrontendPluginFactory(
|
||||
workingDirectory, installDirectory);
|
||||
|
||||
currentBundle = new File(workingDirectory, "vis.bundle.cache.js");
|
||||
installNodeAndNpm();
|
||||
}
|
||||
|
||||
|
|
@ -81,11 +85,12 @@ public class HeliumVisualizationFactory {
|
|||
return new ProxyConfig(proxy);
|
||||
}
|
||||
|
||||
public void bundle(List<HeliumPackage> pkgs) throws IOException, TaskRunnerException {
|
||||
public File bundle(List<HeliumPackage> pkgs) throws IOException, TaskRunnerException {
|
||||
// package.json
|
||||
URL pkgUrl = Resources.getResource("helium/package.json");
|
||||
String pkgJson = Resources.toString(pkgUrl, Charsets.UTF_8);
|
||||
StringBuffer dependencies = new StringBuffer();
|
||||
StringBuilder dependencies = new StringBuilder();
|
||||
|
||||
for (HeliumPackage pkg : pkgs) {
|
||||
String[] moduleNameVersion = getNpmModuleNameAndVersion(pkg);
|
||||
if (moduleNameVersion == null) {
|
||||
|
|
@ -104,6 +109,11 @@ public class HeliumVisualizationFactory {
|
|||
}
|
||||
pkgJson = pkgJson.replaceFirst("DEPENDENCIES", dependencies.toString());
|
||||
|
||||
// check if we can use previous bundle or not
|
||||
if (dependencies.toString().equals(bundleCacheKey) && currentBundle.isFile()) {
|
||||
return currentBundle;
|
||||
}
|
||||
|
||||
// webpack.config.js
|
||||
URL webpackConfigUrl = Resources.getResource("helium/webpack.config.js");
|
||||
String webpackConfig = Resources.toString(webpackConfigUrl, Charsets.UTF_8);
|
||||
|
|
@ -111,6 +121,7 @@ public class HeliumVisualizationFactory {
|
|||
// generate load.js
|
||||
StringBuilder loadJsImport = new StringBuilder();
|
||||
StringBuilder loadJsRegister = new StringBuilder();
|
||||
|
||||
for (HeliumPackage pkg : pkgs) {
|
||||
String [] moduleNameVersion = getNpmModuleNameAndVersion(pkg);
|
||||
if (moduleNameVersion == null) {
|
||||
|
|
@ -146,6 +157,28 @@ public class HeliumVisualizationFactory {
|
|||
|
||||
npmCommand("install");
|
||||
npmCommand("run bundle");
|
||||
|
||||
File visBundleJs = new File(workingDirectory, "vis.bundle.js");
|
||||
if (!visBundleJs.isFile()) {
|
||||
throw new IOException("Failed to create visualization bundle");
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
currentBundle.delete();
|
||||
FileUtils.moveFile(visBundleJs, currentBundle);
|
||||
bundleCacheKey = dependencies.toString();
|
||||
}
|
||||
return currentBundle;
|
||||
}
|
||||
|
||||
public File getCurrentBundle() {
|
||||
synchronized (this) {
|
||||
if (currentBundle.isFile()) {
|
||||
return currentBundle;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLocalPackage(HeliumPackage pkg) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.zeppelin.helium;
|
||||
|
||||
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
|
@ -48,10 +49,11 @@ public class HeliumTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSaveLoadConf() throws IOException, URISyntaxException {
|
||||
public void testSaveLoadConf() throws IOException, URISyntaxException, TaskRunnerException {
|
||||
// given
|
||||
File heliumConf = new File(tmpDir, "helium.conf");
|
||||
Helium helium = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath());
|
||||
Helium helium = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(),
|
||||
null, null);
|
||||
assertFalse(heliumConf.exists());
|
||||
HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1");
|
||||
helium.addRegistry(registry1);
|
||||
|
|
@ -65,14 +67,16 @@ public class HeliumTest {
|
|||
assertTrue(heliumConf.exists());
|
||||
|
||||
// then
|
||||
Helium heliumRestored = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath());
|
||||
Helium heliumRestored = new Helium(
|
||||
heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null);
|
||||
assertEquals(2, heliumRestored.getAllRegistry().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestoreRegistryInstances() throws IOException, URISyntaxException {
|
||||
public void testRestoreRegistryInstances() throws IOException, URISyntaxException, TaskRunnerException {
|
||||
File heliumConf = new File(tmpDir, "helium.conf");
|
||||
Helium helium = new Helium(heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath());
|
||||
Helium helium = new Helium(
|
||||
heliumConf.getAbsolutePath(), localRegistryPath.getAbsolutePath(), null, null);
|
||||
HeliumTestRegistry registry1 = new HeliumTestRegistry("r1", "r1");
|
||||
HeliumTestRegistry registry2 = new HeliumTestRegistry("r2", "r2");
|
||||
helium.addRegistry(registry1);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import java.net.URL;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class HeliumVisualizationFactoryTest {
|
||||
|
|
@ -38,8 +39,7 @@ public class HeliumVisualizationFactoryTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws InstallationException, TaskRunnerException {
|
||||
//tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis());
|
||||
tmpDir = new File("/tmp/npm");
|
||||
tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis());
|
||||
tmpDir.mkdirs();
|
||||
|
||||
// get module dir
|
||||
|
|
@ -91,8 +91,13 @@ public class HeliumVisualizationFactoryTest {
|
|||
);
|
||||
List<HeliumPackage> pkgs = new LinkedList<>();
|
||||
pkgs.add(pkg);
|
||||
hvf.bundle(pkgs);
|
||||
assertTrue(new File(tmpDir, "vis.bundle.js").isFile());
|
||||
File bundle = hvf.bundle(pkgs);
|
||||
assertTrue(bundle.isFile());
|
||||
long lastModified = bundle.lastModified();
|
||||
|
||||
// bundle again and check if it served from cache
|
||||
bundle = hvf.bundle(pkgs);
|
||||
assertEquals(lastModified, bundle.lastModified());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -101,7 +106,6 @@ public class HeliumVisualizationFactoryTest {
|
|||
URL res = Resources.getResource("helium/webpack.config.js");
|
||||
String resDir = new File(res.getFile()).getParent();
|
||||
String localPkg = resDir + "/../../../src/test/resources/helium/vis1";
|
||||
System.err.println("local package " + localPkg);
|
||||
|
||||
HeliumPackage pkg = new HeliumPackage(
|
||||
HeliumPackage.Type.VISUALIZATION,
|
||||
|
|
@ -114,7 +118,7 @@ public class HeliumVisualizationFactoryTest {
|
|||
);
|
||||
List<HeliumPackage> pkgs = new LinkedList<>();
|
||||
pkgs.add(pkg);
|
||||
hvf.bundle(pkgs);
|
||||
assertTrue(new File(tmpDir, "vis.bundle.js").isFile());
|
||||
File bundle = hvf.bundle(pkgs);
|
||||
assertTrue(bundle.isFile());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue