use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException 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());
}
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterServer method open.
@Override
public void open(String sessionId, String className) throws InterpreterRPCException, TException {
LOGGER.info("Open Interpreter {} for session {}", className, sessionId);
Interpreter intp = getInterpreter(sessionId, className);
try {
intp.open();
} catch (InterpreterException e) {
throw new InterpreterRPCException(e.toString());
}
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterEventServer method updateAngularObject.
@Override
public void updateAngularObject(String intpGroupId, String json) throws InterpreterRPCException, TException {
AngularObject<?> angularObject = AngularObject.fromJson(json);
InterpreterGroup interpreterGroup = interpreterSettingManager.getInterpreterGroupById(intpGroupId);
if (interpreterGroup == null) {
throw new InterpreterRPCException("Invalid InterpreterGroupId: " + intpGroupId);
}
AngularObject localAngularObject = interpreterGroup.getAngularObjectRegistry().get(angularObject.getName(), angularObject.getNoteId(), angularObject.getParagraphId());
if (localAngularObject instanceof RemoteAngularObject) {
// to avoid ping-pong loop
((RemoteAngularObject) localAngularObject).set(angularObject.get(), true, false);
} else {
localAngularObject.set(angularObject.get());
}
if (angularObject.getNoteId() != null) {
try {
interpreterSettingManager.getNotebook().processNote(angularObject.getNoteId(), note -> {
if (note != null) {
note.addOrUpdateAngularObject(intpGroupId, angularObject);
interpreterSettingManager.getNotebook().saveNote(note, AuthenticationInfo.ANONYMOUS);
}
return null;
});
} catch (IOException e) {
LOGGER.error("Fail to get note: {}", angularObject.getNoteId());
}
}
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterEventServer method getResource.
@Override
public ByteBuffer getResource(String resourceIdJson) throws InterpreterRPCException, TException {
ResourceId resourceId = ResourceId.fromJson(resourceIdJson);
Object o = getResource(resourceId);
ByteBuffer obj;
if (o == null) {
obj = ByteBuffer.allocate(0);
} else {
try {
obj = Resource.serializeObject(o);
} catch (IOException e) {
throw new InterpreterRPCException(e.toString());
}
}
return obj;
}
use of org.apache.zeppelin.interpreter.thrift.InterpreterRPCException in project zeppelin by apache.
the class RemoteInterpreterServer method angularObjectAdd.
/**
* When zeppelinserver initiate angular object add.
* Dont't need to emit event to zeppelin server
*/
@Override
public void angularObjectAdd(String name, String noteId, String paragraphId, String object) throws InterpreterRPCException, TException {
AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
// first try local objects
AngularObject ao = registry.get(name, noteId, paragraphId);
if (ao != null) {
angularObjectUpdate(name, noteId, paragraphId, object);
return;
}
// Generic java object type for json.
Object value = null;
try {
value = gson.fromJson(object, new TypeToken<Map<String, Object>>() {
}.getType());
} catch (Exception e) {
// it's okay. proceed to treat object as a string
LOGGER.debug(e.getMessage(), e);
}
// try string object type at last
if (value == null) {
value = gson.fromJson(object, String.class);
}
registry.add(name, value, noteId, paragraphId, false);
}
Aggregations