mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
WIP
This commit is contained in:
parent
94dfed27c4
commit
ccbedc17b4
13 changed files with 230 additions and 174 deletions
|
|
@ -177,7 +177,7 @@ public class NotebookRestApi {
|
|||
public Response bind(@PathParam("noteId") String noteId, String req) throws IOException {
|
||||
List<String> settingIdList = gson.fromJson(req, new TypeToken<List<String>>() {
|
||||
}.getType());
|
||||
notebook.bindInterpretersToNote(noteId, settingIdList);
|
||||
notebook.bindInterpretersToNote(SecurityUtils.getPrincipal(), noteId, settingIdList);
|
||||
return new JsonResponse<>(Status.OK).build();
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +458,7 @@ public class NotebookRestApi {
|
|||
}
|
||||
|
||||
AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
|
||||
note.removeParagraph(paragraphId);
|
||||
note.removeParagraph(SecurityUtils.getPrincipal(), paragraphId);
|
||||
note.persist(subject);
|
||||
notebookServer.broadcastNote(note);
|
||||
|
||||
|
|
|
|||
|
|
@ -813,7 +813,7 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
|
||||
/** We dont want to remove the last paragraph */
|
||||
if (!note.isLastParagraph(paragraphId)) {
|
||||
note.removeParagraph(paragraphId);
|
||||
note.removeParagraph(subject.getUser(), paragraphId);
|
||||
note.persist(subject);
|
||||
broadcastNote(note);
|
||||
}
|
||||
|
|
@ -869,6 +869,7 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
String interpreterGroupId = (String) fromMessage.get("interpreterGroupId");
|
||||
String varName = (String) fromMessage.get("name");
|
||||
Object varValue = fromMessage.get("value");
|
||||
String user = SecurityUtils.getPrincipal();
|
||||
AngularObject ao = null;
|
||||
boolean global = false;
|
||||
// propagate change to (Remote) AngularObjectRegistry
|
||||
|
|
@ -877,12 +878,12 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
List<InterpreterSetting> settings = notebook.getInterpreterFactory()
|
||||
.getInterpreterSettings(note.getId());
|
||||
for (InterpreterSetting setting : settings) {
|
||||
if (setting.getInterpreterGroup(note.getId()) == null) {
|
||||
if (setting.getInterpreterGroup(user, note.getId()) == null) {
|
||||
continue;
|
||||
}
|
||||
if (interpreterGroupId.equals(setting.getInterpreterGroup(note.getId()).getId())) {
|
||||
if (interpreterGroupId.equals(setting.getInterpreterGroup(user, note.getId()).getId())) {
|
||||
AngularObjectRegistry angularObjectRegistry = setting
|
||||
.getInterpreterGroup(note.getId()).getAngularObjectRegistry();
|
||||
.getInterpreterGroup(user, note.getId()).getAngularObjectRegistry();
|
||||
|
||||
// first trying to get local registry
|
||||
ao = angularObjectRegistry.get(varName, noteId, paragraphId);
|
||||
|
|
@ -919,12 +920,12 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
List<InterpreterSetting> settings = notebook.getInterpreterFactory()
|
||||
.getInterpreterSettings(note.getId());
|
||||
for (InterpreterSetting setting : settings) {
|
||||
if (setting.getInterpreterGroup(n.getId()) == null) {
|
||||
if (setting.getInterpreterGroup(user, n.getId()) == null) {
|
||||
continue;
|
||||
}
|
||||
if (interpreterGroupId.equals(setting.getInterpreterGroup(n.getId()).getId())) {
|
||||
if (interpreterGroupId.equals(setting.getInterpreterGroup(user, n.getId()).getId())) {
|
||||
AngularObjectRegistry angularObjectRegistry = setting
|
||||
.getInterpreterGroup(n.getId()).getAngularObjectRegistry();
|
||||
.getInterpreterGroup(user, n.getId()).getAngularObjectRegistry();
|
||||
this.broadcastExcept(
|
||||
n.getId(),
|
||||
new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", ao)
|
||||
|
|
@ -1565,6 +1566,7 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
}
|
||||
|
||||
private void sendAllAngularObjects(Note note, NotebookSocket conn) throws IOException {
|
||||
String user = SecurityUtils.getPrincipal();
|
||||
List<InterpreterSetting> settings =
|
||||
notebook().getInterpreterFactory().getInterpreterSettings(note.getId());
|
||||
if (settings == null || settings.size() == 0) {
|
||||
|
|
@ -1572,14 +1574,14 @@ public class NotebookServer extends WebSocketServlet implements
|
|||
}
|
||||
|
||||
for (InterpreterSetting intpSetting : settings) {
|
||||
AngularObjectRegistry registry = intpSetting.getInterpreterGroup(note.getId())
|
||||
AngularObjectRegistry registry = intpSetting.getInterpreterGroup(user, note.getId())
|
||||
.getAngularObjectRegistry();
|
||||
List<AngularObject> objects = registry.getAllWithGlobal(note.getId());
|
||||
for (AngularObject object : objects) {
|
||||
conn.send(serializeMessage(new Message(OP.ANGULAR_OBJECT_UPDATE)
|
||||
.put("angularObject", object)
|
||||
.put("interpreterGroupId",
|
||||
intpSetting.getInterpreterGroup(note.getId()).getId())
|
||||
intpSetting.getInterpreterGroup(user, note.getId()).getId())
|
||||
.put("noteId", note.getId())
|
||||
.put("paragraphId", object.getParagraphId())
|
||||
));
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
List<InterpreterSetting> settings = notebook.getInterpreterFactory().getInterpreterSettings(note1.getId());
|
||||
for (InterpreterSetting setting : settings) {
|
||||
if (setting.getName().equals("md")) {
|
||||
interpreterGroup = setting.getInterpreterGroup("sharedProcess");
|
||||
interpreterGroup = setting.getInterpreterGroup("anonymous", "sharedProcess");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -698,16 +698,17 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
return interpreterGroup;
|
||||
}
|
||||
|
||||
public void removeInterpretersForNote(InterpreterSetting interpreterSetting, String noteId) {
|
||||
public void removeInterpretersForNote(InterpreterSetting interpreterSetting, String user,
|
||||
String noteId) {
|
||||
if (interpreterSetting.getOption().isPerNoteProcess()) {
|
||||
interpreterSetting.closeAndRemoveInterpreterGroup(noteId);
|
||||
} else if (interpreterSetting.getOption().isPerNoteSession()) {
|
||||
InterpreterGroup interpreterGroup = interpreterSetting.getInterpreterGroup(noteId);
|
||||
|
||||
interpreterGroup.close(noteId);
|
||||
interpreterGroup.destroy(noteId);
|
||||
InterpreterGroup interpreterGroup = interpreterSetting.getInterpreterGroup(user, noteId);
|
||||
String key = getInterpreterInstanceKey(user, noteId, interpreterSetting);
|
||||
interpreterGroup.close(key);
|
||||
interpreterGroup.destroy(key);
|
||||
synchronized (interpreterGroup) {
|
||||
interpreterGroup.remove(noteId);
|
||||
interpreterGroup.remove(key);
|
||||
interpreterGroup.notifyAll(); // notify createInterpreterForNote()
|
||||
}
|
||||
logger.info("Interpreter instance {} for note {} is removed", interpreterSetting.getName(),
|
||||
|
|
@ -715,9 +716,9 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
}
|
||||
}
|
||||
|
||||
public void createInterpretersForNote(InterpreterSetting interpreterSetting, String noteId,
|
||||
String key) {
|
||||
InterpreterGroup interpreterGroup = interpreterSetting.getInterpreterGroup(noteId);
|
||||
public void createInterpretersForNote(InterpreterSetting interpreterSetting, String user,
|
||||
String noteId, String key) {
|
||||
InterpreterGroup interpreterGroup = interpreterSetting.getInterpreterGroup(user, noteId);
|
||||
InterpreterOption option = interpreterSetting.getOption();
|
||||
Properties properties = interpreterSetting.getProperties();
|
||||
if (option.isExistingProcess) {
|
||||
|
|
@ -861,8 +862,8 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
}
|
||||
}
|
||||
|
||||
private void putNoteInterpreterSettingBinding(String noteId, List<String> settingList)
|
||||
throws IOException {
|
||||
private void putNoteInterpreterSettingBinding(String user, String noteId,
|
||||
List<String> settingList) throws IOException {
|
||||
List<String> unBindedSettings = new LinkedList<>();
|
||||
|
||||
synchronized (interpreterSettings) {
|
||||
|
|
@ -879,18 +880,18 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
|
||||
for (String settingId : unBindedSettings) {
|
||||
InterpreterSetting setting = get(settingId);
|
||||
removeInterpretersForNote(setting, noteId);
|
||||
removeInterpretersForNote(setting, user, noteId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNoteInterpreterSettingBinding(String noteId) {
|
||||
public void removeNoteInterpreterSettingBinding(String user, String noteId) {
|
||||
synchronized (interpreterSettings) {
|
||||
List<String> settingIds = (interpreterBindings.containsKey(noteId) ?
|
||||
interpreterBindings.remove(noteId) :
|
||||
Collections.<String>emptyList());
|
||||
for (String settingId : settingIds) {
|
||||
this.removeInterpretersForNote(get(settingId), noteId);
|
||||
this.removeInterpretersForNote(get(settingId), user, noteId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1093,8 +1094,8 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
* @param ids InterpreterSetting id list
|
||||
* @throws IOException
|
||||
*/
|
||||
public void setInterpreters(String noteId, List<String> ids) throws IOException {
|
||||
putNoteInterpreterSettingBinding(noteId, ids);
|
||||
public void setInterpreters(String user, String noteId, List<String> ids) throws IOException {
|
||||
putNoteInterpreterSettingBinding(user, noteId, ids);
|
||||
}
|
||||
|
||||
public List<String> getInterpreters(String noteId) {
|
||||
|
|
@ -1119,7 +1120,7 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
return settings;
|
||||
}
|
||||
|
||||
public void closeNote(String noteId) {
|
||||
public void closeNote(String user, String noteId) {
|
||||
// close interpreters in this note session
|
||||
List<InterpreterSetting> settings = getInterpreterSettings(noteId);
|
||||
if (settings == null || settings.size() == 0) {
|
||||
|
|
@ -1128,7 +1129,7 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
|
||||
logger.info("closeNote: {}", noteId);
|
||||
for (InterpreterSetting setting : settings) {
|
||||
removeInterpretersForNote(setting, noteId);
|
||||
removeInterpretersForNote(setting, user, noteId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1148,11 +1149,11 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
|
||||
private List<Interpreter> createOrGetInterpreterList(String user, String noteId,
|
||||
InterpreterSetting setting) {
|
||||
InterpreterGroup interpreterGroup = setting.getInterpreterGroup(noteId);
|
||||
InterpreterGroup interpreterGroup = setting.getInterpreterGroup(user, noteId);
|
||||
synchronized (interpreterGroup) {
|
||||
String key = getInterpreterInstanceKey(user, noteId, setting);
|
||||
if (!interpreterGroup.containsKey(key)) {
|
||||
createInterpretersForNote(setting, noteId, key);
|
||||
createInterpretersForNote(setting, user, noteId, key);
|
||||
}
|
||||
return interpreterGroup.get(getInterpreterInstanceKey(user, noteId, setting));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -54,13 +55,19 @@ public class InterpreterSetting {
|
|||
|
||||
@Deprecated private transient InterpreterGroupFactory interpreterGroupFactory;
|
||||
|
||||
public InterpreterSetting() {
|
||||
private final transient ReentrantReadWriteLock.ReadLock interpreterGroupReadLock;
|
||||
private final transient ReentrantReadWriteLock.WriteLock interpreterGroupWriteLock;
|
||||
|
||||
public InterpreterSetting() {
|
||||
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
interpreterGroupReadLock = lock.readLock();
|
||||
interpreterGroupWriteLock = lock.writeLock();
|
||||
}
|
||||
|
||||
public InterpreterSetting(String id, String name, String group,
|
||||
List<InterpreterInfo> interpreterInfos, Properties properties, List<Dependency> dependencies,
|
||||
InterpreterOption option, String path) {
|
||||
this();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.group = group;
|
||||
|
|
@ -115,31 +122,41 @@ public class InterpreterSetting {
|
|||
|
||||
public InterpreterGroup getInterpreterGroup(String user, String noteId) {
|
||||
String key = getInterpreterProcessKey(user, noteId);
|
||||
synchronized (interpreterGroupRef) {
|
||||
if (!interpreterGroupRef.containsKey(key)) {
|
||||
String interpreterGroupId = getId() + ":" + key;
|
||||
InterpreterGroup intpGroup =
|
||||
interpreterGroupFactory.createInterpreterGroup(interpreterGroupId, getOption());
|
||||
interpreterGroupRef.put(key, intpGroup);
|
||||
}
|
||||
if (!interpreterGroupRef.containsKey(key)) {
|
||||
String interpreterGroupId = getId() + ":" + key;
|
||||
InterpreterGroup intpGroup =
|
||||
interpreterGroupFactory.createInterpreterGroup(interpreterGroupId, getOption());
|
||||
|
||||
interpreterGroupWriteLock.lock();
|
||||
interpreterGroupRef.put(key, intpGroup);
|
||||
interpreterGroupWriteLock.unlock();
|
||||
}
|
||||
try {
|
||||
interpreterGroupReadLock.lock();
|
||||
return interpreterGroupRef.get(key);
|
||||
} finally {
|
||||
interpreterGroupReadLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<InterpreterGroup> getAllInterpreterGroups() {
|
||||
synchronized (interpreterGroupRef) {
|
||||
try {
|
||||
interpreterGroupReadLock.lock();
|
||||
return new LinkedList<>(interpreterGroupRef.values());
|
||||
} finally {
|
||||
interpreterGroupReadLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void closeAndRemoveInterpreterGroup(String noteId) {
|
||||
String key = getInterpreterProcessKey("", noteId);
|
||||
|
||||
InterpreterGroup groupToRemove = null;
|
||||
synchronized (interpreterGroupRef) {
|
||||
for(String intpKey: interpreterGroupRef.keySet()) {
|
||||
if(intpKey.contains(key)) {
|
||||
groupToRemove = interpreterGroupRef.remove(intpKey);
|
||||
}
|
||||
for (String intpKey : new HashSet<>(interpreterGroupRef.keySet())) {
|
||||
if (intpKey.contains(key)) {
|
||||
interpreterGroupWriteLock.lock();
|
||||
groupToRemove = interpreterGroupRef.remove(intpKey);
|
||||
interpreterGroupWriteLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,11 +167,9 @@ public class InterpreterSetting {
|
|||
}
|
||||
|
||||
void closeAndRmoveAllInterpreterGroups() {
|
||||
synchronized (interpreterGroupRef) {
|
||||
HashSet<String> groupsToRemove = new HashSet<>(interpreterGroupRef.keySet());
|
||||
for (String key : groupsToRemove) {
|
||||
closeAndRemoveInterpreterGroup(key);
|
||||
}
|
||||
HashSet<String> groupsToRemove = new HashSet<>(interpreterGroupRef.keySet());
|
||||
for (String key : groupsToRemove) {
|
||||
closeAndRemoveInterpreterGroup(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -286,8 +287,8 @@ public class Note implements Serializable, ParagraphJobListener {
|
|||
* @param paragraphId ID of paragraph
|
||||
* @return a paragraph that was deleted, or <code>null</code> otherwise
|
||||
*/
|
||||
public Paragraph removeParagraph(String paragraphId) {
|
||||
removeAllAngularObjectInParagraph(paragraphId);
|
||||
public Paragraph removeParagraph(String user, String paragraphId) {
|
||||
removeAllAngularObjectInParagraph(user, paragraphId);
|
||||
ResourcePoolUtils.removeResourcesBelongsToParagraph(getId(), paragraphId);
|
||||
synchronized (paragraphs) {
|
||||
Iterator<Paragraph> i = paragraphs.iterator();
|
||||
|
|
@ -460,6 +461,9 @@ public class Note implements Serializable, ParagraphJobListener {
|
|||
*/
|
||||
public void runAll() {
|
||||
String cronExecutingUser = (String) getConfig().get("cronExecutingUser");
|
||||
if (null == cronExecutingUser) {
|
||||
cronExecutingUser = "anonymous";
|
||||
}
|
||||
synchronized (paragraphs) {
|
||||
for (Paragraph p : paragraphs) {
|
||||
if (!p.isEnabled()) {
|
||||
|
|
@ -482,7 +486,8 @@ public class Note implements Serializable, ParagraphJobListener {
|
|||
Paragraph p = getParagraph(paragraphId);
|
||||
p.setListener(jobListenerFactory.getParagraphJobListener(this));
|
||||
String requiredReplName = p.getRequiredReplName();
|
||||
Interpreter intp = factory.getInterpreter(getId(), requiredReplName);
|
||||
Interpreter intp = factory.getInterpreter(p.getUser(), getId(), requiredReplName);
|
||||
|
||||
if (intp == null) {
|
||||
String intpExceptionMsg =
|
||||
p.getJobName() + "'s Interpreter " + requiredReplName + " not found";
|
||||
|
|
@ -526,7 +531,7 @@ public class Note implements Serializable, ParagraphJobListener {
|
|||
}
|
||||
}
|
||||
|
||||
private void snapshotAngularObjectRegistry() {
|
||||
private void snapshotAngularObjectRegistry(String user) {
|
||||
angularObjects = new HashMap<>();
|
||||
|
||||
List<InterpreterSetting> settings = factory.getInterpreterSettings(getId());
|
||||
|
|
@ -535,13 +540,13 @@ public class Note implements Serializable, ParagraphJobListener {
|
|||
}
|
||||
|
||||
for (InterpreterSetting setting : settings) {
|
||||
InterpreterGroup intpGroup = setting.getInterpreterGroup(id);
|
||||
InterpreterGroup intpGroup = setting.getInterpreterGroup(user, id);
|
||||
AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
|
||||
angularObjects.put(intpGroup.getId(), registry.getAllWithGlobal(id));
|
||||
}
|
||||
}
|
||||
|
||||
private void removeAllAngularObjectInParagraph(String paragraphId) {
|
||||
private void removeAllAngularObjectInParagraph(String user, String paragraphId) {
|
||||
angularObjects = new HashMap<>();
|
||||
|
||||
List<InterpreterSetting> settings = factory.getInterpreterSettings(getId());
|
||||
|
|
@ -550,7 +555,7 @@ public class Note implements Serializable, ParagraphJobListener {
|
|||
}
|
||||
|
||||
for (InterpreterSetting setting : settings) {
|
||||
InterpreterGroup intpGroup = setting.getInterpreterGroup(id);
|
||||
InterpreterGroup intpGroup = setting.getInterpreterGroup(user, id);
|
||||
AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
|
||||
|
||||
if (registry instanceof RemoteAngularObjectRegistry) {
|
||||
|
|
@ -580,8 +585,9 @@ public class Note implements Serializable, ParagraphJobListener {
|
|||
}
|
||||
|
||||
public void persist(AuthenticationInfo subject) throws IOException {
|
||||
Preconditions.checkNotNull(subject, "AuthenticationInfo should not be null");
|
||||
stopDelayedPersistTimer();
|
||||
snapshotAngularObjectRegistry();
|
||||
snapshotAngularObjectRegistry(subject.getUser());
|
||||
index.updateIndexDoc(this);
|
||||
repo.save(this, subject);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Sets;
|
||||
|
|
@ -135,6 +137,7 @@ public class Notebook implements NoteEventListener {
|
|||
* @throws IOException
|
||||
*/
|
||||
public Note createNote(AuthenticationInfo subject) throws IOException {
|
||||
Preconditions.checkNotNull(subject, "AuthenticationInfo should not be null");
|
||||
Note note;
|
||||
if (conf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_AUTO_INTERPRETER_BINDING)) {
|
||||
note = createNote(replFactory.getDefaultInterpreterSettingList(), subject);
|
||||
|
|
@ -158,7 +161,7 @@ public class Notebook implements NoteEventListener {
|
|||
notes.put(note.getId(), note);
|
||||
}
|
||||
if (interpreterIds != null) {
|
||||
bindInterpretersToNote(note.getId(), interpreterIds);
|
||||
bindInterpretersToNote(subject.getUser(), note.getId(), interpreterIds);
|
||||
}
|
||||
|
||||
if (subject != null && !"anonymous".equals(subject.getUser())) {
|
||||
|
|
@ -252,7 +255,7 @@ public class Notebook implements NoteEventListener {
|
|||
}
|
||||
// Copy the interpreter bindings
|
||||
List<String> boundInterpreterSettingsIds = getBindedInterpreterSettingsIds(sourceNote.getId());
|
||||
bindInterpretersToNote(newNote.getId(), boundInterpreterSettingsIds);
|
||||
bindInterpretersToNote(subject.getUser(), newNote.getId(), boundInterpreterSettingsIds);
|
||||
|
||||
List<Paragraph> paragraphs = sourceNote.getParagraphs();
|
||||
for (Paragraph p : paragraphs) {
|
||||
|
|
@ -264,7 +267,7 @@ public class Notebook implements NoteEventListener {
|
|||
return newNote;
|
||||
}
|
||||
|
||||
public void bindInterpretersToNote(String id, List<String> interpreterSettingIds)
|
||||
public void bindInterpretersToNote(String user, String id, List<String> interpreterSettingIds)
|
||||
throws IOException {
|
||||
Note note = getNote(id);
|
||||
if (note != null) {
|
||||
|
|
@ -275,7 +278,7 @@ public class Notebook implements NoteEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
replFactory.setInterpreters(note.getId(), interpreterSettingIds);
|
||||
replFactory.setInterpreters(user, note.getId(), interpreterSettingIds);
|
||||
// comment out while note.getNoteReplLoader().setInterpreters(...) do the same
|
||||
// replFactory.putNoteInterpreterSettingBinding(id, interpreterSettingIds);
|
||||
}
|
||||
|
|
@ -306,18 +309,21 @@ public class Notebook implements NoteEventListener {
|
|||
}
|
||||
|
||||
public void removeNote(String id, AuthenticationInfo subject) {
|
||||
Preconditions.checkNotNull(subject, "AuthenticationInfo should not be null");
|
||||
|
||||
Note note;
|
||||
|
||||
synchronized (notes) {
|
||||
note = notes.remove(id);
|
||||
}
|
||||
replFactory.removeNoteInterpreterSettingBinding(id);
|
||||
replFactory.removeNoteInterpreterSettingBinding(subject.getUser(), id);
|
||||
notebookIndex.deleteIndexDocs(note);
|
||||
notebookAuthorization.removeNote(id);
|
||||
|
||||
// remove from all interpreter instance's angular object registry
|
||||
for (InterpreterSetting settings : replFactory.get()) {
|
||||
AngularObjectRegistry registry = settings.getInterpreterGroup(id).getAngularObjectRegistry();
|
||||
AngularObjectRegistry registry =
|
||||
settings.getInterpreterGroup(subject.getUser(), id).getAngularObjectRegistry();
|
||||
if (registry instanceof RemoteAngularObjectRegistry) {
|
||||
// remove paragraph scope object
|
||||
for (Paragraph p : note.getParagraphs()) {
|
||||
|
|
@ -437,7 +443,7 @@ public class Notebook implements NoteEventListener {
|
|||
SnapshotAngularObject snapshot = angularObjectSnapshot.get(name);
|
||||
List<InterpreterSetting> settings = replFactory.get();
|
||||
for (InterpreterSetting setting : settings) {
|
||||
InterpreterGroup intpGroup = setting.getInterpreterGroup(note.getId());
|
||||
InterpreterGroup intpGroup = setting.getInterpreterGroup(subject.getUser(), note.getId());
|
||||
if (intpGroup.getId().equals(snapshot.getIntpGroupId())) {
|
||||
AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
|
||||
String noteId = snapshot.getAngularObject().getNoteId();
|
||||
|
|
@ -533,7 +539,7 @@ public class Notebook implements NoteEventListener {
|
|||
return noteList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Note> getAllNotes(AuthenticationInfo subject) {
|
||||
final Set<String> entities = Sets.newHashSet();
|
||||
if (subject != null) {
|
||||
|
|
|
|||
|
|
@ -446,8 +446,8 @@ public class Paragraph extends Job implements Serializable, Cloneable {
|
|||
|
||||
if (!factory.getInterpreterSettings(note.getId()).isEmpty()) {
|
||||
InterpreterSetting intpGroup = factory.getInterpreterSettings(note.getId()).get(0);
|
||||
registry = intpGroup.getInterpreterGroup(note.getId()).getAngularObjectRegistry();
|
||||
resourcePool = intpGroup.getInterpreterGroup(note.getId()).getResourcePool();
|
||||
registry = intpGroup.getInterpreterGroup(getUser(), note.getId()).getAngularObjectRegistry();
|
||||
resourcePool = intpGroup.getInterpreterGroup(getUser(), note.getId()).getResourcePool();
|
||||
}
|
||||
|
||||
List<InterpreterContextRunner> runners = new LinkedList<InterpreterContextRunner>();
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
new String[][]{});
|
||||
|
||||
Note note1 = notebook.createNote(null);
|
||||
factory.setInterpreters(note1.getId(),factory.getDefaultInterpreterSettingList());
|
||||
factory.setInterpreters("user", note1.getId(),factory.getDefaultInterpreterSettingList());
|
||||
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
new String[][]{});
|
||||
|
||||
Note note1 = notebook.createNote(null);
|
||||
factory.setInterpreters(note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
factory.setInterpreters("user", note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
|
||||
|
|
@ -193,7 +193,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
}
|
||||
|
||||
// when remove paragraph
|
||||
note1.removeParagraph(p1.getId());
|
||||
note1.removeParagraph("user", p1.getId());
|
||||
|
||||
// then
|
||||
assertEquals(ApplicationState.Status.UNLOADED, app.getStatus());
|
||||
|
|
@ -214,7 +214,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
new String[][]{});
|
||||
|
||||
Note note1 = notebook.createNote(null);
|
||||
notebook.bindInterpretersToNote(note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
notebook.bindInterpretersToNote("user", note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
|
||||
|
|
@ -231,7 +231,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
}
|
||||
|
||||
// when unbind interpreter
|
||||
notebook.bindInterpretersToNote(note1.getId(), new LinkedList<String>());
|
||||
notebook.bindInterpretersToNote("user", note1.getId(), new LinkedList<String>());
|
||||
|
||||
// then
|
||||
assertEquals(ApplicationState.Status.UNLOADED, app.getStatus());
|
||||
|
|
@ -255,7 +255,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
|
||||
// Unbind all interpreter from note
|
||||
// NullPointerException shouldn't occur here
|
||||
notebook.bindInterpretersToNote(note1.getId(), new LinkedList<String>());
|
||||
notebook.bindInterpretersToNote("user", note1.getId(), new LinkedList<String>());
|
||||
|
||||
// remove note
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
|
|
@ -273,7 +273,7 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory {
|
|||
new String[][]{});
|
||||
|
||||
Note note1 = notebook.createNote(null);
|
||||
notebook.bindInterpretersToNote(note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
notebook.bindInterpretersToNote("user", note1.getId(), factory.getDefaultInterpreterSettingList());
|
||||
String mock1IntpSettingId = null;
|
||||
for (InterpreterSetting setting : notebook.getBindedInterpreterSettings(note1.getId())) {
|
||||
if (setting.getName().equals("mock1")) {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import org.apache.zeppelin.dep.Dependency;
|
|||
import org.apache.zeppelin.dep.DependencyResolver;
|
||||
import org.apache.zeppelin.interpreter.mock.MockInterpreter1;
|
||||
import org.apache.zeppelin.interpreter.mock.MockInterpreter2;
|
||||
import org.apache.zeppelin.notebook.repo.zeppelinhub.security.Authentication;
|
||||
import org.apache.zeppelin.user.AuthenticationInfo;
|
||||
import org.apache.zeppelin.interpreter.remote.RemoteInterpreter;
|
||||
import org.apache.zeppelin.notebook.JobListenerFactory;
|
||||
import org.apache.zeppelin.notebook.Note;
|
||||
|
|
@ -114,8 +116,8 @@ public class InterpreterFactoryTest {
|
|||
|
||||
// mock1Setting = factory.createNewSetting("mock11", "mock1", new ArrayList<Dependency>(), new InterpreterOption(false), new Properties());
|
||||
|
||||
InterpreterGroup interpreterGroup = mock1Setting.getInterpreterGroup("sharedProcess");
|
||||
factory.createInterpretersForNote(mock1Setting, "sharedProcess", "session");
|
||||
InterpreterGroup interpreterGroup = mock1Setting.getInterpreterGroup("user", "sharedProcess");
|
||||
factory.createInterpretersForNote(mock1Setting, "user", "sharedProcess", "session");
|
||||
|
||||
// get interpreter
|
||||
assertNotNull("get Interpreter", interpreterGroup.get("session").get(0));
|
||||
|
|
@ -125,7 +127,7 @@ public class InterpreterFactoryTest {
|
|||
|
||||
// restart interpreter
|
||||
factory.restart(mock1Setting.getId());
|
||||
assertNull(mock1Setting.getInterpreterGroup("sharedProcess").get("session"));
|
||||
assertNull(mock1Setting.getInterpreterGroup("user", "sharedProcess").get("session"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -205,7 +207,7 @@ public class InterpreterFactoryTest {
|
|||
final InterpreterSetting setting1 = factory.createNewSetting("test-group1", "group1", new ArrayList<Dependency>(), new InterpreterOption(true), new Properties());
|
||||
final InterpreterSetting setting2 = factory.createNewSetting("test-group2", "group1", new ArrayList<Dependency>(), new InterpreterOption(true), new Properties());
|
||||
|
||||
factory.setInterpreters("note", new ArrayList<String>() {{
|
||||
factory.setInterpreters("user", "note", new ArrayList<String>() {{
|
||||
add(setting1.getId());
|
||||
add(setting2.getId());
|
||||
}});
|
||||
|
|
@ -214,6 +216,28 @@ public class InterpreterFactoryTest {
|
|||
assertEquals("className1", factory.getInterpreter("user1", "note", "group1").getClassName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiUser() throws IOException, RepositoryException {
|
||||
factory = new InterpreterFactory(conf, null, null, null, depResolver);
|
||||
final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true);
|
||||
factory.add("group1", new ArrayList<InterpreterInfo>(){{
|
||||
add(info1);
|
||||
}}, new ArrayList<Dependency>(), new InterpreterOption(true), new Properties(), "/path1");
|
||||
|
||||
final InterpreterSetting setting1 = factory.createNewSetting("test-group1", "group1", new ArrayList<Dependency>(), new InterpreterOption(true), new Properties());
|
||||
|
||||
factory.setInterpreters("user1", "note", new ArrayList<String>() {{
|
||||
add(setting1.getId());
|
||||
}});
|
||||
|
||||
factory.setInterpreters("user2", "note", new ArrayList<String>() {{
|
||||
add(setting1.getId());
|
||||
}});
|
||||
|
||||
assertNotEquals(factory.getInterpreter("user1", "note", "test-group1"), factory.getInterpreter("user2", "note", "test-group1"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInvalidInterpreterSettingName() {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class NoteInterpreterLoaderTest {
|
|||
|
||||
@Test
|
||||
public void testGetInterpreter() throws IOException {
|
||||
factory.setInterpreters("note", factory.getDefaultInterpreterSettingList());
|
||||
factory.setInterpreters("user", "note", factory.getDefaultInterpreterSettingList());
|
||||
|
||||
// when there're no interpreter selection directive
|
||||
assertEquals("org.apache.zeppelin.interpreter.mock.MockInterpreter1", factory.getInterpreter("user", "note", null).getClassName());
|
||||
|
|
@ -90,20 +90,20 @@ public class NoteInterpreterLoaderTest {
|
|||
assertEquals("org.apache.zeppelin.interpreter.mock.MockInterpreter11", factory.getInterpreter("user", "note", "group1.mock11").getClassName());
|
||||
assertEquals("org.apache.zeppelin.interpreter.mock.MockInterpreter2", factory.getInterpreter("user", "note", "group2.mock2").getClassName());
|
||||
|
||||
factory.closeNote("note");
|
||||
factory.closeNote("user", "note");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoteSession() throws IOException {
|
||||
factory.setInterpreters("noteA", factory.getDefaultInterpreterSettingList());
|
||||
factory.setInterpreters("user", "noteA", factory.getDefaultInterpreterSettingList());
|
||||
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNoteSession(true);
|
||||
|
||||
factory.setInterpreters("noteB", factory.getDefaultInterpreterSettingList());
|
||||
factory.setInterpreters("user", "noteB", factory.getDefaultInterpreterSettingList());
|
||||
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNoteSession(true);
|
||||
|
||||
// interpreters are not created before accessing it
|
||||
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("shared_process").get("noteA"));
|
||||
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("shared_process").get("noteB"));
|
||||
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get("noteA"));
|
||||
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get("noteB"));
|
||||
|
||||
factory.getInterpreter("user", "noteA", null).open();
|
||||
factory.getInterpreter("user", "noteB", null).open();
|
||||
|
|
@ -113,30 +113,30 @@ public class NoteInterpreterLoaderTest {
|
|||
factory.getInterpreter("user", "noteB", null).getInterpreterGroup().getId()));
|
||||
|
||||
// interpreters are created after accessing it
|
||||
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("shared_process").get("noteA"));
|
||||
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("shared_process").get("noteB"));
|
||||
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get("noteA"));
|
||||
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get("noteB"));
|
||||
|
||||
// when
|
||||
factory.closeNote("noteA");
|
||||
factory.closeNote("noteB");
|
||||
factory.closeNote("user", "noteA");
|
||||
factory.closeNote("user", "noteB");
|
||||
|
||||
// interpreters are destroyed after close
|
||||
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("shared_process").get("noteA"));
|
||||
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("shared_process").get("noteB"));
|
||||
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "shared_process").get("noteA"));
|
||||
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "shared_process").get("noteB"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotePerInterpreterProcess() throws IOException {
|
||||
factory.setInterpreters("noteA", factory.getDefaultInterpreterSettingList());
|
||||
factory.setInterpreters("user", "noteA", factory.getDefaultInterpreterSettingList());
|
||||
factory.getInterpreterSettings("noteA").get(0).getOption().setPerNoteProcess(true);
|
||||
|
||||
factory.setInterpreters("noteB", factory.getDefaultInterpreterSettingList());
|
||||
factory.setInterpreters("user", "noteB", factory.getDefaultInterpreterSettingList());
|
||||
factory.getInterpreterSettings("noteB").get(0).getOption().setPerNoteProcess(true);
|
||||
|
||||
// interpreters are not created before accessing it
|
||||
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("noteA").get("noteA"));
|
||||
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("noteB").get("noteB"));
|
||||
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
|
||||
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
|
||||
|
||||
factory.getInterpreter("user", "noteA", null).open();
|
||||
factory.getInterpreter("user", "noteB", null).open();
|
||||
|
|
@ -147,16 +147,16 @@ public class NoteInterpreterLoaderTest {
|
|||
factory.getInterpreter("user", "noteB", null).getInterpreterGroup().getId()));
|
||||
|
||||
// interpreters are created after accessing it
|
||||
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("noteA").get("noteA"));
|
||||
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("noteB").get("noteB"));
|
||||
assertNotNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
|
||||
assertNotNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
|
||||
|
||||
// when
|
||||
factory.closeNote("noteA");
|
||||
factory.closeNote("noteB");
|
||||
factory.closeNote("user", "noteA");
|
||||
factory.closeNote("user", "noteB");
|
||||
|
||||
// interpreters are destroyed after close
|
||||
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("noteA").get("noteA"));
|
||||
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("noteB").get("noteB"));
|
||||
assertNull(factory.getInterpreterSettings("noteA").get(0).getInterpreterGroup("user", "noteA").get("noteA"));
|
||||
assertNull(factory.getInterpreterSettings("noteB").get(0).getInterpreterGroup("user", "noteB").get("noteB"));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
private DependencyResolver depResolver;
|
||||
private NotebookAuthorization notebookAuthorization;
|
||||
private Credentials credentials;
|
||||
private AuthenticationInfo anonymous = new AuthenticationInfo("anonymous");
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
|
@ -106,8 +107,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
@Test
|
||||
public void testSelectingReplImplementation() throws IOException {
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
// run with default repl
|
||||
Paragraph p1 = note.addParagraph();
|
||||
|
|
@ -137,7 +138,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
FileUtils.copyDirectory(srcDir, destDir);
|
||||
|
||||
// when load
|
||||
notebook.reloadAllNotes(null);
|
||||
notebook.reloadAllNotes(anonymous);
|
||||
assertEquals(1, notebook.getAllNotes().size());
|
||||
|
||||
// then interpreter factory should be injected into all the paragraphs
|
||||
|
|
@ -169,8 +170,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
assertEquals(notes.size(), 0);
|
||||
|
||||
// load copied notebook on memory when reloadAllNotes() is called
|
||||
Note copiedNote = notebookRepo.get("2A94M5J1Z", null);
|
||||
notebook.reloadAllNotes(null);
|
||||
Note copiedNote = notebookRepo.get("2A94M5J1Z", anonymous);
|
||||
notebook.reloadAllNotes(anonymous);
|
||||
notes = notebook.getAllNotes();
|
||||
assertEquals(notes.size(), 2);
|
||||
assertEquals(notes.get(1).getId(), copiedNote.getId());
|
||||
|
|
@ -188,14 +189,14 @@ public class NotebookTest implements JobListenerFactory{
|
|||
assertEquals(notes.size(), 2);
|
||||
|
||||
// delete notebook from notebook list when reloadAllNotes() is called
|
||||
notebook.reloadAllNotes(null);
|
||||
notebook.reloadAllNotes(anonymous);
|
||||
notes = notebook.getAllNotes();
|
||||
assertEquals(notes.size(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersist() throws IOException, SchedulerException, RepositoryException {
|
||||
Note note = notebook.createNote(null);
|
||||
Note note = notebook.createNote(anonymous);
|
||||
|
||||
// run with default repl
|
||||
Paragraph p1 = note.addParagraph();
|
||||
|
|
@ -203,7 +204,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
config.put("enabled", true);
|
||||
p1.setConfig(config);
|
||||
p1.setText("hello world");
|
||||
note.persist(null);
|
||||
note.persist(anonymous);
|
||||
|
||||
Notebook notebook2 = new Notebook(
|
||||
conf, notebookRepo, schedulerFactory,
|
||||
|
|
@ -228,7 +229,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
@Test
|
||||
public void testClearParagraphOutput() throws IOException, SchedulerException{
|
||||
Note note = notebook.createNote(null);
|
||||
Note note = notebook.createNote(anonymous);
|
||||
Paragraph p1 = note.addParagraph();
|
||||
Map config = p1.getConfig();
|
||||
config.put("enabled", true);
|
||||
|
|
@ -247,8 +248,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
@Test
|
||||
public void testRunAll() throws IOException {
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
// p1
|
||||
Paragraph p1 = note.addParagraph();
|
||||
|
|
@ -280,14 +281,14 @@ public class NotebookTest implements JobListenerFactory{
|
|||
assertNull(p2.getResult());
|
||||
assertEquals("repl1: p3", p3.getResult().message());
|
||||
|
||||
notebook.removeNote(note.getId(), null);
|
||||
notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchedule() throws InterruptedException, IOException {
|
||||
// create a note and a paragraph
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
Paragraph p = note.addParagraph();
|
||||
Map config = new HashMap<String, Object>();
|
||||
|
|
@ -319,8 +320,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
@Test
|
||||
public void testAutoRestartInterpreterAfterSchedule() throws InterruptedException, IOException{
|
||||
// create a note and a paragraph
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
Paragraph p = note.addParagraph();
|
||||
Map config = new HashMap<String, Object>();
|
||||
|
|
@ -341,11 +342,11 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
|
||||
MockInterpreter1 mock1 = ((MockInterpreter1) (((ClassloaderInterpreter)
|
||||
((LazyOpenInterpreter) factory.getInterpreter("user", note.getId(), "mock1")).getInnerInterpreter())
|
||||
((LazyOpenInterpreter) factory.getInterpreter(anonymous.getUser(), note.getId(), "mock1")).getInnerInterpreter())
|
||||
.getInnerInterpreter()));
|
||||
|
||||
MockInterpreter2 mock2 = ((MockInterpreter2) (((ClassloaderInterpreter)
|
||||
((LazyOpenInterpreter) factory.getInterpreter("user", note.getId(), "mock2")).getInnerInterpreter())
|
||||
((LazyOpenInterpreter) factory.getInterpreter(anonymous.getUser(), note.getId(), "mock2")).getInnerInterpreter())
|
||||
.getInnerInterpreter()));
|
||||
|
||||
// wait until interpreters are started
|
||||
|
|
@ -372,8 +373,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
@Test
|
||||
public void testExportAndImportNote() throws IOException, CloneNotSupportedException,
|
||||
InterruptedException, InterpreterException, SchedulerException, RepositoryException {
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
final Paragraph p = note.addParagraph();
|
||||
String simpleText = "hello world";
|
||||
|
|
@ -386,7 +387,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
String exportedNoteJson = notebook.exportNote(note.getId());
|
||||
|
||||
Note importedNote = notebook.importNote(exportedNoteJson, "Title", null);
|
||||
Note importedNote = notebook.importNote(exportedNoteJson, "Title", anonymous);
|
||||
|
||||
Paragraph p2 = importedNote.getParagraphs().get(0);
|
||||
|
||||
|
|
@ -411,8 +412,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
@Test
|
||||
public void testCloneNote() throws IOException, CloneNotSupportedException,
|
||||
InterruptedException, InterpreterException, SchedulerException, RepositoryException {
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
final Paragraph p = note.addParagraph();
|
||||
p.setText("hello world");
|
||||
|
|
@ -420,7 +421,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
while(p.isTerminated()==false || p.getResult()==null) Thread.yield();
|
||||
|
||||
p.setStatus(Status.RUNNING);
|
||||
Note cloneNote = notebook.cloneNote(note.getId(), "clone note", null);
|
||||
Note cloneNote = notebook.cloneNote(note.getId(), "clone note", anonymous);
|
||||
Paragraph cp = cloneNote.paragraphs.get(0);
|
||||
assertEquals(cp.getStatus(), Status.READY);
|
||||
|
||||
|
|
@ -457,8 +458,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
@Test
|
||||
public void testCloneNoteWithExceptionResult() throws IOException, CloneNotSupportedException,
|
||||
InterruptedException {
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
final Paragraph p = note.addParagraph();
|
||||
p.setText("hello world");
|
||||
|
|
@ -469,7 +470,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
// Force paragraph to have String type object
|
||||
p.setResult("Exception");
|
||||
|
||||
Note cloneNote = notebook.cloneNote(note.getId(), "clone note with Exception result", null);
|
||||
Note cloneNote = notebook.cloneNote(note.getId(), "clone note with Exception result", anonymous);
|
||||
Paragraph cp = cloneNote.paragraphs.get(0);
|
||||
|
||||
// Keep same ParagraphID
|
||||
|
|
@ -482,8 +483,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
@Test
|
||||
public void testResourceRemovealOnParagraphNoteRemove() throws IOException {
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) {
|
||||
intpGroup.setResourcePool(new LocalResourcePool(intpGroup.getId()));
|
||||
}
|
||||
|
|
@ -499,11 +500,11 @@ public class NotebookTest implements JobListenerFactory{
|
|||
assertEquals(2, ResourcePoolUtils.getAllResources().size());
|
||||
|
||||
// remove a paragraph
|
||||
note.removeParagraph(p1.getId());
|
||||
note.removeParagraph(anonymous.getUser(), p1.getId());
|
||||
assertEquals(1, ResourcePoolUtils.getAllResources().size());
|
||||
|
||||
// remove note
|
||||
notebook.removeNote(note.getId(), null);
|
||||
notebook.removeNote(note.getId(), anonymous);
|
||||
assertEquals(0, ResourcePoolUtils.getAllResources().size());
|
||||
}
|
||||
|
||||
|
|
@ -511,11 +512,11 @@ public class NotebookTest implements JobListenerFactory{
|
|||
public void testAngularObjectRemovalOnNotebookRemove() throws InterruptedException,
|
||||
IOException {
|
||||
// create a note and a paragraph
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
AngularObjectRegistry registry = factory
|
||||
.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess")
|
||||
.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess")
|
||||
.getAngularObjectRegistry();
|
||||
|
||||
Paragraph p1 = note.addParagraph();
|
||||
|
|
@ -530,7 +531,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
registry.add("o3", "object3", null, null);
|
||||
|
||||
// remove notebook
|
||||
notebook.removeNote(note.getId(), null);
|
||||
notebook.removeNote(note.getId(), anonymous);
|
||||
|
||||
// notebook scope or paragraph scope object should be removed
|
||||
assertNull(registry.get("o1", note.getId(), null));
|
||||
|
|
@ -544,11 +545,11 @@ public class NotebookTest implements JobListenerFactory{
|
|||
public void testAngularObjectRemovalOnParagraphRemove() throws InterruptedException,
|
||||
IOException {
|
||||
// create a note and a paragraph
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
AngularObjectRegistry registry = factory
|
||||
.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess")
|
||||
.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess")
|
||||
.getAngularObjectRegistry();
|
||||
|
||||
Paragraph p1 = note.addParagraph();
|
||||
|
|
@ -563,7 +564,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
registry.add("o3", "object3", null, null);
|
||||
|
||||
// remove notebook
|
||||
note.removeParagraph(p1.getId());
|
||||
note.removeParagraph(anonymous.getUser(), p1.getId());
|
||||
|
||||
// paragraph scope should be removed
|
||||
assertNull(registry.get("o1", note.getId(), null));
|
||||
|
|
@ -578,11 +579,11 @@ public class NotebookTest implements JobListenerFactory{
|
|||
public void testAngularObjectRemovalOnInterpreterRestart() throws InterruptedException,
|
||||
IOException {
|
||||
// create a note and a paragraph
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
AngularObjectRegistry registry = factory
|
||||
.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess")
|
||||
.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess")
|
||||
.getAngularObjectRegistry();
|
||||
|
||||
// add local scope object
|
||||
|
|
@ -592,19 +593,19 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
// restart interpreter
|
||||
factory.restart(factory.getInterpreterSettings(note.getId()).get(0).getId());
|
||||
registry = factory.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup("sharedProcess")
|
||||
registry = factory.getInterpreterSettings(note.getId()).get(0).getInterpreterGroup(anonymous.getUser(), "sharedProcess")
|
||||
.getAngularObjectRegistry();
|
||||
|
||||
// local and global scope object should be removed
|
||||
assertNull(registry.get("o1", note.getId(), null));
|
||||
assertNull(registry.get("o2", null, null));
|
||||
notebook.removeNote(note.getId(), null);
|
||||
notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPermissions() throws IOException {
|
||||
// create a note and a paragraph
|
||||
Note note = notebook.createNote(null);
|
||||
Note note = notebook.createNote(anonymous);
|
||||
NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization();
|
||||
// empty owners, readers or writers means note is public
|
||||
assertEquals(notebookAuthorization.isOwner(note.getId(),
|
||||
|
|
@ -643,14 +644,14 @@ public class NotebookTest implements JobListenerFactory{
|
|||
assertEquals(notebookAuthorization.isReader(note.getId(),
|
||||
new HashSet<String>(Arrays.asList("user3"))), true);
|
||||
|
||||
notebook.removeNote(note.getId(), null);
|
||||
notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedException,
|
||||
IOException {
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
Note note = notebook.createNote(anonymous);
|
||||
factory.setInterpreters(anonymous.getUser(), note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
ArrayList<Paragraph> paragraphs = new ArrayList<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
|
@ -687,7 +688,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
@Test
|
||||
public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException {
|
||||
// create a notes
|
||||
Note note1 = notebook.createNote(null);
|
||||
Note note1 = notebook.createNote(new AuthenticationInfo());
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
p1.setText("getId");
|
||||
|
||||
|
|
@ -702,8 +703,8 @@ public class NotebookTest implements JobListenerFactory{
|
|||
InterpreterResult result = p1.getResult();
|
||||
|
||||
// remove note and recreate
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
note1 = notebook.createNote(null);
|
||||
notebook.removeNote(note1.getId(), anonymous);
|
||||
note1 = notebook.createNote(anonymous);
|
||||
p1 = note1.addParagraph();
|
||||
p1.setText("getId");
|
||||
|
||||
|
|
@ -711,16 +712,16 @@ public class NotebookTest implements JobListenerFactory{
|
|||
while (p1.getStatus() != Status.FINISHED) Thread.yield();
|
||||
assertNotEquals(p1.getResult().message(), result.message());
|
||||
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
notebook.removeNote(note1.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSessionInterpreter() throws IOException {
|
||||
// create two notes
|
||||
Note note1 = notebook.createNote(null);
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
|
||||
Note note2 = notebook.createNote(null);
|
||||
Note note2 = notebook.createNote(anonymous);
|
||||
Paragraph p2 = note2.addParagraph();
|
||||
|
||||
p1.setText("getId");
|
||||
|
|
@ -751,15 +752,16 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
assertNotEquals(p1.getResult().message(), p2.getResult().message());
|
||||
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
notebook.removeNote(note2.getId(), null);
|
||||
notebook.removeNote(note1.getId(), anonymous);
|
||||
notebook.removeNote(note2.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerSessionInterpreterCloseOnUnbindInterpreterSetting() throws IOException {
|
||||
// create a notes
|
||||
Note note1 = notebook.createNote(null);
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
p1.setAuthenticationInfo(anonymous);
|
||||
p1.setText("getId");
|
||||
|
||||
// restart interpreter with per note session enabled
|
||||
|
|
@ -775,15 +777,15 @@ public class NotebookTest implements JobListenerFactory{
|
|||
|
||||
// unbind, and rebind setting. that result interpreter instance close
|
||||
List<String> bindedSettings = notebook.getBindedInterpreterSettingsIds(note1.getId());
|
||||
notebook.bindInterpretersToNote(note1.getId(), new LinkedList<String>());
|
||||
notebook.bindInterpretersToNote(note1.getId(), bindedSettings);
|
||||
notebook.bindInterpretersToNote(anonymous.getUser(), note1.getId(), new LinkedList<String>());
|
||||
notebook.bindInterpretersToNote(anonymous.getUser(), note1.getId(), bindedSettings);
|
||||
|
||||
note1.run(p1.getId());
|
||||
while (p1.getStatus() != Status.FINISHED) Thread.yield();
|
||||
|
||||
assertNotEquals(result.message(), p1.getResult().message());
|
||||
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
notebook.removeNote(note1.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -825,7 +827,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
}
|
||||
});
|
||||
|
||||
Note note1 = notebook.createNote(null);
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
assertEquals(1, onNoteCreate.get());
|
||||
|
||||
Paragraph p1 = note1.addParagraph();
|
||||
|
|
@ -834,14 +836,14 @@ public class NotebookTest implements JobListenerFactory{
|
|||
note1.addCloneParagraph(p1);
|
||||
assertEquals(2, onParagraphCreate.get());
|
||||
|
||||
note1.removeParagraph(p1.getId());
|
||||
note1.removeParagraph(anonymous.getUser(), p1.getId());
|
||||
assertEquals(1, onParagraphRemove.get());
|
||||
|
||||
List<String> settings = notebook.getBindedInterpreterSettingsIds(note1.getId());
|
||||
notebook.bindInterpretersToNote(note1.getId(), new LinkedList<String>());
|
||||
notebook.bindInterpretersToNote(anonymous.getUser(), note1.getId(), new LinkedList<String>());
|
||||
assertEquals(settings.size(), unbindInterpreter.get());
|
||||
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
notebook.removeNote(note1.getId(), anonymous);
|
||||
assertEquals(1, onNoteRemove.get());
|
||||
assertEquals(1, onParagraphRemove.get());
|
||||
}
|
||||
|
|
@ -849,7 +851,7 @@ public class NotebookTest implements JobListenerFactory{
|
|||
@Test
|
||||
public void testNormalizeNoteName() throws IOException {
|
||||
// create a notes
|
||||
Note note1 = notebook.createNote(null);
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
|
||||
note1.setName("MyNote");
|
||||
assertEquals(note1.getName(), "MyNote");
|
||||
|
|
@ -869,25 +871,25 @@ public class NotebookTest implements JobListenerFactory{
|
|||
note1.setName("\\\\\\MyNote///sub");
|
||||
assertEquals(note1.getName(), "/MyNote/sub");
|
||||
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
notebook.removeNote(note1.getId(), anonymous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllNotes() throws Exception {
|
||||
Note note1 = notebook.createNote(null);
|
||||
Note note2 = notebook.createNote(null);
|
||||
assertEquals(2, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size());
|
||||
Note note1 = notebook.createNote(anonymous);
|
||||
Note note2 = notebook.createNote(anonymous);
|
||||
assertEquals(2, notebook.getAllNotes(anonymous).size());
|
||||
|
||||
notebook.getNotebookAuthorization().setOwners(note1.getId(), Sets.newHashSet("user1"));
|
||||
notebook.getNotebookAuthorization().setWriters(note1.getId(), Sets.newHashSet("user1"));
|
||||
notebook.getNotebookAuthorization().setReaders(note1.getId(), Sets.newHashSet("user1"));
|
||||
assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size());
|
||||
assertEquals(1, notebook.getAllNotes(anonymous).size());
|
||||
assertEquals(2, notebook.getAllNotes(new AuthenticationInfo("user1")).size());
|
||||
|
||||
notebook.getNotebookAuthorization().setOwners(note2.getId(), Sets.newHashSet("user2"));
|
||||
notebook.getNotebookAuthorization().setWriters(note2.getId(), Sets.newHashSet("user2"));
|
||||
notebook.getNotebookAuthorization().setReaders(note2.getId(), Sets.newHashSet("user2"));
|
||||
assertEquals(0, notebook.getAllNotes(new AuthenticationInfo("anonymous")).size());
|
||||
assertEquals(0, notebook.getAllNotes(anonymous).size());
|
||||
assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("user1")).size());
|
||||
assertEquals(1, notebook.getAllNotes(new AuthenticationInfo("user2")).size());
|
||||
notebook.removeNote(note1.getId(), null);
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class VFSNotebookRepoTest implements JobListenerFactory {
|
|||
@Test
|
||||
public void testSaveNotebook() throws IOException, InterruptedException {
|
||||
Note note = notebook.createNote(null);
|
||||
factory.setInterpreters(note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
factory.setInterpreters("user", note.getId(), factory.getDefaultInterpreterSettingList());
|
||||
|
||||
Paragraph p1 = note.addParagraph();
|
||||
Map<String, Object> config = p1.getConfig();
|
||||
|
|
|
|||
Loading…
Reference in a new issue