use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class ApplicationLoader method findRequiredResourceSet.
static ResourceSet findRequiredResourceSet(String[][] requiredResources, String noteId, String paragraphId, ResourceSet resources) {
ResourceSet args = new ResourceSet();
if (requiredResources == null || requiredResources.length == 0) {
return args;
}
resources = resources.filterByNoteId(noteId).filterByParagraphId(paragraphId);
for (String[] requires : requiredResources) {
args.clear();
for (String require : requires) {
boolean found = false;
for (Resource r : resources) {
if (require.startsWith(":") && r.getClassName().equals(require.substring(1))) {
found = true;
} else if (r.getResourceId().getName().equals(require)) {
found = true;
}
if (found) {
args.add(r);
break;
}
}
if (found == false) {
break;
}
}
if (args.size() == requires.length) {
return args;
}
}
return null;
}
use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class AbstractInterpreter method interpolate.
static String interpolate(String cmd, ResourcePool resourcePool) {
StringBuilder sb = new StringBuilder();
Matcher m;
String st = cmd;
while ((m = VARIABLES.matcher(st)).matches()) {
sb.append(m.group(1));
String varPat = m.group(2);
if (VARIABLE_IN_BRACES.matcher(varPat).matches()) {
// substitute {variable} only if 'variable' has a value ...
Resource resource = resourcePool.get(varPat.substring(1, varPat.length() - 1));
Object variableValue = resource == null ? null : resource.get();
if (variableValue != null)
sb.append(variableValue);
else
return cmd;
} else if (VARIABLE_IN_DOUBLE_BRACES.matcher(varPat).matches()) {
// escape {{text}} ...
sb.append("{").append(varPat, 2, varPat.length() - 2).append("}");
} else {
// mismatched {{ }} or more than 2 braces ...
return cmd;
}
st = m.group(3);
}
sb.append(st);
return sb.toString();
}
use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class ZeppelinContext method get.
/**
* Get object from resource pool
* Search local process first and then the other processes
*
* @param name
* @param clazz The class of the returned value
* @return null if resource not found
*/
@ZeppelinApi
public <T> T get(String name, Class<T> clazz) {
ResourcePool resourcePool = interpreterContext.getResourcePool();
Resource resource = resourcePool.get(name);
if (resource != null) {
return resource.get(clazz);
} else {
return null;
}
}
use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class ZeppelinContext method get.
/**
* Get object from resource pool
* Search local process first and then the other processes
*
* @param name
* @return null if resource not found
*/
@ZeppelinApi
public Object get(String name) {
ResourcePool resourcePool = interpreterContext.getResourcePool();
Resource resource = resourcePool.get(name);
if (resource != null) {
return resource.get();
} else {
return null;
}
}
use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.
the class RemoteInterpreterEventClient method invokeMethod.
/**
* Invoke method and save result in resourcePool as another resource
*
* @param resourceId
* @param methodName
* @param paramTypes
* @param params
* @param returnResourceName
* @return
*/
@Override
public Resource invokeMethod(ResourceId resourceId, String methodName, Class[] paramTypes, Object[] params, String returnResourceName) {
LOGGER.debug("Request Invoke method {} of Resource {}", methodName, resourceId.getName());
InvokeResourceMethodEventMessage invokeMethod = new InvokeResourceMethodEventMessage(resourceId, methodName, paramTypes, params, returnResourceName);
try {
ByteBuffer serializedResource = callRemoteFunction(client -> client.invokeMethod(intpGroupId, invokeMethod.toJson()));
Resource deserializedResource = (Resource) Resource.deserializeObject(serializedResource);
RemoteResource remoteResource = RemoteResource.fromJson(GSON.toJson(deserializedResource));
remoteResource.setResourcePoolConnector(this);
return remoteResource;
} catch (IOException | ClassNotFoundException e) {
LOGGER.error("Failed to invoke method", e);
return null;
}
}
Aggregations