use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class NotebookServer method pushAngularObjectToLocalRepo.
private void pushAngularObjectToLocalRepo(String noteId, String paragraphId, String varName, Object varValue, AngularObjectRegistry registry, String interpreterGroupId, NotebookSocket conn) {
AngularObject angularObject = registry.get(varName, noteId, paragraphId);
if (angularObject == null) {
angularObject = registry.add(varName, varValue, noteId, paragraphId);
} else {
angularObject.set(varValue, true);
}
this.broadcastExcept(noteId, new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", angularObject).put("interpreterGroupId", interpreterGroupId).put("noteId", noteId).put("paragraphId", paragraphId), conn);
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class NotebookService method updateAngularObject.
public void updateAngularObject(String noteId, String paragraphId, String interpreterGroupId, String varName, Object varValue, ServiceContext context, ServiceCallback<AngularObject> callback) throws IOException {
String user = context.getAutheInfo().getUser();
AngularObject ao = null;
boolean global = false;
// propagate change to (Remote) AngularObjectRegistry
List<InterpreterSetting> settings = notebook.processNote(noteId, note -> {
if (note == null) {
return Collections.emptyList();
} else {
return note.getBindedInterpreterSettings(new ArrayList<>(context.getUserAndRoles()));
}
});
for (InterpreterSetting setting : settings) {
if (setting.getInterpreterGroup(user, noteId) == null) {
continue;
}
if (interpreterGroupId.equals(setting.getInterpreterGroup(user, noteId).getId())) {
AngularObjectRegistry angularObjectRegistry = setting.getInterpreterGroup(user, noteId).getAngularObjectRegistry();
// first trying to get local registry
ao = angularObjectRegistry.get(varName, noteId, paragraphId);
if (ao == null) {
// then try notebook scope registry
ao = angularObjectRegistry.get(varName, noteId, null);
if (ao == null) {
// then try global scope registry
ao = angularObjectRegistry.get(varName, null, null);
if (ao == null) {
LOGGER.warn("Object {} is not binded", varName);
} else {
// path from client -> server
ao.set(varValue, false);
global = true;
}
} else {
// path from client -> server
ao.set(varValue, false);
global = false;
}
} else {
ao.set(varValue, false);
global = false;
}
break;
}
}
callback.onSuccess(ao, context);
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class NotebookServer method angularObjectClientBind.
/**
* 1. Push the given Angular variable to the target interpreter angular
* registry given a noteId and a paragraph id.
* 2. Save AngularObject to note.
*/
protected void angularObjectClientBind(NotebookSocket conn, Message fromMessage) throws Exception {
String noteId = fromMessage.getType("noteId");
String varName = fromMessage.getType("name");
Object varValue = fromMessage.get("value");
String paragraphId = fromMessage.getType("paragraphId");
if (paragraphId == null) {
throw new IllegalArgumentException("target paragraph not specified for " + "angular value bind");
}
getNotebook().processNote(noteId, note -> {
if (note != null) {
InterpreterGroup interpreterGroup;
try {
interpreterGroup = findInterpreterGroupForParagraph(note, paragraphId);
} catch (Exception e) {
LOG.error("No interpreter group found for noteId {} and paragraphId {}", noteId, paragraphId, e);
return null;
}
final RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry();
AngularObject ao = pushAngularObjectToRemoteRegistry(noteId, paragraphId, varName, varValue, registry, interpreterGroup.getId(), conn);
note.addOrUpdateAngularObject(interpreterGroup.getId(), ao);
}
return null;
});
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class NotebookServer method updateAngularObjectRegistry.
/**
* Update the AngularObject object in the note to InterpreterGroup and AngularObjectRegistry.
*/
private void updateAngularObjectRegistry(NotebookSocket conn, Note note) {
for (Paragraph paragraph : note.getParagraphs()) {
InterpreterGroup interpreterGroup = null;
try {
interpreterGroup = findInterpreterGroupForParagraph(note, paragraph.getId());
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
}
if (null == interpreterGroup) {
return;
}
RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry();
List<AngularObject> angularObjects = note.getAngularObjects(interpreterGroup.getId());
for (AngularObject ao : angularObjects) {
if (StringUtils.equals(ao.getNoteId(), note.getId()) && StringUtils.equals(ao.getParagraphId(), paragraph.getId())) {
pushAngularObjectToRemoteRegistry(ao.getNoteId(), ao.getParagraphId(), ao.getName(), ao.get(), registry, interpreterGroup.getId(), conn);
}
}
}
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class BaseInterpreterTest method getIntpContext.
protected InterpreterContext getIntpContext() {
final AtomicInteger onAdd = new AtomicInteger(0);
final AtomicInteger onUpdate = new AtomicInteger(0);
final AtomicInteger onRemove = new AtomicInteger(0);
AngularObjectRegistry registry = new AngularObjectRegistry("intpId", new AngularObjectRegistryListener() {
@Override
public void onAddAngularObject(String interpreterGroupId, AngularObject angularObject) {
onAdd.incrementAndGet();
}
@Override
public void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject) {
onUpdate.incrementAndGet();
}
@Override
public void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject) {
onRemove.incrementAndGet();
}
});
AuthenticationInfo authenticationInfo = new AuthenticationInfo("user");
return InterpreterContext.builder().setNoteId("noteId").setNoteName("noteName").setParagraphId("paragraphId").setAuthenticationInfo(authenticationInfo).setAngularObjectRegistry(registry).setInterpreterOut(new InterpreterOutput()).setIntpEventClient(mock(RemoteInterpreterEventClient.class)).build();
}
Aggregations