Search in sources :

Example 51 with Notebook

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

the class NotebookServerTest method unbindAngularObjectFromRemoteForParagraphs.

@Test
public void unbindAngularObjectFromRemoteForParagraphs() throws Exception {
    // Given
    final String varName = "name";
    final String value = "val";
    final Message messageReceived = new Message(OP.ANGULAR_OBJECT_CLIENT_UNBIND).put("noteId", "noteId").put("name", varName).put("paragraphId", "paragraphId");
    try {
        final Notebook notebook = mock(Notebook.class);
        notebookServer.setNotebook(() -> notebook);
        notebookServer.setNotebookService(() -> notebookService);
        final Note note = mock(Note.class, RETURNS_DEEP_STUBS);
        when(notebook.processNote(eq("noteId"), Mockito.any())).then(e -> e.getArgumentAt(1, NoteProcessor.class).process(note));
        final Paragraph paragraph = mock(Paragraph.class, RETURNS_DEEP_STUBS);
        when(note.getParagraph("paragraphId")).thenReturn(paragraph);
        final RemoteAngularObjectRegistry mdRegistry = mock(RemoteAngularObjectRegistry.class);
        final InterpreterGroup mdGroup = new InterpreterGroup("mdGroup");
        mdGroup.setAngularObjectRegistry(mdRegistry);
        when(paragraph.getBindedInterpreter().getInterpreterGroup()).thenReturn(mdGroup);
        final AngularObject<String> ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId");
        when(mdRegistry.removeAndNotifyRemoteProcess(varName, "noteId", "paragraphId")).thenReturn(ao1);
        NotebookSocket conn = mock(NotebookSocket.class);
        NotebookSocket otherConn = mock(NotebookSocket.class);
        final String mdMsg1 = notebookServer.serializeMessage(new Message(OP.ANGULAR_OBJECT_REMOVE).put("angularObject", ao1).put("interpreterGroupId", "mdGroup").put("noteId", "noteId").put("paragraphId", "paragraphId"));
        notebookServer.getConnectionManager().noteSocketMap.put("noteId", asList(conn, otherConn));
        // When
        notebookServer.angularObjectClientUnbind(conn, messageReceived);
        // Then
        verify(mdRegistry, never()).removeAndNotifyRemoteProcess(varName, "noteId", null);
        verify(otherConn).send(mdMsg1);
    } finally {
        // reset these so that it won't affect other tests
        notebookServer.setNotebook(() -> NotebookServerTest.notebook);
        notebookServer.setNotebookService(() -> NotebookServerTest.notebookService);
    }
}
Also used : Message(org.apache.zeppelin.common.Message) Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Note(org.apache.zeppelin.notebook.Note) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) Mockito.anyString(org.mockito.Mockito.anyString) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 52 with Notebook

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

the class ZeppelinClientWithAuthIntegrationTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HELIUM_REGISTRY.getVarName(), "helium");
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_ALLOWED_ORIGINS.getVarName(), "*");
    AbstractTestRestApi.startUpWithAuthenticationEnable(ZeppelinClientWithAuthIntegrationTest.class.getSimpleName());
    notebook = TestUtils.getInstance(Notebook.class);
    clientConfig = new ClientConfig("http://localhost:8080");
    zeppelinClient = new ZeppelinClient(clientConfig);
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) ZeppelinClient(org.apache.zeppelin.client.ZeppelinClient) ClientConfig(org.apache.zeppelin.client.ClientConfig) BeforeClass(org.junit.BeforeClass)

Example 53 with Notebook

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

the class NotebookRepoSyncTest method testOneWaySyncOnReloadedList.

