Search in sources :

Example 1 with NotebookRepo

use of org.apache.zeppelin.notebook.repo.NotebookRepo in project zeppelin by apache.

the class NotebookTest method testRevisionSupported.

@Test
public void testRevisionSupported() throws IOException {
    NotebookRepo notebookRepo;
    Notebook notebook;
    notebookRepo = new DummyNotebookRepo();
    notebook = new Notebook(conf, mock(AuthorizationService.class), notebookRepo, new NoteManager(notebookRepo, conf), interpreterFactory, interpreterSettingManager, credentials, null);
    assertFalse("Revision is not supported in DummyNotebookRepo", notebook.isRevisionSupported());
    notebookRepo = new DummyNotebookRepoWithVersionControl();
    notebook = new Notebook(conf, mock(AuthorizationService.class), notebookRepo, new NoteManager(notebookRepo, conf), interpreterFactory, interpreterSettingManager, credentials, null);
    assertTrue("Revision is supported in DummyNotebookRepoWithVersionControl", notebook.isRevisionSupported());
}
Also used : NotebookRepo(org.apache.zeppelin.notebook.repo.NotebookRepo) VFSNotebookRepo(org.apache.zeppelin.notebook.repo.VFSNotebookRepo) AbstractInterpreterTest(org.apache.zeppelin.interpreter.AbstractInterpreterTest) Test(org.junit.Test)

Example 2 with NotebookRepo

use of org.apache.zeppelin.notebook.repo.NotebookRepo 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 3 with NotebookRepo

use of org.apache.zeppelin.notebook.repo.NotebookRepo in project zeppelin by apache.

the class PluginManager method loadNotebookRepo.

public NotebookRepo loadNotebookRepo(String notebookRepoClassName) throws IOException {
    LOGGER.info("Loading NotebookRepo Plugin: {}", notebookRepoClassName);
    if (builtinNotebookRepoClassNames.contains(notebookRepoClassName) || Boolean.parseBoolean(System.getProperty("zeppelin.isTest", "false"))) {
        try {
            return (NotebookRepo) (Class.forName(notebookRepoClassName).newInstance());
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new IOException("Fail to instantiate notebookrepo from classpath directly:" + notebookRepoClassName, e);
        }
    }
    String simpleClassName = notebookRepoClassName.substring(notebookRepoClassName.lastIndexOf(".") + 1);
    URLClassLoader pluginClassLoader = getPluginClassLoader(pluginsDir, "NotebookRepo", simpleClassName);
    if (pluginClassLoader == null) {
        return null;
    }
    NotebookRepo notebookRepo = null;
    try {
        notebookRepo = (NotebookRepo) (Class.forName(notebookRepoClassName, true, pluginClassLoader)).newInstance();
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new IOException("Fail to instantiate notebookrepo " + notebookRepoClassName + " from plugin classpath:" + pluginsDir, e);
    }
    return notebookRepo;
}
Also used : VFSNotebookRepo(org.apache.zeppelin.notebook.repo.VFSNotebookRepo) NotebookRepo(org.apache.zeppelin.notebook.repo.NotebookRepo) GitNotebookRepo(org.apache.zeppelin.notebook.repo.GitNotebookRepo) URLClassLoader(java.net.URLClassLoader) IOException(java.io.IOException)

Example 4 with NotebookRepo

use of org.apache.zeppelin.notebook.repo.NotebookRepo 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)

Example 5 with NotebookRepo

use of org.apache.zeppelin.notebook.repo.NotebookRepo in project zeppelin by apache.

the class PluginManagerTest method testLoadGitNotebookRepo.

@Test
public void testLoadGitNotebookRepo() throws IOException {
    NotebookRepo notebookRepo = PluginManager.get().loadNotebookRepo("org.apache.zeppelin.notebook.repo.GitNotebookRepo");
    assertTrue(notebookRepo instanceof GitNotebookRepo);
}
Also used : NotebookRepo(org.apache.zeppelin.notebook.repo.NotebookRepo) GitNotebookRepo(org.apache.zeppelin.notebook.repo.GitNotebookRepo) GitNotebookRepo(org.apache.zeppelin.notebook.repo.GitNotebookRepo) Test(org.junit.Test)

Aggregations

NotebookRepo (org.apache.zeppelin.notebook.repo.NotebookRepo)6 AuthorizationService (org.apache.zeppelin.notebook.AuthorizationService)3 NoteManager (org.apache.zeppelin.notebook.NoteManager)3 Notebook (org.apache.zeppelin.notebook.Notebook)3 VFSNotebookRepo (org.apache.zeppelin.notebook.repo.VFSNotebookRepo)3 Credentials (org.apache.zeppelin.user.Credentials)3 Before (org.junit.Before)3 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)2 GitNotebookRepo (org.apache.zeppelin.notebook.repo.GitNotebookRepo)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)1 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)1 Interpreter (org.apache.zeppelin.interpreter.Interpreter)1 InterpreterFactory (org.apache.zeppelin.interpreter.InterpreterFactory)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 InterpreterSettingManager (org.apache.zeppelin.interpreter.InterpreterSettingManager)1 ManagedInterpreterGroup (org.apache.zeppelin.interpreter.ManagedInterpreterGroup)1