use of org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry in project zeppelin by apache.
the class NotebookServer method angularObjectClientUnbind.
/**
* Remove the given Angular variable to the target
* interpreter(s) angular registry given a noteId
* and an optional list of paragraph id(s)
*/
protected void angularObjectClientUnbind(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws Exception {
String noteId = fromMessage.getType("noteId");
String varName = fromMessage.getType("name");
String paragraphId = fromMessage.getType("paragraphId");
Note note = notebook.getNote(noteId);
if (paragraphId == null) {
throw new IllegalArgumentException("target paragraph not specified for " + "angular value unBind");
}
if (note != null) {
final InterpreterGroup interpreterGroup = findInterpreterGroupForParagraph(note, paragraphId);
final AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
if (registry instanceof RemoteAngularObjectRegistry) {
RemoteAngularObjectRegistry remoteRegistry = (RemoteAngularObjectRegistry) registry;
removeAngularFromRemoteRegistry(noteId, paragraphId, varName, remoteRegistry, interpreterGroup.getId(), conn);
} else {
removeAngularObjectFromLocalRepo(noteId, paragraphId, varName, registry, interpreterGroup.getId(), conn);
}
}
}
use of org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry in project zeppelin by apache.
the class Notebook method removeNote.
public void removeNote(String id, AuthenticationInfo subject) {
Preconditions.checkNotNull(subject, "AuthenticationInfo should not be null");
Note note;
synchronized (notes) {
note = notes.remove(id);
folders.removeNote(note);
}
interpreterSettingManager.removeNoteInterpreterSettingBinding(subject.getUser(), id);
noteSearchService.deleteIndexDocs(note);
notebookAuthorization.removeNote(id);
// remove from all interpreter instance's angular object registry
for (InterpreterSetting settings : interpreterSettingManager.get()) {
AngularObjectRegistry registry = settings.getInterpreterGroup(subject.getUser(), id).getAngularObjectRegistry();
if (registry instanceof RemoteAngularObjectRegistry) {
// remove paragraph scope object
for (Paragraph p : note.getParagraphs()) {
((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, p.getId());
// remove app scope object
List<ApplicationState> appStates = p.getAllApplicationStates();
if (appStates != null) {
for (ApplicationState app : appStates) {
((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, app.getId());
}
}
}
// remove note scope object
((RemoteAngularObjectRegistry) registry).removeAllAndNotifyRemoteProcess(id, null);
} else {
// remove paragraph scope object
for (Paragraph p : note.getParagraphs()) {
registry.removeAll(id, p.getId());
// remove app scope object
List<ApplicationState> appStates = p.getAllApplicationStates();
if (appStates != null) {
for (ApplicationState app : appStates) {
registry.removeAll(id, app.getId());
}
}
}
// remove note scope object
registry.removeAll(id, null);
}
}
ResourcePoolUtils.removeResourcesBelongsToNote(id);
fireNoteRemoveEvent(note);
try {
note.unpersist(subject);
} catch (IOException e) {
logger.error(e.toString(), e);
}
}
use of org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry in project zeppelin by apache.
the class NotebookServer method angularObjectClientUnbind.
/**
* 1. Remove the given Angular variable to the target interpreter(s) angular
* registry given a noteId and an optional list of paragraph id(s).
* 2. Delete AngularObject from note.
*/
protected void angularObjectClientUnbind(NotebookSocket conn, Message fromMessage) throws Exception {
String noteId = fromMessage.getType("noteId");
String varName = fromMessage.getType("name");
String paragraphId = fromMessage.getType("paragraphId");
if (paragraphId == null) {
throw new IllegalArgumentException("target paragraph not specified for " + "angular value unBind");
}
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 = removeAngularFromRemoteRegistry(noteId, paragraphId, varName, registry, interpreterGroup.getId(), conn);
note.deleteAngularObject(interpreterGroup.getId(), noteId, paragraphId, varName);
}
return null;
});
}
use of org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry in project zeppelin by apache.
the class NotebookServerTest method bindAngularObjectToRemoteForParagraphs.
@Test
public void bindAngularObjectToRemoteForParagraphs() throws Exception {
// Given
final String varName = "name";
final String value = "DuyHai DOAN";
final Message messageReceived = new Message(OP.ANGULAR_OBJECT_CLIENT_BIND).put("noteId", "noteId").put("name", varName).put("value", value).put("paragraphId", "paragraphId");
try {
final Notebook notebook = mock(Notebook.class);
notebookServer.setNotebook(() -> notebook);
notebookServer.setNotebookService(() -> notebookService);
final Note note = mock(Note.class, RETURNS_DEEP_STUBS);
when(notebook.processNote(eq("noteId"), Mockito.any())).then(e -> e.getArgumentAt(1, NoteProcessor.class).process(note));
final Paragraph paragraph = mock(Paragraph.class, RETURNS_DEEP_STUBS);
when(note.getParagraph("paragraphId")).thenReturn(paragraph);
final RemoteAngularObjectRegistry mdRegistry = mock(RemoteAngularObjectRegistry.class);
final InterpreterGroup mdGroup = new InterpreterGroup("mdGroup");
mdGroup.setAngularObjectRegistry(mdRegistry);
when(paragraph.getBindedInterpreter().getInterpreterGroup()).thenReturn(mdGroup);
final AngularObject<String> ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId");
when(mdRegistry.addAndNotifyRemoteProcess(varName, value, "noteId", "paragraphId")).thenReturn(ao1);
NotebookSocket conn = mock(NotebookSocket.class);
NotebookSocket otherConn = mock(NotebookSocket.class);
final String mdMsg1 = notebookServer.serializeMessage(new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
notebookServer.getConnectionManager().noteSocketMap.put("noteId", asList(conn, otherConn));
// When
notebookServer.angularObjectClientBind(conn, messageReceived);
// Then
verify(mdRegistry, never()).addAndNotifyRemoteProcess(varName, value, "noteId", null);
verify(otherConn).send(mdMsg1);
} finally {
// reset these so that it won't affect other tests
notebookServer.setNotebook(() -> NotebookServerTest.notebook);
notebookServer.setNotebookService(() -> NotebookServerTest.notebookService);
}
}
use of org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry in project zeppelin by apache.
the class InterpreterSetting method createInterpreterGroup.
private ManagedInterpreterGroup createInterpreterGroup(String groupId) {
AngularObjectRegistry angularObjectRegistry;
ManagedInterpreterGroup interpreterGroup = new ManagedInterpreterGroup(groupId, this);
angularObjectRegistry = new RemoteAngularObjectRegistry(groupId, angularObjectRegistryListener, interpreterGroup);
interpreterGroup.setAngularObjectRegistry(angularObjectRegistry);
return interpreterGroup;
}
Aggregations