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);
}
}
}
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;
}
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));
}
}
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);
}
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);
}
Aggregations