use of org.apache.zeppelin.scheduler.JobListener in project zeppelin by apache.
the class RemoteInterpreterServer method interpret.
@Override
public RemoteInterpreterResult interpret(String sessionId, String className, String st, RemoteInterpreterContext interpreterContext) throws InterpreterRPCException, TException {
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("st:\n{}", st);
}
lifecycleManager.onInterpreterUse(interpreterGroupId);
Interpreter intp = getInterpreter(sessionId, className);
InterpreterContext context = convert(interpreterContext);
context.setInterpreterClassName(intp.getClassName());
InterpretJob interpretJob = null;
boolean isRecover = Boolean.parseBoolean(context.getLocalProperties().getOrDefault("isRecover", "false"));
if (isRecover) {
LOGGER.info("Recovering paragraph: {} of note: {}", context.getParagraphId(), context.getNoteId());
interpretJob = runningJobs.get(context.getParagraphId());
if (interpretJob == null) {
InterpreterResult result = new InterpreterResult(Code.ERROR, "Job is finished, unable to recover it");
return convert(result, context.getConfig(), context.getGui(), context.getNoteGui());
}
} else {
Scheduler scheduler = intp.getScheduler();
InterpretJobListener jobListener = new InterpretJobListener();
interpretJob = new InterpretJob(context.getParagraphId(), "RemoteInterpretJob_" + System.currentTimeMillis(), jobListener, intp, st, context);
runningJobs.put(context.getParagraphId(), interpretJob);
scheduler.submit(interpretJob);
}
while (!interpretJob.isTerminated()) {
JobListener jobListener = interpretJob.getListener();
synchronized (jobListener) {
try {
jobListener.wait(1000);
} catch (InterruptedException e) {
LOGGER.info("Exception in RemoteInterpreterServer while interpret, jobListener.wait", e);
}
}
}
progressMap.remove(context.getParagraphId());
resultCleanService.schedule(() -> {
runningJobs.remove(context.getParagraphId());
}, resultCacheInSeconds, TimeUnit.SECONDS);
InterpreterResult result = interpretJob.getReturn();
// in case of job abort in PENDING status, result can be null
if (result == null) {
result = new InterpreterResult(Code.KEEP_PREVIOUS_RESULT);
}
return convert(result, context.getConfig(), context.getGui(), context.getNoteGui());
} catch (Exception e) {
LOGGER.error("Internal error when interpret code", e);
throw new InterpreterRPCException(e.toString());
}
}
Aggregations