Search in sources :

Example 1 with RemoteInterpreterResult

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResult in project zeppelin by apache.

the class RemoteInterpreter method interpret.

@Override
public InterpreterResult interpret(String st, InterpreterContext context) {
    if (logger.isDebugEnabled()) {
        logger.debug("st:\n{}", st);
    }
    FormType form = getFormType();
    RemoteInterpreterProcess interpreterProcess = getInterpreterProcess();
    Client client = null;
    try {
        client = interpreterProcess.getClient();
    } catch (Exception e1) {
        throw new InterpreterException(e1);
    }
    InterpreterContextRunnerPool interpreterContextRunnerPool = interpreterProcess.getInterpreterContextRunnerPool();
    List<InterpreterContextRunner> runners = context.getRunners();
    if (runners != null && runners.size() != 0) {
        // assume all runners in this InterpreterContext have the same note id
        String noteId = runners.get(0).getNoteId();
        interpreterContextRunnerPool.clear(noteId);
        interpreterContextRunnerPool.addAll(noteId, runners);
    }
    boolean broken = false;
    try {
        final GUI currentGUI = context.getGui();
        RemoteInterpreterResult remoteResult = client.interpret(sessionKey, className, st, convert(context));
        Map<String, Object> remoteConfig = (Map<String, Object>) gson.fromJson(remoteResult.getConfig(), new TypeToken<Map<String, Object>>() {
        }.getType());
        context.getConfig().clear();
        context.getConfig().putAll(remoteConfig);
        if (form == FormType.NATIVE) {
            GUI remoteGui = gson.fromJson(remoteResult.getGui(), GUI.class);
            currentGUI.clear();
            currentGUI.setParams(remoteGui.getParams());
            currentGUI.setForms(remoteGui.getForms());
        } else if (form == FormType.SIMPLE) {
            final Map<String, Input> currentForms = currentGUI.getForms();
            final Map<String, Object> currentParams = currentGUI.getParams();
            final GUI remoteGUI = gson.fromJson(remoteResult.getGui(), GUI.class);
            final Map<String, Input> remoteForms = remoteGUI.getForms();
            final Map<String, Object> remoteParams = remoteGUI.getParams();
            currentForms.putAll(remoteForms);
            currentParams.putAll(remoteParams);
        }
        InterpreterResult result = convert(remoteResult);
        return result;
    } catch (TException e) {
        broken = true;
        throw new InterpreterException(e);
    } finally {
        interpreterProcess.releaseClient(client, broken);
    }
}
Also used : TException(org.apache.thrift.TException) RemoteInterpreterResult(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResult) RemoteInterpreterResult(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResult) TException(org.apache.thrift.TException) GUI(org.apache.zeppelin.display.GUI) AngularObject(org.apache.zeppelin.display.AngularObject) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)

Aggregations

TException (org.apache.thrift.TException)1 AngularObject (org.apache.zeppelin.display.AngularObject)1 GUI (org.apache.zeppelin.display.GUI)1 RemoteInterpreterResult (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResult)1 Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)1