Search in sources :

Example 1 with InterpreterGroup

use of org.apache.zeppelin.interpreter.InterpreterGroup 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 2 with InterpreterGroup

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

the class RemoteInterpreterProcessTest method testStartStopRemoteInterpreter.

@Test
public void testStartStopRemoteInterpreter() throws TException, InterruptedException {
    RemoteInterpreterServer server = new RemoteInterpreterServer(3678);
    server.start();
    boolean running = false;
    long startTime = System.currentTimeMillis();
    while (System.currentTimeMillis() - startTime < 10 * 1000) {
        if (server.isRunning()) {
            running = true;
            break;
        } else {
            Thread.sleep(200);
        }
    }
    Properties properties = new Properties();
    properties.setProperty(Constants.ZEPPELIN_INTERPRETER_PORT, "3678");
    properties.setProperty(Constants.ZEPPELIN_INTERPRETER_HOST, "localhost");
    InterpreterGroup intpGroup = mock(InterpreterGroup.class);
    when(intpGroup.getProperty()).thenReturn(properties);
    when(intpGroup.containsKey(Constants.EXISTING_PROCESS)).thenReturn(true);
    RemoteInterpreterProcess rip = new RemoteInterpreterManagedProcess(INTERPRETER_SCRIPT, "nonexists", "fakeRepo", new HashMap<String, String>(), mock(RemoteInterpreterEventPoller.class), 10 * 1000, "fakeName");
    assertFalse(rip.isRunning());
    assertEquals(0, rip.referenceCount());
    assertEquals(1, rip.reference(intpGroup, "anonymous", false));
    assertEquals(true, rip.isRunning());
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with InterpreterGroup

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

the class MockInterpreterB method getInterpreterA.

public MockInterpreterA getInterpreterA() {
    InterpreterGroup interpreterGroup = getInterpreterGroup();
    synchronized (interpreterGroup) {
        for (List<Interpreter> interpreters : interpreterGroup.values()) {
            boolean belongsToSameNoteGroup = false;
            MockInterpreterA a = null;
            for (Interpreter intp : interpreters) {
                if (intp.getClassName().equals(MockInterpreterA.class.getName())) {
                    Interpreter p = intp;
                    while (p instanceof WrappedInterpreter) {
                        p = ((WrappedInterpreter) p).getInnerInterpreter();
                    }
                    a = (MockInterpreterA) p;
                }
                Interpreter p = intp;
                while (p instanceof WrappedInterpreter) {
                    p = ((WrappedInterpreter) p).getInnerInterpreter();
                }
                if (this == p) {
                    belongsToSameNoteGroup = true;
                }
            }
            if (belongsToSameNoteGroup) {
                return a;
            }
        }
    }
    return null;
}
Also used : WrappedInterpreter(org.apache.zeppelin.interpreter.WrappedInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) WrappedInterpreter(org.apache.zeppelin.interpreter.WrappedInterpreter) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup)

Example 4 with InterpreterGroup

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

the class NotebookServer method angularObjectClientUnbind.

/**
   * Remove the given Angular variable to the target
   * interpreter(s) angular registry given a noteId
   * and an optional list of paragraph id(s)
   */
protected void angularObjectClientUnbind(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws Exception {
    String noteId = fromMessage.getType("noteId");
    String varName = fromMessage.getType("name");
    String paragraphId = fromMessage.getType("paragraphId");
    Note note = notebook.getNote(noteId);
    if (paragraphId == null) {
        throw new IllegalArgumentException("target paragraph not specified for " + "angular value unBind");
    }
    if (note != null) {
        final InterpreterGroup interpreterGroup = findInterpreterGroupForParagraph(note, paragraphId);
        final AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
        if (registry instanceof RemoteAngularObjectRegistry) {
            RemoteAngularObjectRegistry remoteRegistry = (RemoteAngularObjectRegistry) registry;
            removeAngularFromRemoteRegistry(noteId, paragraphId, varName, remoteRegistry, interpreterGroup.getId(), conn);
        } else {
            removeAngularObjectFromLocalRepo(noteId, paragraphId, varName, 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) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 5 with InterpreterGroup

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

the class BigQueryInterpreterTest method setUp.

@Before
public void setUp() throws Exception {
    Properties p = new Properties();
    p.setProperty("zeppelin.bigquery.project_id", constants.getProjectId());
    p.setProperty("zeppelin.bigquery.wait_time", "5000");
    p.setProperty("zeppelin.bigquery.max_no_of_rows", "100");
    p.setProperty("zeppelin.bigquery.sql_dialect", "");
    intpGroup = new InterpreterGroup();
    bqInterpreter = new BigQueryInterpreter(p);
    bqInterpreter.setInterpreterGroup(intpGroup);
    bqInterpreter.open();
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Properties(java.util.Properties) Before(org.junit.Before)

Aggregations

InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)74 Properties (java.util.Properties)30 Interpreter (org.apache.zeppelin.interpreter.Interpreter)27 Test (org.junit.Test)26 LazyOpenInterpreter (org.apache.zeppelin.interpreter.LazyOpenInterpreter)23 Before (org.junit.Before)19 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)18 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)17 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)14 IOException (java.io.IOException)12 TException (org.apache.thrift.TException)12 AngularObject (org.apache.zeppelin.display.AngularObject)12 List (java.util.List)10 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)10 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)10 Note (org.apache.zeppelin.notebook.Note)9 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)8 Paragraph (org.apache.zeppelin.notebook.Paragraph)8 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)7 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)7