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