Search in sources :

Example 1 with ApplicationException

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

the class RemoteInterpreterServer method unloadApplication.

@Override
public RemoteApplicationResult unloadApplication(String applicationInstanceId) throws InterpreterRPCException, TException {
    RunningApplication runningApplication = runningApplications.remove(applicationInstanceId);
    if (runningApplication != null) {
        try {
            LOGGER.info("Unloading application {}", applicationInstanceId);
            runningApplication.app.unload();
        } catch (ApplicationException e) {
            LOGGER.error(e.getMessage(), e);
            return new RemoteApplicationResult(false, e.getMessage());
        }
    }
    return new RemoteApplicationResult(true, "");
}
Also used : ApplicationException(org.apache.zeppelin.helium.ApplicationException) RemoteApplicationResult(org.apache.zeppelin.interpreter.thrift.RemoteApplicationResult)

Example 2 with ApplicationException

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

the class RemoteInterpreterServer method close.

@Override
public void close(String sessionId, String className) throws InterpreterRPCException, TException {
    // unload all applications
    for (String appId : runningApplications.keySet()) {
        RunningApplication appInfo = runningApplications.get(appId);
        // see NoteInterpreterLoader.SHARED_SESSION
        if (appInfo.noteId.equals(sessionId) || sessionId.equals("shared_session")) {
            try {
                LOGGER.info("Unload App {} ", appInfo.pkg.getName());
                appInfo.app.unload();
                // see ApplicationState.Status.UNLOADED
                intpEventClient.onAppStatusUpdate(appInfo.noteId, appInfo.paragraphId, appId, "UNLOADED");
            } catch (ApplicationException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    }
    // close interpreters
    if (interpreterGroup != null) {
        synchronized (interpreterGroup) {
            List<Interpreter> interpreters = interpreterGroup.get(sessionId);
            if (interpreters != null) {
                Iterator<Interpreter> it = interpreters.iterator();
                while (it.hasNext()) {
                    Interpreter inp = it.next();
                    if (inp.getClassName().equals(className)) {
                        try {
                            inp.close();
                        } catch (InterpreterException e) {
                            LOGGER.warn("Fail to close interpreter", e);
                        }
                        it.remove();
                        break;
                    }
                }
            }
        }
    }
}
Also used : ApplicationException(org.apache.zeppelin.helium.ApplicationException) Interpreter(org.apache.zeppelin.interpreter.Interpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 3 with ApplicationException

use of org.apache.zeppelin.helium.ApplicationException 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

ApplicationException (org.apache.zeppelin.helium.ApplicationException)3 RemoteApplicationResult (org.apache.zeppelin.interpreter.thrift.RemoteApplicationResult)2 IOException (java.io.IOException)1 ApplicationContext (org.apache.zeppelin.helium.ApplicationContext)1 Interpreter (org.apache.zeppelin.interpreter.Interpreter)1 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)1 InterpreterResultMessageOutput (org.apache.zeppelin.interpreter.InterpreterResultMessageOutput)1 LazyOpenInterpreter (org.apache.zeppelin.interpreter.LazyOpenInterpreter)1 Resource (org.apache.zeppelin.resource.Resource)1 ResourceSet (org.apache.zeppelin.resource.ResourceSet)1