Search in sources :

Example 1 with InvokeResourceMethodEventMessage

use of org.apache.zeppelin.interpreter.remote.InvokeResourceMethodEventMessage in project zeppelin by apache.

the class RemoteInterpreterEventServer method invokeMethod.

/**
 * @param intpGroupId caller interpreter group id
 * @param invokeMethodJson invoke information
 * @return
 * @throws TException
 */
@Override
public ByteBuffer invokeMethod(String intpGroupId, String invokeMethodJson) throws InterpreterRPCException, TException {
    InvokeResourceMethodEventMessage invokeMethodMessage = InvokeResourceMethodEventMessage.fromJson(invokeMethodJson);
    Object ret = invokeResourceMethod(intpGroupId, invokeMethodMessage);
    ByteBuffer obj = null;
    if (ret == null) {
        obj = ByteBuffer.allocate(0);
    } else {
        try {
            obj = Resource.serializeObject(ret);
        } catch (IOException e) {
            LOGGER.error("invokeMethod failed", e);
        }
    }
    return obj;
}
Also used : AngularObject(org.apache.zeppelin.display.AngularObject) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) InvokeResourceMethodEventMessage(org.apache.zeppelin.interpreter.remote.InvokeResourceMethodEventMessage)

Example 2 with InvokeResourceMethodEventMessage

use of org.apache.zeppelin.interpreter.remote.InvokeResourceMethodEventMessage in project zeppelin by apache.

the class RemoteInterpreterEventServer method invokeResourceMethod.

private Object invokeResourceMethod(String intpGroupId, final InvokeResourceMethodEventMessage message) {
    final ResourceId resourceId = message.resourceId;
    ManagedInterpreterGroup intpGroup = interpreterSettingManager.getInterpreterGroupById(resourceId.getResourcePoolId());
    if (intpGroup == null) {
        return null;
    }
    RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
    if (remoteInterpreterProcess == null) {
        ResourcePool localPool = intpGroup.getResourcePool();
        if (localPool != null) {
            Resource res = localPool.get(resourceId.getName());
            if (res != null) {
                try {
                    return res.invokeMethod(message.methodName, message.getParamTypes(), message.params, message.returnResourceName);
                } catch (Exception e) {
                    LOGGER.error(e.getMessage(), e);
                    return null;
                }
            } else {
                // object is null. can't invoke any method
                LOGGER.error("Can't invoke method {} on null object", message.methodName);
                return null;
            }
        } else {
            LOGGER.error("no resource pool");
            return null;
        }
    } else if (remoteInterpreterProcess.isRunning()) {
        ByteBuffer res = remoteInterpreterProcess.callRemoteFunction(client -> client.resourceInvokeMethod(resourceId.getNoteId(), resourceId.getParagraphId(), resourceId.getName(), message.toJson()));
        try {
            return Resource.deserializeObject(res);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }
    return null;
}
Also used : RegisterInfo(org.apache.zeppelin.interpreter.thrift.RegisterInfo) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) RemoteInterpreterEventService(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventService) TypeToken(com.google.gson.reflect.TypeToken) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ScheduledFuture(java.util.concurrent.ScheduledFuture) AppendOutputRunner(org.apache.zeppelin.interpreter.remote.AppendOutputRunner) Resource(org.apache.zeppelin.resource.Resource) TTransportException(org.apache.thrift.transport.TTransportException) LoggerFactory(org.slf4j.LoggerFactory) ResourcePool(org.apache.zeppelin.resource.ResourcePool) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) StringUtils(org.apache.commons.lang3.StringUtils) ByteBuffer(java.nio.ByteBuffer) LibraryMetadata(org.apache.zeppelin.interpreter.thrift.LibraryMetadata) ParagraphInfo(org.apache.zeppelin.interpreter.thrift.ParagraphInfo) Gson(com.google.gson.Gson) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) Map(java.util.Map) AngularObject(org.apache.zeppelin.display.AngularObject) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) Collection(java.util.Collection) Executors(java.util.concurrent.Executors) List(java.util.List) OutputAppendEvent(org.apache.zeppelin.interpreter.thrift.OutputAppendEvent) WebUrlInfo(org.apache.zeppelin.interpreter.thrift.WebUrlInfo) OutputUpdateEvent(org.apache.zeppelin.interpreter.thrift.OutputUpdateEvent) RemoteInterpreterUtils(org.apache.zeppelin.interpreter.remote.RemoteInterpreterUtils) RemoteInterpreterProcessListener(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener) ArrayList(java.util.ArrayList) RunParagraphsEvent(org.apache.zeppelin.interpreter.thrift.RunParagraphsEvent) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) LinkedList(java.util.LinkedList) RemoteInterpreterResultMessage(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage) ResourceSet(org.apache.zeppelin.resource.ResourceSet) OutputUpdateAllEvent(org.apache.zeppelin.interpreter.thrift.OutputUpdateAllEvent) Logger(org.slf4j.Logger) ApplicationEventListener(org.apache.zeppelin.helium.ApplicationEventListener) AppOutputAppendEvent(org.apache.zeppelin.interpreter.thrift.AppOutputAppendEvent) ResourceId(org.apache.zeppelin.resource.ResourceId) Note(org.apache.zeppelin.notebook.Note) TException(org.apache.thrift.TException) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) TServerSocket(org.apache.thrift.transport.TServerSocket) RemoteResource(org.apache.zeppelin.resource.RemoteResource) AppStatusUpdateEvent(org.apache.zeppelin.interpreter.thrift.AppStatusUpdateEvent) InvokeResourceMethodEventMessage(org.apache.zeppelin.interpreter.remote.InvokeResourceMethodEventMessage) AppOutputUpdateEvent(org.apache.zeppelin.interpreter.thrift.AppOutputUpdateEvent) Collections(java.util.Collections) ResourceId(org.apache.zeppelin.resource.ResourceId) Resource(org.apache.zeppelin.resource.Resource) RemoteResource(org.apache.zeppelin.resource.RemoteResource) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ResourcePool(org.apache.zeppelin.resource.ResourcePool) ByteBuffer(java.nio.ByteBuffer) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 AngularObject (org.apache.zeppelin.display.AngularObject)2 InvokeResourceMethodEventMessage (org.apache.zeppelin.interpreter.remote.InvokeResourceMethodEventMessage)2 RemoteAngularObject (org.apache.zeppelin.interpreter.remote.RemoteAngularObject)2 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 FileUtils (org.apache.commons.io.FileUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1