Search in sources :

Example 6 with Gson

use of com.google.gson.Gson in project zeppelin by apache.

the class RemoteInterpreterEventPoller method sendInvokeMethodResult.

public void sendInvokeMethodResult(InvokeResourceMethodEventMessage message, Object o) {
    Client client = null;
    boolean broken = false;
    try {
        client = interpreterProcess.getClient();
        Gson gson = new Gson();
        String invokeMessage = gson.toJson(message);
        ByteBuffer obj;
        if (o == null) {
            obj = ByteBuffer.allocate(0);
        } else {
            obj = Resource.serializeObject(o);
        }
        client.resourceResponseInvokeMethod(invokeMessage, 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 7 with Gson

use of com.google.gson.Gson in project zeppelin by apache.

the class RemoteAngularObjectRegistry method addAndNotifyRemoteProcess.

/**
   * When ZeppelinServer side code want to add angularObject to the registry,
   * this method should be used instead of add()
   * @param name
   * @param o
   * @param noteId
   * @return
   */
public AngularObject addAndNotifyRemoteProcess(String name, Object o, String noteId, String paragraphId) {
    Gson gson = new Gson();
    RemoteInterpreterProcess remoteInterpreterProcess = getRemoteInterpreterProcess();
    if (!remoteInterpreterProcess.isRunning()) {
        return super.add(name, o, noteId, paragraphId, true);
    }
    Client client = null;
    boolean broken = false;
    try {
        client = remoteInterpreterProcess.getClient();
        client.angularObjectAdd(name, noteId, paragraphId, gson.toJson(o));
        return super.add(name, o, noteId, paragraphId, true);
    } catch (TException e) {
        broken = true;
        logger.error("Error", e);
    } catch (Exception e) {
        logger.error("Error", e);
    } finally {
        if (client != null) {
            remoteInterpreterProcess.releaseClient(client, broken);
        }
    }
    return null;
}
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 8 with Gson

use of com.google.gson.Gson in project zeppelin by apache.

the class RemoteInterpreter method pushAngularObjectRegistryToRemote.

/**
   * Push local angular object registry to
   * remote interpreter. This method should be
   * call ONLY inside the init() method
   */
void pushAngularObjectRegistryToRemote(Client client) throws TException {
    final AngularObjectRegistry angularObjectRegistry = this.getInterpreterGroup().getAngularObjectRegistry();
    if (angularObjectRegistry != null && angularObjectRegistry.getRegistry() != null) {
        final Map<String, Map<String, AngularObject>> registry = angularObjectRegistry.getRegistry();
        logger.info("Push local angular object registry from ZeppelinServer to" + " remote interpreter group {}", this.getInterpreterGroup().getId());
        final java.lang.reflect.Type registryType = new TypeToken<Map<String, Map<String, AngularObject>>>() {
        }.getType();
        Gson gson = new Gson();
        client.angularRegistryPush(gson.toJson(registry, registryType));
    }
}
Also used : Gson(com.google.gson.Gson) AngularObject(org.apache.zeppelin.display.AngularObject) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 9 with Gson

use of com.google.gson.Gson in project zeppelin by apache.

the class JsonResponse method toString.

@Override
public String toString() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    if (pretty) {
        gsonBuilder.setPrettyPrinting();
    }
    gsonBuilder.setExclusionStrategies(new JsonExclusionStrategy());
    Gson gson = gsonBuilder.create();
    return gson.toJson(this);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Example 10 with Gson

use of com.google.gson.Gson in project zeppelin by apache.

the class RemoteInterpreterTest method should_push_local_angular_repo_to_remote.

@Test
public void should_push_local_angular_repo_to_remote() throws Exception {
    //Given
    final Client client = Mockito.mock(Client.class);
    final RemoteInterpreter intr = new RemoteInterpreter(new Properties(), "noteId", MockInterpreterA.class.getName(), "runner", "path", "localRepo", env, 10 * 1000, null, null, "anonymous", false);
    final AngularObjectRegistry registry = new AngularObjectRegistry("spark", null);
    registry.add("name", "DuyHai DOAN", "nodeId", "paragraphId");
    final InterpreterGroup interpreterGroup = new InterpreterGroup("groupId");
    interpreterGroup.setAngularObjectRegistry(registry);
    intr.setInterpreterGroup(interpreterGroup);
    final java.lang.reflect.Type registryType = new TypeToken<Map<String, Map<String, AngularObject>>>() {
    }.getType();
    final Gson gson = new Gson();
    final String expected = gson.toJson(registry.getRegistry(), registryType);
    //When
    intr.pushAngularObjectRegistryToRemote(client);
    //Then
    Mockito.verify(client).angularRegistryPush(expected);
}
Also used : Gson(com.google.gson.Gson) AngularObject(org.apache.zeppelin.display.AngularObject) Properties(java.util.Properties) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) MockInterpreterA(org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA) HashMap(java.util.HashMap) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1060 Test (org.junit.Test)236 HashMap (java.util.HashMap)200 JsonObject (com.google.gson.JsonObject)138 GsonBuilder (com.google.gson.GsonBuilder)135 CommandWrapper (ClientServerApi.CommandWrapper)123 CommandExecuter (CommandHandler.CommandExecuter)119 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)118 IOException (java.io.IOException)116 JsonSyntaxException (com.google.gson.JsonSyntaxException)100 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)96 ArrayList (java.util.ArrayList)94 Type (java.lang.reflect.Type)65 JsonElement (com.google.gson.JsonElement)57 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)53 SmartCode (BasicCommonClasses.SmartCode)50 Map (java.util.Map)45 InputStreamReader (java.io.InputStreamReader)41 BroadcastClientMessage (org.bigbluebutton.red5.client.messaging.BroadcastClientMessage)41 Location (BasicCommonClasses.Location)40