use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class NotebookTest method testNotebookEventListener.
public void testNotebookEventListener() throws IOException {
final AtomicInteger onNoteRemove = new AtomicInteger(0);
final AtomicInteger onNoteCreate = new AtomicInteger(0);
final AtomicInteger onParagraphRemove = new AtomicInteger(0);
final AtomicInteger onParagraphCreate = new AtomicInteger(0);
notebook.addNotebookEventListener(new NoteEventListener() {
@Override
public void onNoteRemove(Note note, AuthenticationInfo subject) {
onNoteRemove.incrementAndGet();
}
@Override
public void onNoteCreate(Note note, AuthenticationInfo subject) {
onNoteCreate.incrementAndGet();
}
@Override
public void onNoteUpdate(Note note, AuthenticationInfo subject) {
}
@Override
public void onParagraphRemove(Paragraph p) {
onParagraphRemove.incrementAndGet();
}
@Override
public void onParagraphCreate(Paragraph p) {
onParagraphCreate.incrementAndGet();
}
@Override
public void onParagraphUpdate(Paragraph p) {
}
@Override
public void onParagraphStatusChange(Paragraph p, Status status) {
}
});
String note1Id = notebook.createNote("note1", anonymous);
assertEquals(1, onNoteCreate.get());
notebook.processNote(note1Id, note1 -> {
Paragraph p1 = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
assertEquals(1, onParagraphCreate.get());
note1.addCloneParagraph(p1, AuthenticationInfo.ANONYMOUS);
assertEquals(2, onParagraphCreate.get());
note1.removeParagraph(anonymous.getUser(), p1.getId());
assertEquals(1, onParagraphRemove.get());
return null;
});
notebook.removeNote(note1Id, anonymous);
assertEquals(1, onNoteRemove.get());
assertEquals(1, onParagraphRemove.get());
}
use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class NotebookRepoSyncTest method setUp.
@Before
public void setUp() throws Exception {
System.setProperty("zeppelin.isTest", "true");
ZEPPELIN_HOME = Files.createTempDir();
new File(ZEPPELIN_HOME, "conf").mkdirs();
String mainNotePath = ZEPPELIN_HOME.getAbsolutePath() + "/notebook";
String secNotePath = ZEPPELIN_HOME.getAbsolutePath() + "/notebook_secondary";
mainNotebookDir = new File(mainNotePath);
secNotebookDir = new File(secNotePath);
mainNotebookDir.mkdirs();
secNotebookDir.mkdirs();
System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), ZEPPELIN_HOME.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath());
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.VFSNotebookRepo,org.apache.zeppelin.notebook.repo.mock.VFSNotebookRepoMock");
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_ONE_WAY_SYNC.getVarName(), "false");
System.setProperty(ConfVars.ZEPPELIN_CONFIG_FS_DIR.getVarName(), ZEPPELIN_HOME.getAbsolutePath() + "/conf");
System.setProperty(ConfVars.ZEPPELIN_PLUGINS_DIR.getVarName(), new File("../../../plugins").getAbsolutePath());
LOG.info("main Note dir : " + mainNotePath);
LOG.info("secondary note dir : " + secNotePath);
conf = ZeppelinConfiguration.create();
ConfigStorage.reset();
interpreterSettingManager = new InterpreterSettingManager(conf, mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class));
factory = new InterpreterFactory(interpreterSettingManager);
notebookRepoSync = new NotebookRepoSync(conf);
noteManager = new NoteManager(notebookRepoSync, conf);
authorizationService = new AuthorizationService(noteManager, conf);
credentials = new Credentials(conf);
notebook = new Notebook(conf, authorizationService, notebookRepoSync, noteManager, factory, interpreterSettingManager, credentials, null);
anonymous = new AuthenticationInfo("anonymous");
}
use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class NotebookRepoSyncTest method testSyncWithAcl.
@Test
public void testSyncWithAcl() throws IOException {
/* scenario 1 - note exists with acl on main storage */
AuthenticationInfo user1 = new AuthenticationInfo("user1");
String noteId = notebook.createNote("/test", "test", user1);
notebook.processNote(noteId, note -> {
assertEquals(0, note.getParagraphs().size());
return null;
});
// saved on both storages
assertEquals(1, notebookRepoSync.list(0, null).size());
assertEquals(1, notebookRepoSync.list(1, null).size());
/* check that user1 is the only owner */
Set<String> entity = new HashSet<String>();
entity.add(user1.getUser());
assertEquals(true, authorizationService.isOwner(noteId, entity));
assertEquals(1, authorizationService.getOwners(noteId).size());
assertEquals(0, authorizationService.getReaders(noteId).size());
assertEquals(0, authorizationService.getRunners(noteId).size());
assertEquals(0, authorizationService.getWriters(noteId).size());
/* update note and save on secondary storage */
notebook.processNote(noteId, note -> {
note.setInterpreterFactory(mock(InterpreterFactory.class));
Paragraph p1 = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p1.setText("hello world");
assertEquals(1, note.getParagraphs().size());
notebookRepoSync.save(1, note, null);
return null;
});
/* check paragraph isn't saved into first storage */
assertEquals(0, notebookRepoSync.get(0, notebookRepoSync.list(0, null).get(0).getId(), notebookRepoSync.list(0, null).get(0).getPath(), null).getParagraphs().size());
/* check paragraph is saved into second storage */
assertEquals(1, notebookRepoSync.get(1, notebookRepoSync.list(1, null).get(0).getId(), notebookRepoSync.list(1, null).get(0).getPath(), null).getParagraphs().size());
/* now sync by user1 */
notebookRepoSync.sync(user1);
/* check that note updated and acl are same on main storage*/
assertEquals(1, notebookRepoSync.get(0, notebookRepoSync.list(0, null).get(0).getId(), notebookRepoSync.list(0, null).get(0).getPath(), null).getParagraphs().size());
assertEquals(true, authorizationService.isOwner(noteId, entity));
assertEquals(1, authorizationService.getOwners(noteId).size());
assertEquals(0, authorizationService.getReaders(noteId).size());
assertEquals(0, authorizationService.getRunners(noteId).size());
assertEquals(0, authorizationService.getWriters(noteId).size());
/* scenario 2 - note doesn't exist on main storage */
/* remove from main storage */
notebook.processNote(noteId, note -> {
notebookRepoSync.remove(0, noteId, note.getPath(), user1);
return null;
});
assertEquals(0, notebookRepoSync.list(0, null).size());
assertEquals(1, notebookRepoSync.list(1, null).size());
/* now sync - should bring note from secondary storage with added acl */
notebookRepoSync.sync(user1);
assertEquals(1, notebookRepoSync.list(0, null).size());
assertEquals(1, notebookRepoSync.list(1, null).size());
assertEquals(1, authorizationService.getOwners(noteId).size());
assertEquals(0, authorizationService.getReaders(noteId).size());
assertEquals(0, authorizationService.getRunners(noteId).size());
assertEquals(0, authorizationService.getWriters(noteId).size());
}
use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class NotebookTest method testCloneNote.
@Test
public void testCloneNote() throws Exception {
String noteId = notebook.createNote("note1", anonymous);
notebook.processNote(noteId, note -> {
final Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
p.setText("hello world");
try {
note.runAll(anonymous, true, false, new HashMap<>());
} catch (Exception e) {
fail();
}
p.setStatus(Status.RUNNING);
return null;
});
String cloneNoteId = notebook.cloneNote(noteId, "clone note", anonymous);
notebook.processNote(noteId, note -> {
Paragraph p = note.getParagraph(0);
notebook.processNote(cloneNoteId, cloneNote -> {
Paragraph cp = cloneNote.getParagraph(0);
assertEquals(Status.READY, cp.getStatus());
// Keep same ParagraphId
assertEquals(cp.getId(), p.getId());
assertEquals(cp.getText(), p.getText());
assertEquals(cp.getReturn().message().get(0).getData(), p.getReturn().message().get(0).getData());
return null;
});
return null;
});
// Verify clone note with subject
AuthenticationInfo subject = new AuthenticationInfo("user1");
String cloneNote2Id = notebook.cloneNote(noteId, "clone note2", subject);
assertNotNull(authorizationService.getOwners(cloneNote2Id));
assertEquals(1, authorizationService.getOwners(cloneNote2Id).size());
Set<String> owners = new HashSet<>();
owners.add("user1");
assertEquals(owners, authorizationService.getOwners(cloneNote2Id));
notebook.removeNote(noteId, anonymous);
notebook.removeNote(cloneNoteId, anonymous);
notebook.removeNote(cloneNote2Id, anonymous);
}
use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class Notebook method loadNoteFromRepo.
@SuppressWarnings("rawtypes")
public Note loadNoteFromRepo(String id, AuthenticationInfo subject) {
Note note = null;
try {
// note can be safely returned here, because it's just broadcasted in json later on
note = processNote(id, n -> n);
} catch (IOException e) {
LOGGER.error("Fail to get note: {}", id, e);
return null;
}
if (note == null) {
return null;
}
// Manually inject ALL dependencies, as DI constructor was NOT used
note.setCredentials(this.credentials);
note.setInterpreterFactory(replFactory);
note.setInterpreterSettingManager(interpreterSettingManager);
note.setParagraphJobListener(this.paragraphJobListener);
note.setCronSupported(getConf());
if (note.getDefaultInterpreterGroup() == null) {
note.setDefaultInterpreterGroup(conf.getString(ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT));
}
Map<String, SnapshotAngularObject> angularObjectSnapshot = new HashMap<>();
// restore angular object --------------
Date lastUpdatedDate = new Date(0);
for (Paragraph p : note.getParagraphs()) {
p.setNote(note);
if (p.getDateFinished() != null && lastUpdatedDate.before(p.getDateFinished())) {
lastUpdatedDate = p.getDateFinished();
}
}
Map<String, List<AngularObject>> savedObjects = note.getAngularObjects();
if (savedObjects != null) {
for (Entry<String, List<AngularObject>> intpGroupNameEntry : savedObjects.entrySet()) {
String intpGroupName = intpGroupNameEntry.getKey();
List<AngularObject> objectList = intpGroupNameEntry.getValue();
for (AngularObject object : objectList) {
SnapshotAngularObject snapshot = angularObjectSnapshot.get(object.getName());
if (snapshot == null || snapshot.getLastUpdate().before(lastUpdatedDate)) {
angularObjectSnapshot.put(object.getName(), new SnapshotAngularObject(intpGroupName, object, lastUpdatedDate));
}
}
}
}
note.setNoteEventListeners(this.noteEventListeners);
for (Entry<String, SnapshotAngularObject> angularObjectSnapshotEntry : angularObjectSnapshot.entrySet()) {
String name = angularObjectSnapshotEntry.getKey();
SnapshotAngularObject snapshot = angularObjectSnapshotEntry.getValue();
List<InterpreterSetting> settings = interpreterSettingManager.get();
for (InterpreterSetting setting : settings) {
InterpreterGroup intpGroup = setting.getInterpreterGroup(note.getExecutionContext());
if (intpGroup != null && intpGroup.getId().equals(snapshot.getIntpGroupId())) {
AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
String noteId = snapshot.getAngularObject().getNoteId();
String paragraphId = snapshot.getAngularObject().getParagraphId();
// at this point, remote interpreter process is not created.
// so does not make sense add it to the remote.
//
// therefore instead of addAndNotifyRemoteProcess(), need to use add()
// that results add angularObject only in ZeppelinServer side not remoteProcessSide
registry.add(name, snapshot.getAngularObject().get(), noteId, paragraphId);
}
}
}
return note;
}
Aggregations