@Test
public void testOneWaySyncOnReloadedList() throws IOException, SchedulerException {
    System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath());
    System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_ONE_WAY_SYNC.getVarName(), "true");
    conf = ZeppelinConfiguration.create();
    notebookRepoSync = new NotebookRepoSync(conf);
    notebook = new Notebook(conf, mock(AuthorizationService.class), notebookRepoSync, new NoteManager(notebookRepoSync, conf), factory, interpreterSettingManager, credentials, null);
    // check that both storage repos are empty
    assertTrue(notebookRepoSync.getRepoCount() > 1);
    assertEquals(0, notebookRepoSync.list(0, null).size());
    assertEquals(0, notebookRepoSync.list(1, null).size());
    File srcDir = new File("src/test/resources/notebook");
    File destDir = secNotebookDir;
    /* copy manually new notebook into secondary storage repo and check repos */
    try {
        FileUtils.copyDirectory(srcDir, destDir);
    } catch (IOException e) {
        LOG.error(e.toString(), e);
    }
    assertEquals(0, notebookRepoSync.list(0, null).size());
    assertEquals(2, notebookRepoSync.list(1, null).size());
    // after reloading the notebook should be wiped from secondary storage
    notebook.reloadAllNotes(null);
    assertEquals(0, notebookRepoSync.list(0, null).size());
    assertEquals(0, notebookRepoSync.list(1, null).size());
    destDir = mainNotebookDir;
    // copy manually new notebook into primary storage repo and check repos
    try {
        FileUtils.copyDirectory(srcDir, destDir);
    } catch (IOException e) {
        LOG.error(e.toString(), e);
    }
    assertEquals(2, notebookRepoSync.list(0, null).size());
    assertEquals(0, notebookRepoSync.list(1, null).size());
    // after reloading notebooks repos should be synchronized
    notebook.reloadAllNotes(null);
    assertEquals(2, notebookRepoSync.list(0, null).size());
    assertEquals(2, notebookRepoSync.list(1, null).size());
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) NoteManager(org.apache.zeppelin.notebook.NoteManager) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 54 with Notebook

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

the class ZeppelinRestApiTest method testListNotes.

@Test
public void testListNotes() throws IOException {
    LOG.info("testListNotes");
    CloseableHttpResponse get = httpGet("/notebook/");
    assertThat("List notes method", get, isAllowed());
    Map<String, Object> resp = gson.fromJson(EntityUtils.toString(get.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {
    }.getType());
    List<Map<String, String>> body = (List<Map<String, String>>) resp.get("body");
    // TODO(khalid): anonymous or specific user notes?
    HashSet<String> anonymous = new HashSet<>(Arrays.asList("anonymous"));
    AuthorizationService authorizationService = TestUtils.getInstance(AuthorizationService.class);
    assertEquals("List notes are equal", TestUtils.getInstance(Notebook.class).getNotesInfo(noteId -> authorizationService.isReader(noteId, anonymous)).size(), body.size());
    get.close();
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) AuthorizationService(org.apache.zeppelin.notebook.AuthorizationService) TypeToken(com.google.gson.reflect.TypeToken) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 55 with Notebook

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

the class ZeppelinRestApiTest method testRegressionZEPPELIN_527.

@Test
public void testRegressionZEPPELIN_527() throws Exception {
    String noteId = null;
    try {
        noteId = TestUtils.getInstance(Notebook.class).createNote("note1_testRegressionZEPPELIN_527", anonymous);
        // use write lock because name is overwritten
        TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
            note.setName("note for run test");
            Paragraph paragraph = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
            paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)");
            return null;
        });
        TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
            try {
                note.runAll(AuthenticationInfo.ANONYMOUS, true, false, new HashMap<>());
                TestUtils.getInstance(Notebook.class).saveNote(note, anonymous);
            } catch (Exception e) {
                fail();
            }
            return null;
        });
        CloseableHttpResponse getNoteJobs = httpGet("/notebook/job/" + noteId);
        assertThat("test note jobs run:", getNoteJobs, isAllowed());
        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(getNoteJobs.getEntity(), StandardCharsets.UTF_8), new TypeToken<Map<String, Object>>() {
        }.getType());
        NoteJobStatus noteJobStatus = NoteJobStatus.fromJson(gson.toJson(resp.get("body")));
        assertNotNull(noteJobStatus.getParagraphJobStatusList().get(0).getStarted());
        assertNotNull(noteJobStatus.getParagraphJobStatusList().get(0).getFinished());
        getNoteJobs.close();
    } finally {
        // cleanup
        if (null != noteId) {
            TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous);
        }
    }
}
Also used : NoteJobStatus(org.apache.zeppelin.rest.message.NoteJobStatus) Notebook(org.apache.zeppelin.notebook.Notebook) TypeToken(com.google.gson.reflect.TypeToken) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Aggregations

Notebook (org.apache.zeppelin.notebook.Notebook)79 Test (org.junit.Test)53 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)48 Paragraph (org.apache.zeppelin.notebook.Paragraph)43 TypeToken (com.google.gson.reflect.TypeToken)33 Map (java.util.Map)25 HashMap (java.util.HashMap)24 Note (org.apache.zeppelin.notebook.Note)20 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)12 AuthorizationService (org.apache.zeppelin.notebook.AuthorizationService)12 Before (org.junit.Before)12 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)11 List (java.util.List)10 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)10 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)9 BeforeClass (org.junit.BeforeClass)9 InterpreterSettingManager (org.apache.zeppelin.interpreter.InterpreterSettingManager)8 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)7 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)7