Search in sources :

Example 1 with InterpreterContextRunner

use of org.apache.zeppelin.interpreter.InterpreterContextRunner in project zeppelin by apache.

the class ZeppelinContext method runNote.

public void runNote(String noteId, InterpreterContext context) {
    String runningNoteId = context.getNoteId();
    String runningParagraphId = context.getParagraphId();
    List<InterpreterContextRunner> runners = getInterpreterContextRunner(noteId, context);
    if (runners.size() <= 0) {
        throw new InterpreterException("Note " + noteId + " not found " + runners.size());
    }
    for (InterpreterContextRunner r : runners) {
        if (r.getNoteId().equals(runningNoteId) && r.getParagraphId().equals(runningParagraphId)) {
            continue;
        }
        r.run();
    }
}
Also used : InterpreterContextRunner(org.apache.zeppelin.interpreter.InterpreterContextRunner) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 2 with InterpreterContextRunner

use of org.apache.zeppelin.interpreter.InterpreterContextRunner in project zeppelin by apache.

the class InterpreterContextRunnerPool method run.

public void run(String noteId, String paragraphId) {
    synchronized (interpreterContextRunners) {
        List<InterpreterContextRunner> list = interpreterContextRunners.get(noteId);
        if (list != null) {
            for (InterpreterContextRunner r : list) {
                if (noteId.equals(r.getNoteId()) && paragraphId.equals(r.getParagraphId())) {
                    logger.info("run paragraph {} on note {} from InterpreterContext", r.getParagraphId(), r.getNoteId());
                    r.run();
                    return;
                }
            }
        }
        throw new InterpreterException("Can not run paragraph " + paragraphId + " on " + noteId);
    }
}
Also used : InterpreterContextRunner(org.apache.zeppelin.interpreter.InterpreterContextRunner) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 3 with InterpreterContextRunner

use of org.apache.zeppelin.interpreter.InterpreterContextRunner in project zeppelin by apache.

the class NotebookServer method onGetParagraphRunners.

@Override
public void onGetParagraphRunners(String noteId, String paragraphId, RemoteWorksEventListener callback) {
    Notebook notebookIns = notebook();
    List<InterpreterContextRunner> runner = new LinkedList<>();
    if (notebookIns == null) {
        LOG.info("intepreter request notebook instance is null");
        callback.onFinished(notebookIns);
    }
    try {
        Note note = notebookIns.getNote(noteId);
        if (note != null) {
            if (paragraphId != null) {
                Paragraph paragraph = note.getParagraph(paragraphId);
                if (paragraph != null) {
                    runner.add(paragraph.getInterpreterContextRunner());
                }
            } else {
                for (Paragraph p : note.getParagraphs()) {
                    runner.add(p.getInterpreterContextRunner());
                }
            }
        }
        callback.onFinished(runner);
    } catch (NullPointerException e) {
        LOG.warn(e.getMessage());
        callback.onError();
    }
}
Also used : InterpreterContextRunner(org.apache.zeppelin.interpreter.InterpreterContextRunner) Notebook(org.apache.zeppelin.notebook.Notebook) Note(org.apache.zeppelin.notebook.Note) LinkedList(java.util.LinkedList) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 4 with InterpreterContextRunner

use of org.apache.zeppelin.interpreter.InterpreterContextRunner in project zeppelin by apache.

the class ZeppelinContext method run.

/**
   * Run paragraph at index
   * @param idx index starting from 0
   * @param context interpreter context
   */
public void run(String noteId, int idx, InterpreterContext context) {
    List<InterpreterContextRunner> runners = getInterpreterContextRunner(noteId, context);
    if (idx >= runners.size()) {
        throw new InterpreterException("Index out of bound");
    }
    InterpreterContextRunner runner = runners.get(idx);
    if (runner.getParagraphId().equals(context.getParagraphId())) {
        throw new InterpreterException("Can not run current Paragraph");
    }
    runner.run();
}
Also used : InterpreterContextRunner(org.apache.zeppelin.interpreter.InterpreterContextRunner) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 5 with InterpreterContextRunner

use of org.apache.zeppelin.interpreter.InterpreterContextRunner 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

InterpreterContextRunner (org.apache.zeppelin.interpreter.InterpreterContextRunner)7 LinkedList (java.util.LinkedList)4 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 Map (java.util.Map)2 TException (org.apache.thrift.TException)2 AngularObject (org.apache.zeppelin.display.AngularObject)2 RemoteZeppelinServerResource (org.apache.zeppelin.interpreter.RemoteZeppelinServerResource)2 Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)2 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)1 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 RemoteWorksController (org.apache.zeppelin.interpreter.RemoteWorksController)1 RemoteInterpreterEvent (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent)1 RemoteInterpreterEventType (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventType)1 ZeppelinServerResourceParagraphRunner (org.apache.zeppelin.interpreter.thrift.ZeppelinServerResourceParagraphRunner)1 Note (org.apache.zeppelin.notebook.Note)1