Search in sources :

Example 6 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteAngularObjectRegistry method removeAndNotifyRemoteProcess.

/**
   * When ZeppelinServer side code want to remove angularObject from the registry,
   * this method should be used instead of remove()
   * @param name
   * @param noteId
   * @param paragraphId
   * @return
   */
public AngularObject removeAndNotifyRemoteProcess(String name, String noteId, String paragraphId) {
    RemoteInterpreterProcess remoteInterpreterProcess = getRemoteInterpreterProcess();
    if (remoteInterpreterProcess == null || !remoteInterpreterProcess.isRunning()) {
        return super.remove(name, noteId, paragraphId);
    }
    Client client = null;
    boolean broken = false;
    try {
        client = remoteInterpreterProcess.getClient();
        client.angularObjectRemove(name, noteId, paragraphId);
        return super.remove(name, noteId, paragraphId);
    } catch (TException e) {
        broken = true;
        logger.error("Error", e);
    } catch (Exception e) {
        logger.error("Error", e);
    } finally {
        if (client != null) {
            remoteInterpreterProcess.releaseClient(client, broken);
        }
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Example 7 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteAngularObjectRegistry method addAndNotifyRemoteProcess.

/**
   * When ZeppelinServer side code want to add angularObject to the registry,
   * this method should be used instead of add()
   * @param name
   * @param o
   * @param noteId
   * @return
   */
public AngularObject addAndNotifyRemoteProcess(String name, Object o, String noteId, String paragraphId) {
    Gson gson = new Gson();
    RemoteInterpreterProcess remoteInterpreterProcess = getRemoteInterpreterProcess();
    if (!remoteInterpreterProcess.isRunning()) {
        return super.add(name, o, noteId, paragraphId, true);
    }
    Client client = null;
    boolean broken = false;
    try {
        client = remoteInterpreterProcess.getClient();
        client.angularObjectAdd(name, noteId, paragraphId, gson.toJson(o));
        return super.add(name, o, noteId, paragraphId, true);
    } catch (TException e) {
        broken = true;
        logger.error("Error", e);
    } catch (Exception e) {
        logger.error("Error", e);
    } finally {
        if (client != null) {
            remoteInterpreterProcess.releaseClient(client, broken);
        }
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) Gson(com.google.gson.Gson) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Example 8 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client 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)

Example 9 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteInterpreter method completion.

@Override
public List<InterpreterCompletion> completion(String buf, int cursor) {
    RemoteInterpreterProcess interpreterProcess = getInterpreterProcess();
    Client client = null;
    try {
        client = interpreterProcess.getClient();
    } catch (Exception e1) {
        throw new InterpreterException(e1);
    }
    boolean broken = false;
    try {
        List completion = client.completion(sessionKey, className, buf, cursor);
        return completion;
    } catch (TException e) {
        broken = true;
        throw new InterpreterException(e);
    } finally {
        interpreterProcess.releaseClient(client, broken);
    }
}
Also used : TException(org.apache.thrift.TException) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Example 10 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteInterpreter method getFormType.

@Override
public FormType getFormType() {
    init();
    if (formType != null) {
        return formType;
    }
    RemoteInterpreterProcess interpreterProcess = getInterpreterProcess();
    Client client = null;
    try {
        client = interpreterProcess.getClient();
    } catch (Exception e1) {
        throw new InterpreterException(e1);
    }
    boolean broken = false;
    try {
        formType = FormType.valueOf(client.getFormType(sessionKey, className));
        return formType;
    } catch (TException e) {
        broken = true;
        throw new InterpreterException(e);
    } finally {
        interpreterProcess.releaseClient(client, broken);
    }
}
Also used : TException(org.apache.thrift.TException) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Aggregations

Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)22 TException (org.apache.thrift.TException)19 Gson (com.google.gson.Gson)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 AngularObject (org.apache.zeppelin.display.AngularObject)6 ByteBuffer (java.nio.ByteBuffer)4 LinkedList (java.util.LinkedList)4 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)4 RemoteZeppelinServerResource (org.apache.zeppelin.interpreter.RemoteZeppelinServerResource)4 List (java.util.List)3 Map (java.util.Map)3 ResourcePool (org.apache.zeppelin.resource.ResourcePool)3 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 InterpreterContextRunner (org.apache.zeppelin.interpreter.InterpreterContextRunner)2 Resource (org.apache.zeppelin.resource.Resource)2 ResourceId (org.apache.zeppelin.resource.ResourceId)2 ResourceSet (org.apache.zeppelin.resource.ResourceSet)2 Test (org.junit.Test)2 TypeToken (com.google.gson.reflect.TypeToken)1 HashMap (java.util.HashMap)1