Search in sources :

Example 1 with ApplicationContext

use of org.apache.zeppelin.helium.ApplicationContext in project zeppelin by apache.

the class RemoteInterpreterServer method loadApplication.

@Override
public RemoteApplicationResult loadApplication(String applicationInstanceId, String packageInfo, String noteId, String paragraphId) throws InterpreterRPCException, TException {
    if (runningApplications.containsKey(applicationInstanceId)) {
        LOGGER.warn("Application instance {} is already running", applicationInstanceId);
        return new RemoteApplicationResult(true, "");
    }
    HeliumPackage pkgInfo = HeliumPackage.fromJson(packageInfo);
    ApplicationContext context = getApplicationContext(pkgInfo, noteId, paragraphId, applicationInstanceId);
    try {
        Application app = null;
        LOGGER.info("Loading application {}({}), artifact={}, className={} into note={}, paragraph={}", pkgInfo.getName(), applicationInstanceId, pkgInfo.getArtifact(), pkgInfo.getClassName(), noteId, paragraphId);
        app = appLoader.load(pkgInfo, context);
        runningApplications.put(applicationInstanceId, new RunningApplication(pkgInfo, app, noteId, paragraphId));
        return new RemoteApplicationResult(true, "");
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return new RemoteApplicationResult(false, e.getMessage());
    }
}
Also used : ApplicationContext(org.apache.zeppelin.helium.ApplicationContext) HeliumPackage(org.apache.zeppelin.helium.HeliumPackage) RemoteApplicationResult(org.apache.zeppelin.interpreter.thrift.RemoteApplicationResult) Application(org.apache.zeppelin.helium.Application) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) ApplicationException(org.apache.zeppelin.helium.ApplicationException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 2 with ApplicationContext

use of org.apache.zeppelin.helium.ApplicationContext in project zeppelin by apache.

the class RemoteInterpreterServer method runApplication.

@Override
public RemoteApplicationResult runApplication(String applicationInstanceId) throws InterpreterRPCException, TException {
    LOGGER.info("run application {}", applicationInstanceId);
    RunningApplication runningApp = runningApplications.get(applicationInstanceId);
    if (runningApp == null) {
        LOGGER.error("Application instance {} not exists", applicationInstanceId);
        return new RemoteApplicationResult(false, "Application instance does not exists");
    } else {
        ApplicationContext context = runningApp.app.context();
        try {
            context.out.clear();
            context.out.setType(InterpreterResult.Type.ANGULAR);
            ResourceSet resource = appLoader.findRequiredResourceSet(runningApp.pkg.getResources(), context.getNoteId(), context.getParagraphId());
            for (Resource res : resource) {
                System.err.println("Resource " + res.get());
            }
            runningApp.app.run(resource);
            context.out.flush();
            InterpreterResultMessageOutput out = context.out.getOutputAt(0);
            intpEventClient.onAppOutputUpdate(context.getNoteId(), context.getParagraphId(), 0, applicationInstanceId, out.getType(), new String(out.toByteArray()));
            return new RemoteApplicationResult(true, "");
        } catch (ApplicationException | IOException e) {
            return new RemoteApplicationResult(false, e.getMessage());
        }
    }
}
Also used : ApplicationContext(org.apache.zeppelin.helium.ApplicationContext) ApplicationException(org.apache.zeppelin.helium.ApplicationException) Resource(org.apache.zeppelin.resource.Resource) InterpreterResultMessageOutput(org.apache.zeppelin.interpreter.InterpreterResultMessageOutput) ResourceSet(org.apache.zeppelin.resource.ResourceSet) IOException(java.io.IOException) RemoteApplicationResult(org.apache.zeppelin.interpreter.thrift.RemoteApplicationResult)

Aggregations

IOException (java.io.IOException)2 ApplicationContext (org.apache.zeppelin.helium.ApplicationContext)2 ApplicationException (org.apache.zeppelin.helium.ApplicationException)2 RemoteApplicationResult (org.apache.zeppelin.interpreter.thrift.RemoteApplicationResult)2 TException (org.apache.thrift.TException)1 TTransportException (org.apache.thrift.transport.TTransportException)1 Application (org.apache.zeppelin.helium.Application)1 HeliumPackage (org.apache.zeppelin.helium.HeliumPackage)1 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)1 InterpreterResultMessageOutput (org.apache.zeppelin.interpreter.InterpreterResultMessageOutput)1 InterpreterRPCException (org.apache.zeppelin.interpreter.thrift.InterpreterRPCException)1 Resource (org.apache.zeppelin.resource.Resource)1 ResourceSet (org.apache.zeppelin.resource.ResourceSet)1