Search in sources :

Example 1 with ZeppelinServerResourceParagraphRunner

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

the class RemoteInterpreterEventPoller method progressRemoteZeppelinControlEvent.

private void progressRemoteZeppelinControlEvent(RemoteZeppelinServerResource.Type resourceType, RemoteInterpreterProcessListener remoteWorksEventListener, RemoteZeppelinServerResource reqResourceBody) throws Exception {
    boolean broken = false;
    final Gson gson = new Gson();
    final String eventOwnerKey = reqResourceBody.getOwnerKey();
    Client interpreterServerMain = null;
    try {
        interpreterServerMain = interpreterProcess.getClient();
        final Client eventClient = interpreterServerMain;
        if (resourceType == RemoteZeppelinServerResource.Type.PARAGRAPH_RUNNERS) {
            final List<ZeppelinServerResourceParagraphRunner> remoteRunners = new LinkedList<>();
            ZeppelinServerResourceParagraphRunner reqRunnerContext = new ZeppelinServerResourceParagraphRunner();
            Map<String, Object> reqResourceMap = (Map<String, Object>) reqResourceBody.getData();
            String noteId = (String) reqResourceMap.get("noteId");
            String paragraphId = (String) reqResourceMap.get("paragraphId");
            reqRunnerContext.setNoteId(noteId);
            reqRunnerContext.setParagraphId(paragraphId);
            RemoteInterpreterProcessListener.RemoteWorksEventListener callBackEvent = new RemoteInterpreterProcessListener.RemoteWorksEventListener() {

                @Override
                public void onFinished(Object resultObject) {
                    boolean clientBroken = false;
                    if (resultObject != null && resultObject instanceof List) {
                        List<InterpreterContextRunner> runnerList = (List<InterpreterContextRunner>) resultObject;
                        for (InterpreterContextRunner r : runnerList) {
                            remoteRunners.add(new ZeppelinServerResourceParagraphRunner(r.getNoteId(), r.getParagraphId()));
                        }
                        final RemoteZeppelinServerResource resResource = new RemoteZeppelinServerResource();
                        resResource.setOwnerKey(eventOwnerKey);
                        resResource.setResourceType(RemoteZeppelinServerResource.Type.PARAGRAPH_RUNNERS);
                        resResource.setData(remoteRunners);
                        try {
                            eventClient.onReceivedZeppelinResource(gson.toJson(resResource));
                        } catch (Exception e) {
                            clientBroken = true;
                            logger.error("Can't get RemoteInterpreterEvent", e);
                            waitQuietly();
                        } finally {
                            interpreterProcess.releaseClient(eventClient, clientBroken);
                        }
                    }
                }

                @Override
                public void onError() {
                    logger.info("onGetParagraphRunners onError");
                }
            };
            remoteWorksEventListener.onGetParagraphRunners(reqRunnerContext.getNoteId(), reqRunnerContext.getParagraphId(), callBackEvent);
        }
    } catch (Exception e) {
        broken = true;
        logger.error("Can't get RemoteInterpreterEvent", e);
        waitQuietly();
    } finally {
        interpreterProcess.releaseClient(interpreterServerMain, broken);
    }
}
Also used : ZeppelinServerResourceParagraphRunner(org.apache.zeppelin.interpreter.thrift.ZeppelinServerResourceParagraphRunner) InterpreterContextRunner(org.apache.zeppelin.interpreter.InterpreterContextRunner) Gson(com.google.gson.Gson) LinkedList(java.util.LinkedList) TException(org.apache.thrift.TException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AngularObject(org.apache.zeppelin.display.AngularObject) LinkedList(java.util.LinkedList) List(java.util.List) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) Map(java.util.Map) RemoteZeppelinServerResource(org.apache.zeppelin.interpreter.RemoteZeppelinServerResource)

Aggregations

Gson (com.google.gson.Gson)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 TException (org.apache.thrift.TException)1 AngularObject (org.apache.zeppelin.display.AngularObject)1 InterpreterContextRunner (org.apache.zeppelin.interpreter.InterpreterContextRunner)1 RemoteZeppelinServerResource (org.apache.zeppelin.interpreter.RemoteZeppelinServerResource)1 Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)1 ZeppelinServerResourceParagraphRunner (org.apache.zeppelin.interpreter.thrift.ZeppelinServerResourceParagraphRunner)1