Search in sources :

Example 36 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookRepoSyncTest method setUp.

@Before
public void setUp() throws Exception {
    String zpath = System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis();
    mainZepDir = new File(zpath);
    mainZepDir.mkdirs();
    new File(mainZepDir, "conf").mkdirs();
    String mainNotePath = zpath + "/notebook";
    String secNotePath = mainNotePath + "_secondary";
    mainNotebookDir = new File(mainNotePath);
    secNotebookDir = new File(secNotePath);
    mainNotebookDir.mkdirs();
    secNotebookDir.mkdirs();
    System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), mainZepDir.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");
    LOG.info("main Note dir : " + mainNotePath);
    LOG.info("secondary note dir : " + secNotePath);
    conf = ZeppelinConfiguration.create();
    this.schedulerFactory = new SchedulerFactory();
    depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo");
    interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
    factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
    search = mock(SearchService.class);
    notebookRepoSync = new NotebookRepoSync(conf);
    notebookAuthorization = NotebookAuthorization.init(conf);
    credentials = new Credentials(conf.credentialsPersist(), conf.getCredentialsPath());
    notebookSync = new Notebook(conf, notebookRepoSync, schedulerFactory, factory, interpreterSettingManager, this, search, notebookAuthorization, credentials);
    anonymous = new AuthenticationInfo("anonymous");
}
Also used : InterpreterOption(org.apache.zeppelin.interpreter.InterpreterOption) SearchService(org.apache.zeppelin.search.SearchService) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) File(java.io.File) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) Credentials(org.apache.zeppelin.user.Credentials) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) SchedulerFactory(org.apache.zeppelin.scheduler.SchedulerFactory) DependencyResolver(org.apache.zeppelin.dep.DependencyResolver) Before(org.junit.Before)

Example 37 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class InterpreterFactoryTest method getEditorSetting.

@Test
public void getEditorSetting() throws IOException, RepositoryException, SchedulerException {
    List<String> intpIds = new ArrayList<>();
    for (InterpreterSetting intpSetting : interpreterSettingManager.get()) {
        if (intpSetting.getName().startsWith("mock1")) {
            intpIds.add(intpSetting.getId());
        }
    }
    Note note = notebook.createNote(intpIds, new AuthenticationInfo("anonymous"));
    Interpreter interpreter = factory.getInterpreter("user1", note.getId(), "mock11");
    // get editor setting from interpreter-setting.json
    Map<String, Object> editor = interpreterSettingManager.getEditorSetting(interpreter, "user1", note.getId(), "mock11");
    assertEquals("java", editor.get("language"));
    // when interpreter is not loaded via interpreter-setting.json
    // or editor setting doesn't exit
    editor = interpreterSettingManager.getEditorSetting(factory.getInterpreter("user1", note.getId(), "mock1"), "user1", note.getId(), "mock1");
    assertEquals(null, editor.get("language"));
    // when interpreter is not bound to note
    editor = interpreterSettingManager.getEditorSetting(factory.getInterpreter("user1", note.getId(), "mock11"), "user1", note.getId(), "mock2");
    assertEquals("text", editor.get("language"));
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) Note(org.apache.zeppelin.notebook.Note) ArrayList(java.util.ArrayList) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Test(org.junit.Test)

Example 38 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookTest method testPublicPrivateNewNote.

@Test
public void testPublicPrivateNewNote() throws IOException, SchedulerException {
    HashSet<String> user1 = Sets.newHashSet("user1");
    HashSet<String> user2 = Sets.newHashSet("user2");
    // case of public note
    assertTrue(conf.isNotebokPublic());
    assertTrue(notebookAuthorization.isPublic());
    List<Note> notes1 = notebook.getAllNotes(user1);
    List<Note> notes2 = notebook.getAllNotes(user2);
    assertEquals(notes1.size(), 0);
    assertEquals(notes2.size(), 0);
    // user1 creates note
    Note notePublic = notebook.createNote(new AuthenticationInfo("user1"));
    // both users have note
    notes1 = notebook.getAllNotes(user1);
    notes2 = notebook.getAllNotes(user2);
    assertEquals(notes1.size(), 1);
    assertEquals(notes2.size(), 1);
    assertEquals(notes1.get(0).getId(), notePublic.getId());
    assertEquals(notes2.get(0).getId(), notePublic.getId());
    // user1 is only owner
    assertEquals(notebookAuthorization.getOwners(notePublic.getId()).size(), 1);
    assertEquals(notebookAuthorization.getReaders(notePublic.getId()).size(), 0);
    assertEquals(notebookAuthorization.getWriters(notePublic.getId()).size(), 0);
    // case of private note
    System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_PUBLIC.getVarName(), "false");
    ZeppelinConfiguration conf2 = ZeppelinConfiguration.create();
    assertFalse(conf2.isNotebokPublic());
    // notebook authorization reads from conf, so no need to re-initilize
    assertFalse(notebookAuthorization.isPublic());
    // check that still 1 note per user
    notes1 = notebook.getAllNotes(user1);
    notes2 = notebook.getAllNotes(user2);
    assertEquals(notes1.size(), 1);
    assertEquals(notes2.size(), 1);
    // create private note
    Note notePrivate = notebook.createNote(new AuthenticationInfo("user1"));
    // only user1 have notePrivate right after creation
    notes1 = notebook.getAllNotes(user1);
    notes2 = notebook.getAllNotes(user2);
    assertEquals(notes1.size(), 2);
    assertEquals(notes2.size(), 1);
    assertEquals(true, notes1.contains(notePrivate));
    // user1 have all rights
    assertEquals(notebookAuthorization.getOwners(notePrivate.getId()).size(), 1);
    assertEquals(notebookAuthorization.getReaders(notePrivate.getId()).size(), 1);
    assertEquals(notebookAuthorization.getWriters(notePrivate.getId()).size(), 1);
    //set back public to true
    System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_PUBLIC.getVarName(), "true");
    ZeppelinConfiguration.create();
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Test(org.junit.Test)

