Search in sources :

Example 6 with ResourcePool

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();
    }
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.zeppelin.resource.Resource) ResourcePool(org.apache.zeppelin.resource.ResourcePool) Session(org.neo4j.driver.Session) Result(org.neo4j.driver.Result)

Example 7 with ResourcePool

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;
}
Also used : RegisterInfo(org.apache.zeppelin.interpreter.thrift.RegisterInfo) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) RemoteInterpreterEventService(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventService) TypeToken(com.google.gson.reflect.TypeToken) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ScheduledFuture(java.util.concurrent.ScheduledFuture) AppendOutputRunner(org.apache.zeppelin.interpreter.remote.AppendOutputRunner) Resource(org.apache.zeppelin.resource.Resource) TTransportException(org.apache.thrift.transport.TTransportException) LoggerFactory(org.slf4j.LoggerFactory) ResourcePool(org.apache.zeppelin.resource.ResourcePool) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) StringUtils(org.apache.commons.lang3.StringUtils) ByteBuffer(java.nio.ByteBuffer) LibraryMetadata(org.apache.zeppelin.interpreter.thrift.LibraryMetadata) ParagraphInfo(org.apache.zeppelin.interpreter.thrift.ParagraphInfo) Gson(com.google.gson.Gson) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) Map(java.util.Map) AngularObject(org.apache.zeppelin.display.AngularObject) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) Collection(java.util.Collection) Executors(java.util.concurrent.Executors) List(java.util.List) OutputAppendEvent(org.apache.zeppelin.interpreter.thrift.OutputAppendEvent) WebUrlInfo(org.apache.zeppelin.interpreter.thrift.WebUrlInfo) OutputUpdateEvent(org.apache.zeppelin.interpreter.thrift.OutputUpdateEvent) RemoteInterpreterUtils(org.apache.zeppelin.interpreter.remote.RemoteInterpreterUtils) RemoteInterpreterProcessListener(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener) ArrayList(java.util.ArrayList) RunParagraphsEvent(org.apache.zeppelin.interpreter.thrift.RunParagraphsEvent) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) LinkedList(java.util.LinkedList) RemoteInterpreterResultMessage(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage) ResourceSet(org.apache.zeppelin.resource.ResourceSet) OutputUpdateAllEvent(org.apache.zeppelin.interpreter.thrift.OutputUpdateAllEvent) Logger(org.slf4j.Logger) ApplicationEventListener(org.apache.zeppelin.helium.ApplicationEventListener) AppOutputAppendEvent(org.apache.zeppelin.interpreter.thrift.AppOutputAppendEvent) ResourceId(org.apache.zeppelin.resource.ResourceId) Note(org.apache.zeppelin.notebook.Note) TException(org.apache.thrift.TException) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) TServerSocket(org.apache.thrift.transport.TServerSocket) RemoteResource(org.apache.zeppelin.resource.RemoteResource) AppStatusUpdateEvent(org.apache.zeppelin.interpreter.thrift.AppStatusUpdateEvent) InvokeResourceMethodEventMessage(org.apache.zeppelin.interpreter.remote.InvokeResourceMethodEventMessage) AppOutputUpdateEvent(org.apache.zeppelin.interpreter.thrift.AppOutputUpdateEvent) Collections(java.util.Collections) ResourceId(org.apache.zeppelin.resource.ResourceId) Resource(org.apache.zeppelin.resource.Resource) RemoteResource(org.apache.zeppelin.resource.RemoteResource) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ResourcePool(org.apache.zeppelin.resource.ResourcePool) ByteBuffer(java.nio.ByteBuffer) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 8 with ResourcePool

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

Example 9 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 10 with ResourcePool

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;
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Gson(com.google.gson.Gson) ResourcePool(org.apache.zeppelin.resource.ResourcePool) LinkedList(java.util.LinkedList) List(java.util.List) ResourceSet(org.apache.zeppelin.resource.ResourceSet) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

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