Search in sources :

Example 21 with Resource

use of org.apache.zeppelin.resource.Resource in project SSM by Intel-bigdata.

the class RemoteInterpreterEventPoller method sendResourcePoolResponseGetAll.

private void sendResourcePoolResponseGetAll(ResourceSet resourceSet) {
    Client client = null;
    boolean broken = false;
    try {
        client = interpreterProcess.getClient();
        List<String> resourceList = new LinkedList<>();
        Gson gson = new Gson();
        for (Resource r : resourceSet) {
            resourceList.add(gson.toJson(r));
        }
        client.resourcePoolResponseGetAll(resourceList);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        broken = true;
    } finally {
        if (client != null) {
            interpreterProcess.releaseClient(client, broken);
        }
    }
}
Also used : Resource(org.apache.zeppelin.resource.Resource) RemoteZeppelinServerResource(org.apache.zeppelin.interpreter.RemoteZeppelinServerResource) Gson(com.google.gson.Gson) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) LinkedList(java.util.LinkedList) TException(org.apache.thrift.TException)

Example 22 with Resource

use of org.apache.zeppelin.resource.Resource in project SSM by Intel-bigdata.

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();
    }
    try {
        // wait for watcher executed
        Thread.sleep(500);
    } catch (InterruptedException e) {
    }
    Gson gson = new Gson();
    return new InterpreterResult(Code.SUCCESS, gson.toJson(ret));
}
Also used : Resource(org.apache.zeppelin.resource.Resource) Gson(com.google.gson.Gson) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) ResourcePool(org.apache.zeppelin.resource.ResourcePool)

Example 23 with Resource

use of org.apache.zeppelin.resource.Resource in project SSM by Intel-bigdata.

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

Aggregations

Resource (org.apache.zeppelin.resource.Resource)23 ResourcePool (org.apache.zeppelin.resource.ResourcePool)11 Gson (com.google.gson.Gson)6 IOException (java.io.IOException)6 LinkedList (java.util.LinkedList)6 ResourceSet (org.apache.zeppelin.resource.ResourceSet)6 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)5 ByteBuffer (java.nio.ByteBuffer)4 TException (org.apache.thrift.TException)4 AngularObject (org.apache.zeppelin.display.AngularObject)3 TypeToken (com.google.gson.reflect.TypeToken)2 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 TTransportException (org.apache.thrift.transport.TTransportException)2 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)2