Example 39 with AuthenticationInfo

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");
    Note note = notebookSync.createNote(user1);
    assertEquals(0, note.getParagraphs().size());
    // 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 */
    NotebookAuthorization authInfo = NotebookAuthorization.getInstance();
    Set<String> entity = new HashSet<String>();
    entity.add(user1.getUser());
    assertEquals(true, authInfo.isOwner(note.getId(), entity));
    assertEquals(1, authInfo.getOwners(note.getId()).size());
    assertEquals(0, authInfo.getReaders(note.getId()).size());
    assertEquals(0, authInfo.getWriters(note.getId()).size());
    /* update note and save on secondary storage */
    Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    p1.setText("hello world");
    assertEquals(1, note.getParagraphs().size());
    notebookRepoSync.save(1, note, null);
    /* check paragraph isn't saved into first storage */
    assertEquals(0, notebookRepoSync.get(0, notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size());
    /* check paragraph is saved into second storage */
    assertEquals(1, notebookRepoSync.get(1, notebookRepoSync.list(1, null).get(0).getId(), 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(), null).getParagraphs().size());
    assertEquals(true, authInfo.isOwner(note.getId(), entity));
    assertEquals(1, authInfo.getOwners(note.getId()).size());
    assertEquals(0, authInfo.getReaders(note.getId()).size());
    assertEquals(0, authInfo.getWriters(note.getId()).size());
    /* scenario 2 - note doesn't exist on main storage */
    /* remove from main storage */
    notebookRepoSync.remove(0, note.getId(), user1);
    assertEquals(0, notebookRepoSync.list(0, null).size());
    assertEquals(1, notebookRepoSync.list(1, null).size());
    authInfo.removeNote(note.getId());
    assertEquals(0, authInfo.getOwners(note.getId()).size());
    assertEquals(0, authInfo.getReaders(note.getId()).size());
    assertEquals(0, authInfo.getWriters(note.getId()).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, authInfo.getOwners(note.getId()).size());
    assertEquals(1, authInfo.getReaders(note.getId()).size());
    assertEquals(1, authInfo.getWriters(note.getId()).size());
    assertEquals(true, authInfo.isOwner(note.getId(), entity));
    assertEquals(true, authInfo.isReader(note.getId(), entity));
    assertEquals(true, authInfo.isWriter(note.getId(), entity));
}
Also used : AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class VFSNotebookRepoTest method testSaveNotebook.

@Test
public void testSaveNotebook() throws IOException, InterruptedException {
    AuthenticationInfo anonymous = new AuthenticationInfo("anonymous");
    Note note = notebook.createNote(anonymous);
    interpreterSettingManager.setInterpreters("user", note.getId(), interpreterSettingManager.getDefaultInterpreterSettingList());
    Paragraph p1 = note.addParagraph(AuthenticationInfo.ANONYMOUS);
    Map<String, Object> config = p1.getConfig();
    config.put("enabled", true);
    p1.setConfig(config);
    p1.setText("%mock1 hello world");
    p1.setAuthenticationInfo(anonymous);
    note.run(p1.getId());
    int timeout = 1;
    while (!p1.isTerminated()) {
        Thread.sleep(1000);
        if (timeout++ > 10) {
            break;
        }
    }
    int i = 0;
    int TEST_COUNT = 10;
    while (i++ < TEST_COUNT) {
        p1.setText("%mock1 hello zeppelin");
        new Thread(new NotebookWriter(note)).start();
        p1.setText("%mock1 hello world");
        new Thread(new NotebookWriter(note)).start();
    }
    note.setName("SaveTest");
    notebookRepo.save(note, null);
    assertEquals(note.getName(), "SaveTest");
    notebookRepo.remove(note.getId(), null);
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Aggregations

AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)88 HashMap (java.util.HashMap)27 Note (org.apache.zeppelin.notebook.Note)27 Test (org.junit.Test)22 LinkedList (java.util.LinkedList)19 Properties (java.util.Properties)19 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)19 GUI (org.apache.zeppelin.display.GUI)19 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)17 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)16 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)15 Path (javax.ws.rs.Path)14 Message (org.apache.zeppelin.notebook.socket.Message)14 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)14 Paragraph (org.apache.zeppelin.notebook.Paragraph)12 Before (org.junit.Before)12 Map (java.util.Map)11 File (java.io.File)10 AngularObject (org.apache.zeppelin.display.AngularObject)9 POST (javax.ws.rs.POST)6