use of org.apache.zeppelin.resource.ResourcePool in project zeppelin by apache.
the class SparkInterpreter method putLatestVarInResourcePool.
private void putLatestVarInResourcePool(InterpreterContext context) {
String varName = (String) Utils.invokeMethod(intp, "mostRecentVar");
if (varName == null || varName.isEmpty()) {
return;
}
Object lastObj = null;
try {
if (Utils.isScala2_10()) {
lastObj = getValue(varName);
} else {
lastObj = getLastObject();
}
} catch (NullPointerException e) {
// Some case, scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call throws an NPE
logger.error(e.getMessage(), e);
}
if (lastObj != null) {
ResourcePool resourcePool = context.getResourcePool();
resourcePool.put(context.getNoteId(), context.getParagraphId(), WellKnownResourceName.ZeppelinReplResult.toString(), lastObj);
}
}
use of org.apache.zeppelin.resource.ResourcePool in project zeppelin by apache.
the class ZeppelinContext method containsKey.
/**
* Check if resource pool has the object
* @param name
* @return
*/
@ZeppelinApi
public boolean containsKey(String name) {
ResourcePool resourcePool = interpreterContext.getResourcePool();
Resource resource = resourcePool.get(name);
return resource != null;
}
use of org.apache.zeppelin.resource.ResourcePool in project zeppelin by apache.
the class RemoteInterpreterEventPoller method invokeResourceMethod.
private Object invokeResourceMethod(InvokeResourceMethodEventMessage message) {
ResourceId resourceId = message.resourceId;
InterpreterGroup intpGroup = InterpreterGroup.getByInterpreterGroupId(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 (interpreterProcess.isRunning()) {
Client client = null;
boolean broken = false;
try {
client = remoteInterpreterProcess.getClient();
ByteBuffer res = client.resourceInvokeMethod(resourceId.getNoteId(), resourceId.getParagraphId(), resourceId.getName(), gson.toJson(message));
Object o = Resource.deserializeObject(res);
return o;
} catch (Exception e) {
logger.error(e.getMessage(), e);
broken = true;
} finally {
if (client != null) {
intpGroup.getRemoteInterpreterProcess().releaseClient(client, broken);
}
}
}
return null;
}
use of org.apache.zeppelin.resource.ResourcePool in project zeppelin by apache.
the class Paragraph method getInterpreterContextWithoutRunner.
private InterpreterContext getInterpreterContextWithoutRunner(InterpreterOutput output) {
AngularObjectRegistry registry = null;
ResourcePool resourcePool = null;
if (!interpreterSettingManager.getInterpreterSettings(note.getId()).isEmpty()) {
InterpreterSetting intpGroup = interpreterSettingManager.getInterpreterSettings(note.getId()).get(0);
registry = intpGroup.getInterpreterGroup(getUser(), note.getId()).getAngularObjectRegistry();
resourcePool = intpGroup.getInterpreterGroup(getUser(), note.getId()).getResourcePool();
}
List<InterpreterContextRunner> runners = new LinkedList<>();
final Paragraph self = this;
Credentials credentials = note.getCredentials();
if (authenticationInfo != null) {
UserCredentials userCredentials = credentials.getUserCredentials(authenticationInfo.getUser());
authenticationInfo.setUserCredentials(userCredentials);
}
InterpreterContext interpreterContext = new InterpreterContext(note.getId(), getId(), getRequiredReplName(), this.getTitle(), this.getText(), this.getAuthenticationInfo(), this.getConfig(), this.settings, registry, resourcePool, runners, output);
return interpreterContext;
}
use of org.apache.zeppelin.resource.ResourcePool in project zeppelin by apache.
the class Paragraph method getInterpreterContext.
private InterpreterContext getInterpreterContext(InterpreterOutput output) {
AngularObjectRegistry registry = null;
ResourcePool resourcePool = null;
if (!interpreterSettingManager.getInterpreterSettings(note.getId()).isEmpty()) {
InterpreterSetting intpGroup = interpreterSettingManager.getInterpreterSettings(note.getId()).get(0);
registry = intpGroup.getInterpreterGroup(getUser(), note.getId()).getAngularObjectRegistry();
resourcePool = intpGroup.getInterpreterGroup(getUser(), note.getId()).getResourcePool();
}
List<InterpreterContextRunner> runners = new LinkedList<>();
for (Paragraph p : note.getParagraphs()) {
runners.add(new ParagraphRunner(note, note.getId(), p.getId()));
}
final Paragraph self = this;
Credentials credentials = note.getCredentials();
if (authenticationInfo != null) {
UserCredentials userCredentials = credentials.getUserCredentials(authenticationInfo.getUser());
authenticationInfo.setUserCredentials(userCredentials);
}
InterpreterContext interpreterContext = new InterpreterContext(note.getId(), getId(), getRequiredReplName(), this.getTitle(), this.getText(), this.getAuthenticationInfo(), this.getConfig(), this.settings, registry, resourcePool, runners, output);
return interpreterContext;
}
Aggregations