Search in sources :

Example 1 with NoteManager

use of org.apache.zeppelin.notebook.NoteManager in project zeppelin by apache.

the class NotebookRepoSyncTest method testCheckpointOneStorage.

@Test
public void testCheckpointOneStorage() throws IOException, SchedulerException {
    System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.GitNotebookRepo");
    ZeppelinConfiguration vConf = ZeppelinConfiguration.create();
    NotebookRepoSync vRepoSync = new NotebookRepoSync(vConf);
    Notebook vNotebookSync = new Notebook(vConf, mock(AuthorizationService.class), vRepoSync, new NoteManager(vRepoSync, conf), factory, interpreterSettingManager, credentials, null);
    // one git versioned storage initialized
    assertEquals(1, vRepoSync.getRepoCount());
    assertTrue(vRepoSync.getRepo(0) instanceof GitNotebookRepo);
    GitNotebookRepo gitRepo = (GitNotebookRepo) vRepoSync.getRepo(0);
    // no notes
    assertEquals(0, vRepoSync.list(anonymous).size());
    // create note
    String noteIdTmp = vNotebookSync.createNote("/test", "test", anonymous);
    System.out.println(noteIdTmp);
    Note note = vNotebookSync.processNote(noteIdTmp, noteTmp -> {
        return noteTmp;
    });
    assertEquals(1, vRepoSync.list(anonymous).size());
    System.out.println(note);
    NoteInfo noteInfo = vRepoSync.list(anonymous).values().iterator().next();
    String noteId = noteInfo.getId();
    String notePath = noteInfo.getPath();
    // first checkpoint
    vRepoSync.checkpoint(noteId, notePath, "checkpoint message", anonymous);
    int vCount = gitRepo.revisionHistory(noteId, notePath, anonymous).size();
    assertEquals(1, vCount);
    note.setInterpreterFactory(mock(InterpreterFactory.class));
    Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    Map<String, Object> config = p.getConfig();
    config.put("enabled", true);
    p.setConfig(config);
    p.setText("%md checkpoint test");
    // save and checkpoint again
    vRepoSync.save(note, anonymous);
    vRepoSync.checkpoint(noteId, notePath, "checkpoint message 2", anonymous);
    assertEquals(vCount + 1, gitRepo.revisionHistory(noteId, notePath, anonymous).size());
    notebookRepoSync.remove(note.getId(), note.getPath(), anonymous);
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) Paragraph(org.apache.zeppelin.notebook.Paragraph) NoteInfo(org.apache.zeppelin.notebook.NoteInfo) AuthorizationService(org.apache.zeppelin.notebook.AuthorizationService) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) Note(org.apache.zeppelin.notebook.Note) NoteManager(org.apache.zeppelin.notebook.NoteManager) Test(org.junit.Test)

Example 2 with NoteManager

use of org.apache.zeppelin.notebook.NoteManager 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");
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) AuthorizationService(org.apache.zeppelin.notebook.AuthorizationService) NoteManager(org.apache.zeppelin.notebook.NoteManager) 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) Before(org.junit.Before)

Example 3 with NoteManager

use of org.apache.zeppelin.notebook.NoteManager in project zeppelin by apache.

the class LuceneSearchTest method startUp.

@Before
public void startUp() throws IOException {
    indexDir = Files.createTempDirectory("lucene").toFile();
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SEARCH_INDEX_PATH.getVarName(), indexDir.getAbsolutePath());
    ZeppelinConfiguration conf = ZeppelinConfiguration.create();
    noteManager = new NoteManager(new InMemoryNotebookRepo(), conf);
    interpreterSettingManager = mock(InterpreterSettingManager.class);
    InterpreterSetting defaultInterpreterSetting = mock(InterpreterSetting.class);
    when(defaultInterpreterSetting.getName()).thenReturn("test");
    when(interpreterSettingManager.getDefaultInterpreterSetting()).thenReturn(defaultInterpreterSetting);
    notebook = new Notebook(conf, mock(AuthorizationService.class), mock(NotebookRepo.class), noteManager, mock(InterpreterFactory.class), interpreterSettingManager, mock(Credentials.class), null);
    noteSearchService = new LuceneSearch(ZeppelinConfiguration.create(), notebook);
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) NoteManager(org.apache.zeppelin.notebook.NoteManager) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) InMemoryNotebookRepo(org.apache.zeppelin.notebook.repo.InMemoryNotebookRepo) Before(org.junit.Before)

