Search in sources :

Example 1 with RemoteResource

use of org.apache.zeppelin.resource.RemoteResource 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;
    }
}
Also used : RemoteResource(org.apache.zeppelin.resource.RemoteResource) Resource(org.apache.zeppelin.resource.Resource) RemoteResource(org.apache.zeppelin.resource.RemoteResource) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 2 with RemoteResource

use of org.apache.zeppelin.resource.RemoteResource in project zeppelin by apache.

the class RemoteInterpreterEventClient method getAllResources.

/**
 * Get all resources except for specific resourcePool
 *
 * @return
 */
@Override
public ResourceSet getAllResources() {
    try {
        List<String> resources = callRemoteFunction(client -> client.getAllResources(intpGroupId));
        ResourceSet resourceSet = new ResourceSet();
        for (String res : resources) {
            RemoteResource resource = RemoteResource.fromJson(res);
            resource.setResourcePoolConnector(this);
            resourceSet.add(resource);
        }
        return resourceSet;
    } catch (Exception e) {
        LOGGER.warn("Fail to getAllResources", e);
        return null;
    }
}
Also used : RemoteResource(org.apache.zeppelin.resource.RemoteResource) ResourceSet(org.apache.zeppelin.resource.ResourceSet) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 RemoteResource (org.apache.zeppelin.resource.RemoteResource)2 ByteBuffer (java.nio.ByteBuffer)1 TTransportException (org.apache.thrift.transport.TTransportException)1 Resource (org.apache.zeppelin.resource.Resource)1 ResourceSet (org.apache.zeppelin.resource.ResourceSet)1