Search in sources :

Example 6 with ResourceSet

use of org.apache.zeppelin.resource.ResourceSet in project zeppelin by apache.

the class ApplicationLoader method load.

/**
   *
   * Instantiate application
   *
   * @param packageInfo
   * @param context
   * @return
   * @throws Exception
   */
public Application load(HeliumPackage packageInfo, ApplicationContext context) throws Exception {
    if (packageInfo.getType() != HeliumType.APPLICATION) {
        throw new ApplicationException("Can't instantiate " + packageInfo.getType() + " package using ApplicationLoader");
    }
    // check if already loaded
    RunningApplication key = new RunningApplication(packageInfo, context.getNoteId(), context.getParagraphId());
    // get resource required by this package
    ResourceSet resources = findRequiredResourceSet(packageInfo.getResources(), context.getNoteId(), context.getParagraphId());
    // load class
    Class<Application> appClass = loadClass(packageInfo);
    // instantiate
    ClassLoader oldcl = Thread.currentThread().getContextClassLoader();
    ClassLoader cl = appClass.getClassLoader();
    Thread.currentThread().setContextClassLoader(cl);
    try {
        Constructor<Application> constructor = appClass.getConstructor(ApplicationContext.class);
        Application app = new ClassLoaderApplication(constructor.newInstance(context), cl);
        return app;
    } catch (Exception e) {
        throw new ApplicationException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldcl);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) ResourceSet(org.apache.zeppelin.resource.ResourceSet)

Aggregations

ResourceSet (org.apache.zeppelin.resource.ResourceSet)6 Gson (com.google.gson.Gson)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TException (org.apache.thrift.TException)2 Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)2 ResourcePool (org.apache.zeppelin.resource.ResourcePool)2 TypeToken (com.google.gson.reflect.TypeToken)1 URLClassLoader (java.net.URLClassLoader)1 Map (java.util.Map)1 AngularObject (org.apache.zeppelin.display.AngularObject)1 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)1 Interpreter (org.apache.zeppelin.interpreter.Interpreter)1 InterpreterContextRunner (org.apache.zeppelin.interpreter.InterpreterContextRunner)1 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 RemoteZeppelinServerResource (org.apache.zeppelin.interpreter.RemoteZeppelinServerResource)1 RemoteInterpreterEvent (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent)1 RemoteInterpreterEventType (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventType)1