Example 4 with NoteManager

use of org.apache.zeppelin.notebook.NoteManager in project zeppelin by apache.

the class AbstractInterpreterTest method setUp.

@Before
public void setUp() throws Exception {
    // copy the resources files to a temp folder
    zeppelinHome = new File("..");
    LOGGER.info("ZEPPELIN_HOME: " + zeppelinHome.getAbsolutePath());
    interpreterDir = new File(zeppelinHome, "interpreter_" + getClass().getSimpleName());
    confDir = new File(zeppelinHome, "conf_" + getClass().getSimpleName());
    notebookDir = new File(zeppelinHome, "notebook_" + getClass().getSimpleName());
    FileUtils.deleteDirectory(notebookDir);
    interpreterDir.mkdirs();
    confDir.mkdirs();
    notebookDir.mkdirs();
    FileUtils.copyDirectory(new File("src/test/resources/interpreter"), interpreterDir);
    FileUtils.copyDirectory(new File("src/test/resources/conf"), confDir);
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinHome.getAbsolutePath());
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), confDir.getAbsolutePath());
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_DIR.getVarName(), interpreterDir.getAbsolutePath());
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT.getVarName(), "test");
    conf = ZeppelinConfiguration.create();
    NotebookRepo notebookRepo = new InMemoryNotebookRepo();
    NoteManager noteManager = new NoteManager(notebookRepo, conf);
    AuthorizationService authorizationService = new AuthorizationService(noteManager, conf);
    interpreterSettingManager = new InterpreterSettingManager(conf, mock(AngularObjectRegistryListener.class), mock(RemoteInterpreterProcessListener.class), mock(ApplicationEventListener.class));
    interpreterFactory = new InterpreterFactory(interpreterSettingManager);
    Credentials credentials = new Credentials(conf);
    notebook = new Notebook(conf, authorizationService, notebookRepo, noteManager, interpreterFactory, interpreterSettingManager, credentials);
    interpreterSettingManager.setNotebook(notebook);
}
Also used : NotebookRepo(org.apache.zeppelin.notebook.repo.NotebookRepo) InMemoryNotebookRepo(org.apache.zeppelin.notebook.repo.InMemoryNotebookRepo) Notebook(org.apache.zeppelin.notebook.Notebook) AuthorizationService(org.apache.zeppelin.notebook.AuthorizationService) NoteManager(org.apache.zeppelin.notebook.NoteManager) File(java.io.File) InMemoryNotebookRepo(org.apache.zeppelin.notebook.repo.InMemoryNotebookRepo) Credentials(org.apache.zeppelin.user.Credentials) Before(org.junit.Before)

Example 5 with NoteManager

use of org.apache.zeppelin.notebook.NoteManager in project zeppelin by apache.

the class NotebookServiceTest method setUp.

