Search in sources :

Example 1 with InterpreterRPCException

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());
    }
}
Also used : InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) Interpreter(org.apache.zeppelin.interpreter.Interpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) Scheduler(org.apache.zeppelin.scheduler.Scheduler) RemoteInterpreterResult(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResult) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) RemoteInterpreterContext(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterContext) JobListener(org.apache.zeppelin.scheduler.JobListener) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) ApplicationException(org.apache.zeppelin.helium.ApplicationException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 2 with InterpreterRPCException

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());
    }
}
Also used : InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) Interpreter(org.apache.zeppelin.interpreter.Interpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 3 with InterpreterRPCException

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());
        }
    }
}
Also used : InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) IOException(java.io.IOException)

Example 4 with InterpreterRPCException

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;
}
Also used : InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) ResourceId(org.apache.zeppelin.resource.ResourceId) AngularObject(org.apache.zeppelin.display.AngularObject) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 5 with InterpreterRPCException

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);
}
Also used : AngularObject(org.apache.zeppelin.display.AngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HeliumAppAngularObjectRegistry(org.apache.zeppelin.helium.HeliumAppAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) ApplicationException(org.apache.zeppelin.helium.ApplicationException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Aggregations

InterpreterRPCException (org.apache.zeppelin.interpreter.thrift.InterpreterRPCException)11 IOException (java.io.IOException)9 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)9 TException (org.apache.thrift.TException)7 TTransportException (org.apache.thrift.transport.TTransportException)7 ApplicationException (org.apache.zeppelin.helium.ApplicationException)7 AngularObject (org.apache.zeppelin.display.AngularObject)5 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)4 HeliumAppAngularObjectRegistry (org.apache.zeppelin.helium.HeliumAppAngularObjectRegistry)4 Interpreter (org.apache.zeppelin.interpreter.Interpreter)4 LazyOpenInterpreter (org.apache.zeppelin.interpreter.LazyOpenInterpreter)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)2 RemoteAngularObject (org.apache.zeppelin.interpreter.remote.RemoteAngularObject)2 RemoteInterpreterContext (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterContext)2 DistributedResourcePool (org.apache.zeppelin.resource.DistributedResourcePool)2 ByteBuffer (java.nio.ByteBuffer)1