use of org.apache.zeppelin.resource.ResourcePool in project zeppelin by apache.
the class Neo4jConnectionManager method execute.
public List<Record> execute(String cypherQuery, InterpreterContext interpreterContext) {
Map<String, Object> params = new HashMap<>();
if (interpreterContext != null) {
ResourcePool resourcePool = interpreterContext.getResourcePool();
Set<String> keys = extractParams(cypherQuery, PROPERTY_PATTERN, REPLACE_CURLY_BRACKETS);
keys.addAll(extractParams(cypherQuery, $_PATTERN, REPLACE_$));
for (String key : keys) {
Resource resource = resourcePool.get(key);
if (resource != null) {
params.put(key, resource.get());
}
}
}
LOGGER.debug("Executing cypher query {} with params {}", cypherQuery, params);
try (Session session = getSession()) {
final Result result = params.isEmpty() ? session.run(cypherQuery) : session.run(cypherQuery, params);
return result.list();
}
}
use of org.apache.zeppelin.resource.ResourcePool 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;
}
use of org.apache.zeppelin.resource.ResourcePool in project zeppelin by apache.
the class ZeppelinContext method remove.
/**
* Remove object from resourcePool
*
* @param name
*/
@ZeppelinApi
public void remove(String name) {
ResourcePool resourcePool = interpreterContext.getResourcePool();
resourcePool.remove(name);
}
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 SSM by Intel-bigdata.
the class RemoteInterpreterEventPoller method getAllResourcePoolExcept.
private ResourceSet getAllResourcePoolExcept() {
ResourceSet resourceSet = new ResourceSet();
for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) {
if (intpGroup.getId().equals(interpreterGroup.getId())) {
continue;
}
RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
if (remoteInterpreterProcess == null) {
ResourcePool localPool = intpGroup.getResourcePool();
if (localPool != null) {
resourceSet.addAll(localPool.getAll());
}
} else if (interpreterProcess.isRunning()) {
Client client = null;
boolean broken = false;
try {
client = remoteInterpreterProcess.getClient();
List<String> resourceList = client.resourcePoolGetAll();
Gson gson = new Gson();
for (String res : resourceList) {
resourceSet.add(gson.fromJson(res, Resource.class));
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
broken = true;
} finally {
if (client != null) {
intpGroup.getRemoteInterpreterProcess().releaseClient(client, broken);
}
}
}
}
return resourceSet;
}
Aggregations