@Before
public void setUp() throws Exception {
    notebookDir = Files.createTempDirectory("notebookDir").toAbsolutePath().toFile();
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
    ZeppelinConfiguration zeppelinConfiguration = ZeppelinConfiguration.create();
    NotebookRepo notebookRepo = new VFSNotebookRepo();
    notebookRepo.init(zeppelinConfiguration);
    InterpreterSettingManager mockInterpreterSettingManager = mock(InterpreterSettingManager.class);
    InterpreterFactory mockInterpreterFactory = mock(InterpreterFactory.class);
    Interpreter mockInterpreter = mock(Interpreter.class);
    when(mockInterpreterFactory.getInterpreter(any(), any())).thenReturn(mockInterpreter);
    when(mockInterpreter.interpret(eq("invalid_code"), any())).thenReturn(new InterpreterResult(Code.ERROR, "failed"));
    when(mockInterpreter.interpret(eq("1+1"), any())).thenReturn(new InterpreterResult(Code.SUCCESS, "succeed"));
    doCallRealMethod().when(mockInterpreter).getScheduler();
    when(mockInterpreter.getFormType()).thenReturn(FormType.NATIVE);
    ManagedInterpreterGroup mockInterpreterGroup = mock(ManagedInterpreterGroup.class);
    when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
    InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
    when(mockInterpreterSetting.isUserAuthorized(any())).thenReturn(true);
    when(mockInterpreterGroup.getInterpreterSetting()).thenReturn(mockInterpreterSetting);
    when(mockInterpreterSetting.getStatus()).thenReturn(InterpreterSetting.Status.READY);
    Credentials credentials = new Credentials();
    NoteManager noteManager = new NoteManager(notebookRepo, zeppelinConfiguration);
    AuthorizationService authorizationService = new AuthorizationService(noteManager, zeppelinConfiguration);
    notebook = new Notebook(zeppelinConfiguration, authorizationService, notebookRepo, noteManager, mockInterpreterFactory, mockInterpreterSettingManager, credentials, null);
    searchService = new LuceneSearch(zeppelinConfiguration, notebook);
    QuartzSchedulerService schedulerService = new QuartzSchedulerService(zeppelinConfiguration, notebook);
    schedulerService.waitForFinishInit();
    notebookService = new NotebookService(notebook, authorizationService, zeppelinConfiguration, schedulerService);
    String interpreterName = "test";
    when(mockInterpreterSetting.getName()).thenReturn(interpreterName);
    when(mockInterpreterSettingManager.getDefaultInterpreterSetting()).thenReturn(mockInterpreterSetting);
}
Also used : NotebookRepo(org.apache.zeppelin.notebook.repo.NotebookRepo) VFSNotebookRepo(org.apache.zeppelin.notebook.repo.VFSNotebookRepo) Interpreter(org.apache.zeppelin.interpreter.Interpreter) Notebook(org.apache.zeppelin.notebook.Notebook) QuartzSchedulerService(org.apache.zeppelin.notebook.scheduler.QuartzSchedulerService) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) VFSNotebookRepo(org.apache.zeppelin.notebook.repo.VFSNotebookRepo) AuthorizationService(org.apache.zeppelin.notebook.AuthorizationService) LuceneSearch(org.apache.zeppelin.search.LuceneSearch) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) NoteManager(org.apache.zeppelin.notebook.NoteManager) Credentials(org.apache.zeppelin.user.Credentials) Before(org.junit.Before)

Aggregations

NoteManager (org.apache.zeppelin.notebook.NoteManager)7 Notebook (org.apache.zeppelin.notebook.Notebook)7 AuthorizationService (org.apache.zeppelin.notebook.AuthorizationService)5 Before (org.junit.Before)5 Credentials (org.apache.zeppelin.user.Credentials)4 File (java.io.File)3 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)3 InterpreterFactory (org.apache.zeppelin.interpreter.InterpreterFactory)3 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)3 InterpreterSettingManager (org.apache.zeppelin.interpreter.InterpreterSettingManager)3 NotebookRepo (org.apache.zeppelin.notebook.repo.NotebookRepo)3 InMemoryNotebookRepo (org.apache.zeppelin.notebook.repo.InMemoryNotebookRepo)2 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Interpreter (org.apache.zeppelin.interpreter.Interpreter)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 ManagedInterpreterGroup (org.apache.zeppelin.interpreter.ManagedInterpreterGroup)1 Note (org.apache.zeppelin.notebook.Note)1 NoteInfo (org.apache.zeppelin.notebook.NoteInfo)1