Search in sources :

Example 1 with ResourcePool

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);
    }
}
Also used : ResourcePool(org.apache.zeppelin.resource.ResourcePool)

Example 2 with ResourcePool

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;
}
Also used : Resource(org.apache.zeppelin.resource.Resource) ResourcePool(org.apache.zeppelin.resource.ResourcePool) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 3 with ResourcePool

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;
}
Also used : ResourceId(org.apache.zeppelin.resource.ResourceId) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Resource(org.apache.zeppelin.resource.Resource) RemoteZeppelinServerResource(org.apache.zeppelin.interpreter.RemoteZeppelinServerResource) ResourcePool(org.apache.zeppelin.resource.ResourcePool) AngularObject(org.apache.zeppelin.display.AngularObject) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) ByteBuffer(java.nio.ByteBuffer) TException(org.apache.thrift.TException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ResourcePool

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;
}
Also used : ResourcePool(org.apache.zeppelin.resource.ResourcePool) UserCredentials(org.apache.zeppelin.user.UserCredentials) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) UserCredentials(org.apache.zeppelin.user.UserCredentials) Credentials(org.apache.zeppelin.user.Credentials)

Example 5 with ResourcePool

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;
}
Also used : ResourcePool(org.apache.zeppelin.resource.ResourcePool) UserCredentials(org.apache.zeppelin.user.UserCredentials) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) UserCredentials(org.apache.zeppelin.user.UserCredentials) Credentials(org.apache.zeppelin.user.Credentials)

Aggregations

ResourcePool (org.apache.zeppelin.resource.ResourcePool)27 Resource (org.apache.zeppelin.resource.Resource)11 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)9 Gson (com.google.gson.Gson)6 TException (org.apache.thrift.TException)6 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)6 ResourceSet (org.apache.zeppelin.resource.ResourceSet)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)5 Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)5 ByteBuffer (java.nio.ByteBuffer)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 AngularObject (org.apache.zeppelin.display.AngularObject)4 Credentials (org.apache.zeppelin.user.Credentials)4 UserCredentials (org.apache.zeppelin.user.UserCredentials)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 TypeToken (com.google.gson.reflect.TypeToken)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2