Search in sources :

Example 16 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteInterpreterEventPoller method sendResourceResponseGet.

private void sendResourceResponseGet(ResourceId resourceId, Object o) {
    Client client = null;
    boolean broken = false;
    try {
        client = interpreterProcess.getClient();
        Gson gson = new Gson();
        String rid = gson.toJson(resourceId);
        ByteBuffer obj;
        if (o == null) {
            obj = ByteBuffer.allocate(0);
        } else {
            obj = Resource.serializeObject(o);
        }
        client.resourceResponseGet(rid, obj);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        broken = true;
    } finally {
        if (client != null) {
            interpreterProcess.releaseClient(client, broken);
        }
    }
}
Also used : Gson(com.google.gson.Gson) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) ByteBuffer(java.nio.ByteBuffer) TException(org.apache.thrift.TException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 17 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteInterpreterProcess method updateRemoteAngularObject.

/**
   * Called when angular object is updated in client side to propagate
   * change to the remote process
   * @param name
   * @param o
   */
public void updateRemoteAngularObject(String name, String noteId, String paragraphId, Object o) {
    Client client = null;
    try {
        client = getClient();
    } catch (NullPointerException e) {
        // remote process not started
        logger.info("NullPointerException in RemoteInterpreterProcess while " + "updateRemoteAngularObject getClient, remote process not started", e);
        return;
    } catch (Exception e) {
        logger.error("Can't update angular object", e);
    }
    boolean broken = false;
    try {
        Gson gson = new Gson();
        client.angularObjectUpdate(name, noteId, paragraphId, gson.toJson(o));
    } catch (TException e) {
        broken = true;
        logger.error("Can't update angular object", e);
    } catch (NullPointerException e) {
        logger.error("Remote interpreter process not started", e);
        return;
    } finally {
        if (client != null) {
            releaseClient(client, broken);
        }
    }
}
Also used : TException(org.apache.thrift.TException) Gson(com.google.gson.Gson) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Example 18 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteInterpreter method getProgress.

@Override
public int getProgress(InterpreterContext context) {
    RemoteInterpreterProcess interpreterProcess = getInterpreterProcess();
    if (interpreterProcess == null || !interpreterProcess.isRunning()) {
        return 0;
    }
    Client client = null;
    try {
        client = interpreterProcess.getClient();
    } catch (Exception e1) {
        throw new InterpreterException(e1);
    }
    boolean broken = false;
    try {
        return client.getProgress(sessionKey, className, convert(context));
    } catch (TException e) {
        broken = true;
        throw new InterpreterException(e);
    } finally {
        interpreterProcess.releaseClient(client, broken);
    }
}
Also used : TException(org.apache.thrift.TException) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Example 19 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteInterpreter method init.

public synchronized void init() {
    if (initialized == true) {
        return;
    }
    RemoteInterpreterProcess interpreterProcess = getInterpreterProcess();
    final InterpreterGroup interpreterGroup = getInterpreterGroup();
    interpreterProcess.reference(interpreterGroup, userName, isUserImpersonate);
    interpreterProcess.setMaxPoolSize(Math.max(this.maxPoolSize, interpreterProcess.getMaxPoolSize()));
    String groupId = interpreterGroup.getId();
    synchronized (interpreterProcess) {
        Client client = null;
        try {
            client = interpreterProcess.getClient();
        } catch (Exception e1) {
            throw new InterpreterException(e1);
        }
        boolean broken = false;
        try {
            logger.info("Create remote interpreter {}", getClassName());
            if (localRepoPath != null) {
                property.put("zeppelin.interpreter.localRepo", localRepoPath);
            }
            property.put("zeppelin.interpreter.output.limit", Integer.toString(outputLimit));
            client.createInterpreter(groupId, sessionKey, getClassName(), (Map) property, userName);
            // Push angular object loaded from JSON file to remote interpreter
            if (!interpreterGroup.isAngularRegistryPushed()) {
                pushAngularObjectRegistryToRemote(client);
                interpreterGroup.setAngularRegistryPushed(true);
            }
        } catch (TException e) {
            logger.error("Failed to create interpreter: {}", getClassName());
            throw new InterpreterException(e);
        } finally {
            // TODO(jongyoul): Fixed it when not all of interpreter in same interpreter group are broken
            interpreterProcess.releaseClient(client, broken);
        }
    }
    initialized = true;
}
Also used : TException(org.apache.thrift.TException) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Example 20 with Client

use of org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client in project zeppelin by apache.

the class RemoteInterpreterProcessTest method testClientFactory.

@Test
public void testClientFactory() throws Exception {
    InterpreterGroup intpGroup = new InterpreterGroup();
    RemoteInterpreterManagedProcess rip = new RemoteInterpreterManagedProcess(INTERPRETER_SCRIPT, "nonexists", "fakeRepo", new HashMap<String, String>(), mock(RemoteInterpreterEventPoller.class), 10 * 1000, "fakeName");
    rip.reference(intpGroup, "anonymous", false);
    assertEquals(0, rip.getNumActiveClient());
    assertEquals(0, rip.getNumIdleClient());
    Client client = rip.getClient();
    assertEquals(1, rip.getNumActiveClient());
    assertEquals(0, rip.getNumIdleClient());
    rip.releaseClient(client);
    assertEquals(0, rip.getNumActiveClient());
    assertEquals(1, rip.getNumIdleClient());
    rip.dereference();
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) Test(org.junit.Test)

Aggregations

Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)22 TException (org.apache.thrift.TException)19 Gson (com.google.gson.Gson)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 AngularObject (org.apache.zeppelin.display.AngularObject)6 ByteBuffer (java.nio.ByteBuffer)4 LinkedList (java.util.LinkedList)4 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)4 RemoteZeppelinServerResource (org.apache.zeppelin.interpreter.RemoteZeppelinServerResource)4 List (java.util.List)3 Map (java.util.Map)3 ResourcePool (org.apache.zeppelin.resource.ResourcePool)3 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 InterpreterContextRunner (org.apache.zeppelin.interpreter.InterpreterContextRunner)2 Resource (org.apache.zeppelin.resource.Resource)2 ResourceId (org.apache.zeppelin.resource.ResourceId)2 ResourceSet (org.apache.zeppelin.resource.ResourceSet)2 Test (org.junit.Test)2 TypeToken (com.google.gson.reflect.TypeToken)1 HashMap (java.util.HashMap)1