Search in sources :

Example 16 with InterpreterGroup

use of org.apache.zeppelin.interpreter.InterpreterGroup in project zeppelin by apache.

the class RemoteInterpreterProcessTest method testStartStop.

@Test
public void testStartStop() {
    InterpreterGroup intpGroup = new InterpreterGroup();
    RemoteInterpreterManagedProcess rip = new RemoteInterpreterManagedProcess(INTERPRETER_SCRIPT, "nonexists", "fakeRepo", new HashMap<String, String>(), 10 * 1000, null, null, "fakeName");
    assertFalse(rip.isRunning());
    assertEquals(0, rip.referenceCount());
    assertEquals(1, rip.reference(intpGroup, "anonymous", false));
    assertEquals(2, rip.reference(intpGroup, "anonymous", false));
    assertEquals(true, rip.isRunning());
    assertEquals(1, rip.dereference());
    assertEquals(true, rip.isRunning());
    assertEquals(0, rip.dereference());
    assertEquals(false, rip.isRunning());
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Test(org.junit.Test)

Example 17 with InterpreterGroup

use of org.apache.zeppelin.interpreter.InterpreterGroup in project zeppelin by apache.

the class RemoteInterpreterProcessTest method testPropagateError.

@Test
public void testPropagateError() throws TException, InterruptedException {
    InterpreterGroup intpGroup = new InterpreterGroup();
    RemoteInterpreterManagedProcess rip = new RemoteInterpreterManagedProcess("echo hello_world", "nonexists", "fakeRepo", new HashMap<String, String>(), 10 * 1000, null, null, "fakeName");
    assertFalse(rip.isRunning());
    assertEquals(0, rip.referenceCount());
    try {
        assertEquals(1, rip.reference(intpGroup, "anonymous", false));
    } catch (InterpreterException e) {
        e.getMessage().contains("hello_world");
    }
    assertEquals(0, rip.referenceCount());
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) Test(org.junit.Test)

Example 18 with InterpreterGroup

use of org.apache.zeppelin.interpreter.InterpreterGroup in project zeppelin by apache.

the class ResourcePoolUtils method getAllResourcesExcept.

public static ResourceSet getAllResourcesExcept(String interpreterGroupExcludsion) {
    ResourceSet resourceSet = new ResourceSet();
    for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) {
        if (interpreterGroupExcludsion != null && intpGroup.getId().equals(interpreterGroupExcludsion)) {
            continue;
        }
        RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
        if (remoteInterpreterProcess == null) {
            ResourcePool localPool = intpGroup.getResourcePool();
            if (localPool != null) {
                resourceSet.addAll(localPool.getAll());
            }
        } else if (remoteInterpreterProcess.isRunning()) {
            RemoteInterpreterService.Client client = null;
            boolean broken = false;
            try {
                client = remoteInterpreterProcess.getClient();
                if (client == null) {
                    // remote interpreter may not started yet or terminated.
                    continue;
                }
                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) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) List(java.util.List)

Example 19 with InterpreterGroup

use of org.apache.zeppelin.interpreter.InterpreterGroup in project zeppelin by apache.

the class ResourcePoolUtils method removeResourcesBelongsToParagraph.

public static void removeResourcesBelongsToParagraph(String noteId, String paragraphId) {
    for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) {
        ResourceSet resourceSet = new ResourceSet();
        RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
        if (remoteInterpreterProcess == null) {
            ResourcePool localPool = intpGroup.getResourcePool();
            if (localPool != null) {
                resourceSet.addAll(localPool.getAll());
            }
            if (noteId != null) {
                resourceSet = resourceSet.filterByNoteId(noteId);
            }
            if (paragraphId != null) {
                resourceSet = resourceSet.filterByParagraphId(paragraphId);
            }
            for (Resource r : resourceSet) {
                localPool.remove(r.getResourceId().getNoteId(), r.getResourceId().getParagraphId(), r.getResourceId().getName());
            }
        } else if (remoteInterpreterProcess.isRunning()) {
            RemoteInterpreterService.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));
                }
                if (noteId != null) {
                    resourceSet = resourceSet.filterByNoteId(noteId);
                }
                if (paragraphId != null) {
                    resourceSet = resourceSet.filterByParagraphId(paragraphId);
                }
                for (Resource r : resourceSet) {
                    client.resourceRemove(r.getResourceId().getNoteId(), r.getResourceId().getParagraphId(), r.getResourceId().getName());
                }
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                broken = true;
            } finally {
                if (client != null) {
                    intpGroup.getRemoteInterpreterProcess().releaseClient(client, broken);
                }
            }
        }
    }
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Gson(com.google.gson.Gson) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) List(java.util.List)

Example 20 with InterpreterGroup

use of org.apache.zeppelin.interpreter.InterpreterGroup in project zeppelin by apache.

the class NotebookServer method angularObjectClientBind.

/**
   * Push the given Angular variable to the target
   * interpreter angular registry given a noteId
   * and a paragraph id
   */
protected void angularObjectClientBind(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws Exception {
    String noteId = fromMessage.getType("noteId");
    String varName = fromMessage.getType("name");
    Object varValue = fromMessage.get("value");
    String paragraphId = fromMessage.getType("paragraphId");
    Note note = notebook.getNote(noteId);
    if (paragraphId == null) {
        throw new IllegalArgumentException("target paragraph not specified for " + "angular value bind");
    }
    if (note != null) {
        final InterpreterGroup interpreterGroup = findInterpreterGroupForParagraph(note, paragraphId);
        final AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
        if (registry instanceof RemoteAngularObjectRegistry) {
            RemoteAngularObjectRegistry remoteRegistry = (RemoteAngularObjectRegistry) registry;
            pushAngularObjectToRemoteRegistry(noteId, paragraphId, varName, varValue, remoteRegistry, interpreterGroup.getId(), conn);
        } else {
            pushAngularObjectToLocalRepo(noteId, paragraphId, varName, varValue, registry, interpreterGroup.getId(), conn);
        }
    }
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Note(org.apache.zeppelin.notebook.Note) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) JsonObject(com.google.gson.JsonObject) AngularObject(org.apache.zeppelin.display.AngularObject) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Aggregations

InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)25 Test (org.junit.Test)10 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)9 Note (org.apache.zeppelin.notebook.Note)7 Properties (java.util.Properties)6 Interpreter (org.apache.zeppelin.interpreter.Interpreter)6 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)6 Before (org.junit.Before)6 LinkedList (java.util.LinkedList)5 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)5 Paragraph (org.apache.zeppelin.notebook.Paragraph)5 Message (org.apache.zeppelin.notebook.socket.Message)5 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)5 HashMap (java.util.HashMap)4 GUI (org.apache.zeppelin.display.GUI)4 Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)4 Notebook (org.apache.zeppelin.notebook.Notebook)4 ResourcePool (org.apache.zeppelin.resource.ResourcePool)4 Gson (com.google.gson.Gson)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3