use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class RemoteInterpreter method pushAngularObjectRegistryToRemote.
/**
* Push local angular object registry to
* remote interpreter. This method should be
* call ONLY once when the first Interpreter is created
*/
private 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();
client.angularRegistryPush(GSON.toJson(registry, registryType));
}
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class RemoteInterpreterServer method angularObjectAdd.
/**
* When zeppelinserver initiate angular object add.
* Dont't need to emit event to zeppelin server
*/
@Override
public void angularObjectAdd(String name, String noteId, String paragraphId, String object) throws InterpreterRPCException, TException {
AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
// first try local objects
AngularObject ao = registry.get(name, noteId, paragraphId);
if (ao != null) {
angularObjectUpdate(name, noteId, paragraphId, object);
return;
}
// Generic java object type for json.
Object value = null;
try {
value = gson.fromJson(object, new TypeToken<Map<String, Object>>() {
}.getType());
} catch (Exception e) {
// it's okay. proceed to treat object as a string
LOGGER.debug(e.getMessage(), e);
}
// try string object type at last
if (value == null) {
value = gson.fromJson(object, String.class);
}
registry.add(name, value, noteId, paragraphId, false);
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class RemoteInterpreterServer method angularObjectUpdate.
/**
* called when object is updated in client (web) side.
*
* @param name
* @param noteId noteId where the update issues
* @param paragraphId paragraphId where the update issues
* @param object
* @throws InterpreterRPCException, TException
*/
@Override
public void angularObjectUpdate(String name, String noteId, String paragraphId, String object) throws InterpreterRPCException, TException {
AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
// first try local objects
AngularObject ao = registry.get(name, noteId, paragraphId);
if (ao == null) {
LOGGER.debug("Angular object {} not exists", name);
return;
}
if (object == null) {
ao.set(null, false);
return;
}
Object oldObject = ao.get();
Object value = null;
if (oldObject != null) {
// first try with previous object's type
try {
value = gson.fromJson(object, oldObject.getClass());
ao.set(value, false);
return;
} catch (Exception e) {
// it's not a previous object's type. proceed to treat as a generic type
LOGGER.debug(e.getMessage(), e);
}
}
// Generic java object type for json.
if (value == null) {
try {
value = gson.fromJson(object, new TypeToken<Map<String, Object>>() {
}.getType());
} catch (Exception e) {
// it's not a generic json object, too. okay, proceed to threat as a string type
LOGGER.debug(e.getMessage(), e);
}
}
// try string object type at last
if (value == null) {
value = gson.fromJson(object, String.class);
}
ao.set(value, false);
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class ZeppelinContext method getAngularObject.
private AngularObject getAngularObject(String name, String noteId, String paragraphId, InterpreterContext interpreterContext) {
AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
AngularObject ao = registry.get(name, noteId, paragraphId);
return ao;
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class NoteTest method testNoteJson.
public void testNoteJson() throws IOException {
Note note = new Note("test", "", interpreterFactory, interpreterSettingManager, paragraphJobListener, credentials, noteEventListener);
note.setName("/test_note");
note.getConfig().put("config_1", "value_1");
note.getInfo().put("info_1", "value_1");
String pText = "%spark sc.version";
Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p.setText(pText);
p.setResult(new InterpreterResult(InterpreterResult.Code.SUCCESS, "1.6.2"));
p.settings.getForms().put("textbox_1", new TextBox("name", "default_name"));
p.settings.getParams().put("textbox_1", "my_name");
note.getAngularObjects().put("ao_1", Arrays.asList(new AngularObject("name_1", "value_1", note.getId(), p.getId(), null)));
// test Paragraph Json
Paragraph p2 = Paragraph.fromJson(p.toJson());
assertEquals(p2.settings, p.settings);
assertEquals(p2, p);
// test Note Json
Note note2 = Note.fromJson(null, note.toJson());
assertEquals(note2, note);
}
Aggregations