use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class RemoteInterpreterServer method resourcePoolGetAll.
@Override
public List<String> resourcePoolGetAll() throws InterpreterRPCException, TException {
LOGGER.debug("Request resourcePoolGetAll from ZeppelinServer");
List<String> result = new LinkedList<>();
if (resourcePool == null) {
return result;
}
ResourceSet resourceSet = resourcePool.getAll(false);
for (Resource r : resourceSet) {
result.add(r.toJson());
}
return result;
}
use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class TableDataProxy method rows.
@Override
public Iterator<Row> rows() {
String resourceName = resource.getResourceId().getName() + ".rows";
Resource rows = resource.invokeMethod("rows", resourceName);
ProxyRowIterator it = new ProxyRowIterator(rows);
return it;
}
use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class InterpreterSettingManager method removeResourcesBelongsToParagraph.
public void removeResourcesBelongsToParagraph(String noteId, String paragraphId) {
for (ManagedInterpreterGroup intpGroup : getAllInterpreterGroup()) {
ResourceSet resourceSet = new ResourceSet();
RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
if (remoteInterpreterProcess == null) {
ResourcePool localPool = intpGroup.getResourcePool();
if (localPool != null) {
resourceSet.addAll(localPool.getAll());
}
if (noteId != null) {
resourceSet = resourceSet.filterByNoteId(noteId);
}
if (paragraphId != null) {
resourceSet = resourceSet.filterByParagraphId(paragraphId);
}
for (Resource r : resourceSet) {
localPool.remove(r.getResourceId().getNoteId(), r.getResourceId().getParagraphId(), r.getResourceId().getName());
}
} else if (remoteInterpreterProcess.isRunning()) {
try {
List<String> resourceList = remoteInterpreterProcess.callRemoteFunction(client -> client.resourcePoolGetAll());
for (String res : resourceList) {
resourceSet.add(Resource.fromJson(res));
}
if (noteId != null) {
resourceSet = resourceSet.filterByNoteId(noteId);
}
if (paragraphId != null) {
resourceSet = resourceSet.filterByParagraphId(paragraphId);
}
for (final Resource r : resourceSet) {
remoteInterpreterProcess.callRemoteFunction(client -> {
client.resourceRemove(r.getResourceId().getNoteId(), r.getResourceId().getParagraphId(), r.getResourceId().getName());
return null;
});
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
}
}
}
use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class RemoteInterpreterEventServer method getAllResources.
@Override
public List<String> getAllResources(String intpGroupId) throws InterpreterRPCException, TException {
ResourceSet resourceSet = getAllResourcePoolExcept(intpGroupId);
List<String> resourceList = new LinkedList<>();
for (Resource r : resourceSet) {
resourceList.add(r.toJson());
}
return resourceList;
}
use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class MockInterpreterResourcePool method interpret.
@Override
public InterpreterResult interpret(String st, InterpreterContext context) {
String[] stmt = st.split(" ");
String cmd = stmt[0];
String noteId = null;
String paragraphId = null;
String name = null;
if (stmt.length >= 2) {
String[] npn = stmt[1].split(":");
if (npn.length >= 3) {
noteId = npn[0];
paragraphId = npn[1];
name = npn[2];
} else {
name = stmt[1];
}
}
String value = null;
if (stmt.length >= 3) {
value = stmt[2];
}
ResourcePool resourcePool = context.getResourcePool();
Object ret = null;
if (cmd.equals("put")) {
resourcePool.put(noteId, paragraphId, name, value);
} else if (cmd.equalsIgnoreCase("get")) {
Resource resource = resourcePool.get(noteId, paragraphId, name);
if (resource != null) {
ret = resourcePool.get(noteId, paragraphId, name).get();
} else {
ret = "";
}
} else if (cmd.equals("remove")) {
ret = resourcePool.remove(noteId, paragraphId, name);
} else if (cmd.equals("getAll")) {
ret = resourcePool.getAll();
} else if (cmd.equals("invoke")) {
Resource resource = resourcePool.get(noteId, paragraphId, name);
LOGGER.info("Resource: " + resource);
if (stmt.length >= 4) {
Resource res = resource.invokeMethod(value, stmt[3]);
LOGGER.info("After invokeMethod: " + resource);
ret = res.get();
} else {
ret = resource.invokeMethod(value);
LOGGER.info("After invokeMethod: " + ret);
}
}
try {
// wait for watcher executed
Thread.sleep(500);
} catch (InterruptedException e) {
}
Gson gson = new Gson();
return new InterpreterResult(Code.SUCCESS, gson.toJson(ret));
}
Aggregations