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();
}
}
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);
}
}
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();
}
}
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();
}
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);
}
}
Aggregations