diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ByteBufferInputStream.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ByteBufferInputStream.java index a8becb4aea1..efccb6ac053 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ByteBufferInputStream.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ByteBufferInputStream.java @@ -21,6 +21,7 @@ import java.io.InputStream; import java.nio.ByteBuffer; + /** * InputStream from bytebuffer */ diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java index c4cd441497a..de41692607a 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/user/AuthenticationInfo.java @@ -28,6 +28,10 @@ public class AuthenticationInfo { public AuthenticationInfo() {} + public AuthenticationInfo(String user) { + this.user = user; + } + /*** * * @param user diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java index 2bbe7960c82..87e7ccef8f5 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java @@ -46,6 +46,7 @@ import org.apache.zeppelin.search.SearchService; import org.apache.zeppelin.server.JsonResponse; import org.apache.zeppelin.socket.NotebookServer; +import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.utils.SecurityUtils; import org.quartz.CronExpression; import org.slf4j.Logger; @@ -158,7 +159,8 @@ public Response putNotePermissions(@PathParam("noteId") String noteId, String re notebookAuthorization.getOwners(noteId), notebookAuthorization.getReaders(noteId), notebookAuthorization.getWriters(noteId)); - note.persist(); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + note.persist(subject); notebookServer.broadcastNote(note); return new JsonResponse<>(Status.OK).build(); } @@ -224,7 +226,8 @@ public Response bind(@PathParam("noteId") String noteId) { @Path("/") @ZeppelinApi public Response getNotebookList() throws IOException { - List> notesInfo = notebookServer.generateNotebooksInfo(false); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + List> notesInfo = notebookServer.generateNotebooksInfo(false, subject); return new JsonResponse<>(Status.OK, "", notesInfo ).build(); } @@ -266,7 +269,8 @@ public Response exportNoteBook(@PathParam("id") String noteId) throws IOExceptio @Path("import") @ZeppelinApi public Response importNotebook(String req) throws IOException { - Note newNote = notebook.importNote(req, null); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + Note newNote = notebook.importNote(req, null, subject); return new JsonResponse<>(Status.CREATED, "", newNote.getId()).build(); } @@ -283,7 +287,8 @@ public Response createNote(String message) throws IOException { LOG.info("Create new notebook by JSON {}" , message); NewNotebookRequest request = gson.fromJson(message, NewNotebookRequest.class); - Note note = notebook.createNote(); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + Note note = notebook.createNote(subject); List initialParagraphs = request.getParagraphs(); if (initialParagraphs != null) { for (NewParagraphRequest paragraphRequest : initialParagraphs) { @@ -297,10 +302,11 @@ public Response createNote(String message) throws IOException { if (noteName.isEmpty()) { noteName = "Note " + note.getId(); } + note.setName(noteName); - note.persist(); + note.persist(subject); notebookServer.broadcastNote(note); - notebookServer.broadcastNoteList(); + notebookServer.broadcastNoteList(subject); return new JsonResponse<>(Status.CREATED, "", note.getId() ).build(); } @@ -315,13 +321,15 @@ public Response createNote(String message) throws IOException { @ZeppelinApi public Response deleteNote(@PathParam("notebookId") String notebookId) throws IOException { LOG.info("Delete notebook {} ", notebookId); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); if (!(notebookId.isEmpty())) { Note note = notebook.getNote(notebookId); if (note != null) { - notebook.removeNote(notebookId); + notebook.removeNote(notebookId, subject); } } - notebookServer.broadcastNoteList(); + + notebookServer.broadcastNoteList(subject); return new JsonResponse<>(Status.OK, "").build(); } @@ -340,9 +348,10 @@ public Response cloneNote(@PathParam("notebookId") String notebookId, String mes NewNotebookRequest request = gson.fromJson(message, NewNotebookRequest.class); String newNoteName = request.getName(); - Note newNote = notebook.cloneNote(notebookId, newNoteName); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + Note newNote = notebook.cloneNote(notebookId, newNoteName, subject); notebookServer.broadcastNote(newNote); - notebookServer.broadcastNoteList(); + notebookServer.broadcastNoteList(subject); return new JsonResponse<>(Status.CREATED, "", newNote.getId()).build(); } @@ -376,7 +385,8 @@ public Response insertParagraph(@PathParam("notebookId") String notebookId, Stri p.setTitle(request.getTitle()); p.setText(request.getText()); - note.persist(); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + note.persist(subject); notebookServer.broadcastNote(note); return new JsonResponse(Status.CREATED, "", p.getId()).build(); } @@ -434,7 +444,8 @@ public Response moveParagraph(@PathParam("notebookId") String notebookId, try { note.moveParagraph(paragraphId, Integer.parseInt(newIndex), true); - note.persist(); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + note.persist(subject); notebookServer.broadcastNote(note); return new JsonResponse(Status.OK, "").build(); } catch (IndexOutOfBoundsException e) { @@ -466,8 +477,9 @@ public Response deleteParagraph(@PathParam("notebookId") String notebookId, return new JsonResponse(Status.NOT_FOUND, "paragraph not found.").build(); } + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); note.removeParagraph(paragraphId); - note.persist(); + note.persist(subject); notebookServer.broadcastNote(note); return new JsonResponse(Status.OK, "").build(); @@ -574,7 +586,8 @@ public Response runParagraph(@PathParam("notebookId") String notebookId, Map paramsForUpdating = request.getParams(); if (paramsForUpdating != null) { paragraph.settings.getParams().putAll(paramsForUpdating); - note.persist(); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + note.persist(subject); } } @@ -700,7 +713,8 @@ public Response getCronJob(@PathParam("notebookId") String notebookId) throws public Response getJobListforNotebook() throws IOException, IllegalArgumentException { LOG.info("Get notebook jobs for job manager"); - List> notebookJobs = notebook.getJobListforNotebook(false, 0); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + List> notebookJobs = notebook.getJobListforNotebook(false, 0, subject); Map response = new HashMap<>(); response.put("lastResponseUnixTime", System.currentTimeMillis()); @@ -724,7 +738,8 @@ public Response getUpdatedJobListforNotebook( LOG.info("Get updated notebook jobs lastUpdateTime {}", lastUpdateUnixTime); List> notebookJobs; - notebookJobs = notebook.getJobListforNotebook(false, lastUpdateUnixTime); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); + notebookJobs = notebook.getJobListforNotebook(false, lastUpdateUnixTime, subject); Map response = new HashMap<>(); response.put("lastResponseUnixTime", System.currentTimeMillis()); diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index dc190d1b8f1..339f4617475 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -147,14 +147,15 @@ public void onMessage(NotebookSocket conn, String msg) { userAndRoles.addAll(roles); } } + AuthenticationInfo subject = new AuthenticationInfo(messagereceived.principal); /** Lets be elegant here */ switch (messagereceived.op) { case LIST_NOTES: - unicastNoteList(conn); + unicastNoteList(conn, subject); break; case RELOAD_NOTES_FROM_REPO: - broadcastReloadedNoteList(); + broadcastReloadedNoteList(subject); break; case GET_HOME_NOTE: sendHomeNote(conn, userAndRoles, notebook); @@ -219,7 +220,7 @@ public void onMessage(NotebookSocket conn, String msg) { checkpointNotebook(conn, notebook, messagereceived); break; case LIST_NOTEBOOK_JOBS: - unicastNotebookJobInfo(conn); + unicastNotebookJobInfo(conn, messagereceived); break; case LIST_UPDATE_NOTEBOOK_JOBS: unicastUpdateNotebookJobInfo(conn, messagereceived); @@ -371,9 +372,10 @@ private void unicast(Message m, NotebookSocket conn) { } } - public void unicastNotebookJobInfo(NotebookSocket conn) throws IOException { + public void unicastNotebookJobInfo(NotebookSocket conn, Message fromMessage) throws IOException { - List> notebookJobs = notebook().getJobListforNotebook(false, 0); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); + List> notebookJobs = notebook().getJobListforNotebook(false, 0, subject); Map response = new HashMap<>(); response.put("lastResponseUnixTime", System.currentTimeMillis()); @@ -389,7 +391,8 @@ public void unicastUpdateNotebookJobInfo(NotebookSocket conn, Message fromMessag long lastUpdateUnixTime = new Double(lastUpdateUnixTimeRaw).longValue(); List> notebookJobs; - notebookJobs = notebook().getJobListforNotebook(false, lastUpdateUnixTime); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); + notebookJobs = notebook().getJobListforNotebook(false, lastUpdateUnixTime, subject); Map response = new HashMap<>(); response.put("lastResponseUnixTime", System.currentTimeMillis()); @@ -399,7 +402,9 @@ public void unicastUpdateNotebookJobInfo(NotebookSocket conn, Message fromMessag .put("notebookRunningJobs", response))); } - public List> generateNotebooksInfo(boolean needsReload) { + public List> generateNotebooksInfo(boolean needsReload, + AuthenticationInfo subject) { + Notebook notebook = notebook(); ZeppelinConfiguration conf = notebook.getConf(); @@ -409,7 +414,7 @@ public List> generateNotebooksInfo(boolean needsReload) { if (needsReload) { try { - notebook.reloadAllNotes(); + notebook.reloadAllNotes(subject); } catch (IOException e) { LOG.error("Fail to reload notes from repository", e); } @@ -436,18 +441,18 @@ public void broadcastNote(Note note) { broadcast(note.id(), new Message(OP.NOTE).put("note", note)); } - public void broadcastNoteList() { - List> notesInfo = generateNotebooksInfo(false); + public void broadcastNoteList(AuthenticationInfo subject) { + List> notesInfo = generateNotebooksInfo(false, subject); broadcastAll(new Message(OP.NOTES_INFO).put("notes", notesInfo)); } - public void unicastNoteList(NotebookSocket conn) { - List> notesInfo = generateNotebooksInfo(false); + public void unicastNoteList(NotebookSocket conn, AuthenticationInfo subject) { + List> notesInfo = generateNotebooksInfo(false, subject); unicast(new Message(OP.NOTES_INFO).put("notes", notesInfo), conn); } - public void broadcastReloadedNoteList() { - List> notesInfo = generateNotebooksInfo(true); + public void broadcastReloadedNoteList(AuthenticationInfo subject) { + List> notesInfo = generateNotebooksInfo(true, subject); broadcastAll(new Message(OP.NOTES_INFO).put("notes", notesInfo)); } @@ -543,9 +548,10 @@ private void updateNote(NotebookSocket conn, HashSet userAndRoles, notebook.refreshCron(note.id()); } - note.persist(); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); + note.persist(subject); broadcastNote(note); - broadcastNoteList(); + broadcastNoteList(subject); } } @@ -566,7 +572,8 @@ private boolean isCronUpdated(Map configA, private void createNote(NotebookSocket conn, HashSet userAndRoles, Notebook notebook, Message message) throws IOException { - Note note = notebook.createNote(); + AuthenticationInfo subject = new AuthenticationInfo(message.principal); + Note note = notebook.createNote(subject); note.addParagraph(); // it's an empty note. so add one paragraph if (message != null) { String noteName = (String) message.get("name"); @@ -576,10 +583,10 @@ private void createNote(NotebookSocket conn, HashSet userAndRoles, note.setName(noteName); } - note.persist(); + note.persist(subject); addConnectionToNote(note.id(), (NotebookSocket) conn); conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", note))); - broadcastNoteList(); + broadcastNoteList(subject); } private void removeNote(NotebookSocket conn, HashSet userAndRoles, @@ -597,9 +604,10 @@ private void removeNote(NotebookSocket conn, HashSet userAndRoles, return; } - notebook.removeNote(noteId); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); + notebook.removeNote(noteId, subject); removeNote(noteId); - broadcastNoteList(); + broadcastNoteList(subject); } private void updateParagraph(NotebookSocket conn, HashSet userAndRoles, @@ -616,6 +624,7 @@ private void updateParagraph(NotebookSocket conn, HashSet userAndRoles, String noteId = getOpenNoteId(conn); final Note note = notebook.getNote(noteId); NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); if (!notebookAuthorization.isWriter(noteId, userAndRoles)) { permissionError(conn, "write", userAndRoles, notebookAuthorization.getWriters(noteId)); return; @@ -626,7 +635,7 @@ private void updateParagraph(NotebookSocket conn, HashSet userAndRoles, p.setConfig(config); p.setTitle((String) fromMessage.get("title")); p.setText((String) fromMessage.get("paragraph")); - note.persist(); + note.persist(subject); broadcast(note.id(), new Message(OP.PARAGRAPH).put("paragraph", p)); } @@ -635,10 +644,11 @@ private void cloneNote(NotebookSocket conn, HashSet userAndRoles, throws IOException, CloneNotSupportedException { String noteId = getOpenNoteId(conn); String name = (String) fromMessage.get("name"); - Note newNote = notebook.cloneNote(noteId, name); + Note newNote = notebook.cloneNote(noteId, name, new AuthenticationInfo(fromMessage.principal)); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); addConnectionToNote(newNote.id(), (NotebookSocket) conn); conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", newNote))); - broadcastNoteList(); + broadcastNoteList(subject); } protected Note importNote(NotebookSocket conn, HashSet userAndRoles, @@ -648,10 +658,11 @@ protected Note importNote(NotebookSocket conn, HashSet userAndRoles, if (fromMessage != null) { String noteName = (String) ((Map) fromMessage.get("notebook")).get("name"); String noteJson = gson.toJson(fromMessage.get("notebook")); - note = notebook.importNote(noteJson, noteName); - note.persist(); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); + note = notebook.importNote(noteJson, noteName, subject); + note.persist(subject); broadcastNote(note); - broadcastNoteList(); + broadcastNoteList(subject); } return note; } @@ -665,6 +676,7 @@ private void removeParagraph(NotebookSocket conn, HashSet userAndRoles, String noteId = getOpenNoteId(conn); final Note note = notebook.getNote(noteId); NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); if (!notebookAuthorization.isWriter(noteId, userAndRoles)) { permissionError(conn, "write", userAndRoles, notebookAuthorization.getWriters(noteId)); return; @@ -673,7 +685,7 @@ private void removeParagraph(NotebookSocket conn, HashSet userAndRoles, /** We dont want to remove the last paragraph */ if (!note.isLastParagraph(paragraphId)) { note.removeParagraph(paragraphId); - note.persist(); + note.persist(subject); broadcastNote(note); } } @@ -967,13 +979,14 @@ private void moveParagraph(NotebookSocket conn, HashSet userAndRoles, No String noteId = getOpenNoteId(conn); final Note note = notebook.getNote(noteId); NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); if (!notebookAuthorization.isWriter(noteId, userAndRoles)) { permissionError(conn, "write", userAndRoles, notebookAuthorization.getWriters(noteId)); return; } note.moveParagraph(paragraphId, newIndex); - note.persist(); + note.persist(subject); broadcastNote(note); } @@ -984,13 +997,14 @@ private void insertParagraph(NotebookSocket conn, HashSet userAndRoles, String noteId = getOpenNoteId(conn); final Note note = notebook.getNote(noteId); NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); + AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal()); if (!notebookAuthorization.isWriter(noteId, userAndRoles)) { permissionError(conn, "write", userAndRoles, notebookAuthorization.getWriters(noteId)); return; } note.insertParagraph(index); - note.persist(); + note.persist(subject); broadcastNote(note); } @@ -1054,7 +1068,8 @@ private void runParagraph(NotebookSocket conn, HashSet userAndRoles, Not note.addParagraph(); } - note.persist(); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); + note.persist(subject); try { note.run(paragraphId); } catch (Exception ex) { @@ -1093,7 +1108,8 @@ private void checkpointNotebook(NotebookSocket conn, Notebook notebook, Message fromMessage) throws IOException { String noteId = (String) fromMessage.get("noteId"); String commitMessage = (String) fromMessage.get("commitMessage"); - notebook.checkpointNote(noteId, commitMessage); + AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); + notebook.checkpointNote(noteId, commitMessage, subject); } /** @@ -1164,7 +1180,8 @@ public void afterStatusChange(Job job, Status before, Status after) { if (job.isTerminated()) { LOG.info("Job {} is finished", job.getId()); try { - note.persist(); + //TODO(khalid): may change interface for JobListener and pass subject from interpreter + note.persist(null); } catch (IOException e) { LOG.error(e.toString(), e); } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java index 3862717c36d..f03d87b32f9 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/InterpreterRestApiTest.java @@ -123,7 +123,7 @@ public void testSettingsCRUD() throws IOException { @Test public void testInterpreterAutoBinding() throws IOException { // create note - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); // check interpreter is binded GetMethod get = httpGet("/notebook/interpreter/bind/" + note.id()); @@ -136,13 +136,13 @@ public void testInterpreterAutoBinding() throws IOException { get.releaseConnection(); //cleanup - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testInterpreterRestart() throws IOException, InterruptedException { // create new note - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); note.addParagraph(); Paragraph p = note.getLastParagraph(); Map config = p.getConfig(); @@ -179,7 +179,7 @@ public void testInterpreterRestart() throws IOException, InterruptedException { } assertEquals("

markdown restarted

\n", p.getResult().message()); //cleanup - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java index dc88b5d44cf..94e7fa8b071 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java @@ -61,7 +61,7 @@ public static void destroy() throws Exception { @Test public void testPermissions() throws IOException { - Note note1 = ZeppelinServer.notebook.createNote(); + Note note1 = ZeppelinServer.notebook.createNote(null); // Set only readers String jsonRequest = "{\"readers\":[\"admin-team\"],\"owners\":[]," + "\"writers\":[]}"; @@ -84,7 +84,7 @@ public void testPermissions() throws IOException { get.releaseConnection(); - Note note2 = ZeppelinServer.notebook.createNote(); + Note note2 = ZeppelinServer.notebook.createNote(null); // Set only writers jsonRequest = "{\"readers\":[],\"owners\":[]," + "\"writers\":[\"admin-team\"]}"; @@ -118,8 +118,8 @@ public void testPermissions() throws IOException { assertEquals(authInfo.get("owners"), Lists.newArrayList()); get.releaseConnection(); //cleanup - ZeppelinServer.notebook.removeNote(note1.getId()); - ZeppelinServer.notebook.removeNote(note2.getId()); + ZeppelinServer.notebook.removeNote(note1.getId(), null); + ZeppelinServer.notebook.removeNote(note2.getId(), null); } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java index 36c95af9802..4390d74b495 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java @@ -77,7 +77,7 @@ public void getApiRoot() throws IOException { public void testGetNotebookInfo() throws IOException { LOG.info("testGetNotebookInfo"); // Create note to get info - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); assertNotNull("can't create new note", note); note.setName("note"); Paragraph paragraph = note.addParagraph(); @@ -86,7 +86,7 @@ public void testGetNotebookInfo() throws IOException { paragraph.setConfig(config); String paragraphText = "%md This is my new paragraph in my new note"; paragraph.setText(paragraphText); - note.persist(); + note.persist(null); String sourceNoteID = note.getId(); GetMethod get = httpGet("/notebook/" + sourceNoteID); @@ -153,7 +153,7 @@ public void testNotebookCreateWithParagraphs() throws IOException { assertTrue("paragraph text check failed", p.getText().startsWith("text")); } // cleanup - ZeppelinServer.notebook.removeNote(newNotebookId); + ZeppelinServer.notebook.removeNote(newNotebookId, null); post.releaseConnection(); } @@ -180,7 +180,7 @@ private void testNotebookCreate(String noteName) throws IOException { } assertEquals("compare note name", expectedNoteName, newNoteName); // cleanup - ZeppelinServer.notebook.removeNote(newNotebookId); + ZeppelinServer.notebook.removeNote(newNotebookId, null); post.releaseConnection(); } @@ -189,7 +189,7 @@ private void testNotebookCreate(String noteName) throws IOException { public void testDeleteNote() throws IOException { LOG.info("testDeleteNote"); //Create note and get ID - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); String noteId = note.getId(); testDeleteNotebook(noteId); } @@ -205,7 +205,7 @@ public void testDeleteNoteBadId() throws IOException { @Test public void testExportNotebook() throws IOException { LOG.info("testExportNotebook"); - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); assertNotNull("can't create new note", note); note.setName("source note for export"); Paragraph paragraph = note.addParagraph(); @@ -213,7 +213,7 @@ public void testExportNotebook() throws IOException { config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - note.persist(); + note.persist(null); String sourceNoteID = note.getId(); // Call export Notebook REST API GetMethod get = httpGet("/notebook/export/" + sourceNoteID); @@ -227,7 +227,7 @@ public void testExportNotebook() throws IOException { String exportJSON = (String) resp.get("body"); assertNotNull("Can not find new notejson", exportJSON); LOG.info("export JSON:=" + exportJSON); - ZeppelinServer.notebook.removeNote(sourceNoteID); + ZeppelinServer.notebook.removeNote(sourceNoteID, null); get.releaseConnection(); } @@ -238,7 +238,7 @@ public void testImportNotebook() throws IOException { String noteName = "source note for import"; LOG.info("testImortNotebook"); // create test notebook - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); assertNotNull("can't create new note", note); note.setName(noteName); Paragraph paragraph = note.addParagraph(); @@ -246,7 +246,7 @@ public void testImportNotebook() throws IOException { config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - note.persist(); + note.persist(null); String sourceNoteID = note.getId(); // get note content as JSON String oldJson = getNoteContent(sourceNoteID); @@ -264,8 +264,8 @@ public void testImportNotebook() throws IOException { assertEquals("Compare paragraphs count", note.getParagraphs().size(), newNote.getParagraphs() .size()); // cleanup - ZeppelinServer.notebook.removeNote(note.getId()); - ZeppelinServer.notebook.removeNote(newNote.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(newNote.getId(), null); importPost.releaseConnection(); } @@ -300,7 +300,7 @@ private void testDeleteNotebook(String notebookId) throws IOException { public void testCloneNotebook() throws IOException, CloneNotSupportedException, IllegalArgumentException { LOG.info("testCloneNotebook"); // Create note to clone - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); assertNotNull("can't create new note", note); note.setName("source note for clone"); Paragraph paragraph = note.addParagraph(); @@ -308,7 +308,7 @@ public void testCloneNotebook() throws IOException, CloneNotSupportedException, config.put("enabled", true); paragraph.setConfig(config); paragraph.setText("%md This is my new paragraph in my new note"); - note.persist(); + note.persist(null); String sourceNoteID = note.getId(); String noteName = "clone Note Name"; @@ -328,8 +328,8 @@ public void testCloneNotebook() throws IOException, CloneNotSupportedException, assertEquals("Compare note names", noteName, newNote.getName()); assertEquals("Compare paragraphs count", note.getParagraphs().size(), newNote.getParagraphs().size()); //cleanup - ZeppelinServer.notebook.removeNote(note.getId()); - ZeppelinServer.notebook.removeNote(newNote.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); + ZeppelinServer.notebook.removeNote(newNote.getId(), null); post.releaseConnection(); } @@ -349,7 +349,7 @@ public void testListNotebooks() throws IOException { public void testNoteJobs() throws IOException, InterruptedException { LOG.info("testNoteJobs"); // Create note to run test. - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); assertNotNull("can't create new note", note); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); @@ -359,7 +359,7 @@ public void testNoteJobs() throws IOException, InterruptedException { paragraph.setConfig(config); paragraph.setText("%md This is test paragraph."); - note.persist(); + note.persist(null); String noteID = note.getId(); note.runAll(); @@ -397,14 +397,14 @@ public void testNoteJobs() throws IOException, InterruptedException { Thread.sleep(1000); //cleanup - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testGetNotebookJob() throws IOException, InterruptedException { LOG.info("testGetNotebookJob"); // Create note to run test. - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); assertNotNull("can't create new note", note); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); @@ -414,7 +414,7 @@ public void testGetNotebookJob() throws IOException, InterruptedException { paragraph.setConfig(config); paragraph.setText("%sh sleep 1"); - note.persist(); + note.persist(null); String noteID = note.getId(); note.runAll(); @@ -450,14 +450,14 @@ public void testGetNotebookJob() throws IOException, InterruptedException { } } - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testRunParagraphWithParams() throws IOException, InterruptedException { LOG.info("testRunParagraphWithParams"); // Create note to run test. - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); assertNotNull("can't create new note", note); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); @@ -467,7 +467,7 @@ public void testRunParagraphWithParams() throws IOException, InterruptedExceptio paragraph.setConfig(config); paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)"); - note.persist(); + note.persist(null); String noteID = note.getId(); note.runAll(); @@ -495,13 +495,13 @@ public void testRunParagraphWithParams() throws IOException, InterruptedExceptio assertEquals("world", params.get("param2")); //cleanup - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testCronJobs() throws InterruptedException, IOException{ // create a note and a paragraph - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); @@ -545,18 +545,18 @@ public void testCronJobs() throws InterruptedException, IOException{ DeleteMethod deleteCron = httpDelete("/notebook/cron/" + note.getId()); assertThat("", deleteCron, isAllowed()); deleteCron.releaseConnection(); - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testRegressionZEPPELIN_527() throws IOException { - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); note.setName("note for run test"); Paragraph paragraph = note.addParagraph(); paragraph.setText("%spark\nval param = z.input(\"param\").toString\nprintln(param)"); - note.persist(); + note.persist(null); GetMethod getNoteJobs = httpGet("/notebook/job/" + note.getId()); assertThat("test notebook jobs run:", getNoteJobs, isAllowed()); @@ -567,12 +567,12 @@ public void testRegressionZEPPELIN_527() throws IOException { assertFalse(body.get(0).containsKey("finished")); getNoteJobs.releaseConnection(); - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testInsertParagraph() throws IOException { - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); String jsonRequest = "{\"title\": \"title1\", \"text\": \"text1\"}"; PostMethod post = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest); @@ -607,17 +607,17 @@ public void testInsertParagraph() throws IOException { assertEquals("title2", paragraphAtIdx0.getTitle()); assertEquals("text2", paragraphAtIdx0.getText()); - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testGetParagraph() throws IOException { - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); Paragraph p = note.addParagraph(); p.setTitle("hello"); p.setText("world"); - note.persist(); + note.persist(null); GetMethod get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p.getId()); LOG.info("testGetParagraph response\n" + get.getResponseBodyAsString()); @@ -636,12 +636,12 @@ public void testGetParagraph() throws IOException { assertEquals("hello", body.get("title")); assertEquals("world", body.get("text")); - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testMoveParagraph() throws IOException { - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); Paragraph p = note.addParagraph(); p.setTitle("title1"); @@ -651,7 +651,7 @@ public void testMoveParagraph() throws IOException { p2.setTitle("title2"); p2.setText("text2"); - note.persist(); + note.persist(null); PostMethod post = httpPost("/notebook/" + note.getId() + "/paragraph/" + p2.getId() + "/move/" + 0, ""); assertThat("Test post method: ", post, isAllowed()); @@ -668,18 +668,18 @@ public void testMoveParagraph() throws IOException { assertThat("Test post method: ", post2, isBadRequest()); post.releaseConnection(); - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test public void testDeleteParagraph() throws IOException { - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); Paragraph p = note.addParagraph(); p.setTitle("title1"); p.setText("text1"); - note.persist(); + note.persist(null); DeleteMethod delete = httpDelete("/notebook/" + note.getId() + "/paragraph/" + p.getId()); assertThat("Test delete method: ", delete, isAllowed()); @@ -689,7 +689,7 @@ public void testDeleteParagraph() throws IOException { Paragraph retrParagrah = retrNote.getParagraph(p.getId()); assertNull("paragraph should be deleted", retrParagrah); - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } @Test @@ -705,12 +705,12 @@ public void testSearch() throws IOException { String username = body.get("principal"); getSecurityTicket.releaseConnection(); - Note note1 = ZeppelinServer.notebook.createNote(); + Note note1 = ZeppelinServer.notebook.createNote(null); String jsonRequest = "{\"title\": \"title1\", \"text\": \"ThisIsToTestSearchMethodWithPermissions 1\"}"; PostMethod postNotebookText = httpPost("/notebook/" + note1.getId() + "/paragraph", jsonRequest); postNotebookText.releaseConnection(); - Note note2 = ZeppelinServer.notebook.createNote(); + Note note2 = ZeppelinServer.notebook.createNote(null); jsonRequest = "{\"title\": \"title1\", \"text\": \"ThisIsToTestSearchMethodWithPermissions 2\"}"; postNotebookText = httpPost("/notebook/" + note2.getId() + "/paragraph", jsonRequest); postNotebookText.releaseConnection(); @@ -752,13 +752,13 @@ public void testSearch() throws IOException { getPermission.releaseConnection(); } searchNotebook.releaseConnection(); - ZeppelinServer.notebook.removeNote(note1.getId()); - ZeppelinServer.notebook.removeNote(note2.getId()); + ZeppelinServer.notebook.removeNote(note1.getId(), null); + ZeppelinServer.notebook.removeNote(note2.getId(), null); } @Test public void testTitleSearch() throws IOException { - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); String jsonRequest = "{\"title\": \"testTitleSearchOfParagraph\", \"text\": \"ThisIsToTestSearchMethodWithTitle \"}"; PostMethod postNotebookText = httpPost("/notebook/" + note.getId() + "/paragraph", jsonRequest); postNotebookText.releaseConnection(); @@ -779,7 +779,7 @@ public void testTitleSearch() throws IOException { } assertEquals("Paragraph title hits must be at-least one", true, numberOfTitleHits >= 1); searchNotebook.releaseConnection(); - ZeppelinServer.notebook.removeNote(note.getId()); + ZeppelinServer.notebook.removeNote(note.getId(), null); } } diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java index a928e97df94..d234ffd4b83 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinSparkClusterTest.java @@ -68,7 +68,7 @@ private void waitForFinish(Paragraph p) { @Test public void basicRDDTransformationAndActionTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); // run markdown paragraph, again Paragraph p = note.addParagraph(); @@ -80,13 +80,13 @@ public void basicRDDTransformationAndActionTest() throws IOException { waitForFinish(p); assertEquals(Status.FINISHED, p.getStatus()); assertEquals("55", p.getResult().message()); - ZeppelinServer.notebook.removeNote(note.id()); + ZeppelinServer.notebook.removeNote(note.id(), null); } @Test public void sparkRTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); int sparkVersion = getSparkVersionNumber(note); if (isSparkR() && sparkVersion >= 14) { // sparkr supported from 1.4.0 @@ -104,13 +104,13 @@ public void sparkRTest() throws IOException { assertEquals(Status.FINISHED, p.getStatus()); assertEquals("[1] 3", p.getResult().message()); } - ZeppelinServer.notebook.removeNote(note.id()); + ZeppelinServer.notebook.removeNote(note.id(), null); } @Test public void pySparkTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); note.setName("note"); int sparkVersion = getSparkVersionNumber(note); @@ -127,13 +127,13 @@ public void pySparkTest() throws IOException { assertEquals(Status.FINISHED, p.getStatus()); assertEquals("55\n", p.getResult().message()); } - ZeppelinServer.notebook.removeNote(note.id()); + ZeppelinServer.notebook.removeNote(note.id(), null); } @Test public void pySparkAutoConvertOptionTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); note.setName("note"); int sparkVersion = getSparkVersionNumber(note); @@ -152,13 +152,13 @@ public void pySparkAutoConvertOptionTest() throws IOException { assertEquals(Status.FINISHED, p.getStatus()); assertEquals("10\n", p.getResult().message()); } - ZeppelinServer.notebook.removeNote(note.id()); + ZeppelinServer.notebook.removeNote(note.id(), null); } @Test public void zRunTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); Paragraph p0 = note.addParagraph(); Map config0 = p0.getConfig(); config0.put("enabled", true); @@ -184,13 +184,13 @@ public void zRunTest() throws IOException { assertEquals(Status.FINISHED, p2.getStatus()); assertEquals("10", p2.getResult().message()); - ZeppelinServer.notebook.removeNote(note.id()); + ZeppelinServer.notebook.removeNote(note.id(), null); } @Test public void pySparkDepLoaderTest() throws IOException { // create new note - Note note = ZeppelinServer.notebook.createNote(); + Note note = ZeppelinServer.notebook.createNote(null); if (isPyspark() && getSparkVersionNumber(note) >= 14) { // restart spark interpreter diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java index b904b6849e0..ee2c7c6aa94 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java @@ -89,7 +89,7 @@ public void checkInvalidOrigin(){ @Test public void testMakeSureNoAngularObjectBroadcastToWebsocketWhoFireTheEvent() throws IOException { // create a notebook - Note note1 = notebook.createNote(); + Note note1 = notebook.createNote(null); // get reference to interpreterGroup InterpreterGroup interpreterGroup = null; @@ -139,7 +139,7 @@ public void testMakeSureNoAngularObjectBroadcastToWebsocketWhoFireTheEvent() thr verify(sock1, times(0)).send(anyString()); verify(sock2, times(1)).send(anyString()); - notebook.removeNote(note1.getId()); + notebook.removeNote(note1.getId(), null); } @Test @@ -162,7 +162,7 @@ public void testImportNotebook() throws IOException { assertNotEquals(null, notebook.getNote(note.getId())); assertEquals("Test Zeppelin notebook import", notebook.getNote(note.getId()).getName()); assertEquals("Test paragraphs import", notebook.getNote(note.getId()).getParagraphs().get(0).getText()); - notebook.removeNote(note.getId()); + notebook.removeNote(note.getId(), null); } @Test diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java index 01d625abe00..3ed81f4a4e2 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java @@ -479,27 +479,27 @@ private void removeAllAngularObjectInParagraph(String paragraphId) { } } - public void persist() throws IOException { + public void persist(AuthenticationInfo subject) throws IOException { stopDelayedPersistTimer(); snapshotAngularObjectRegistry(); index.updateIndexDoc(this); - repo.save(this); + repo.save(this, subject); } /** * Persist this note with maximum delay. * @param maxDelaySec */ - public void persist(int maxDelaySec) { - startDelayedPersistTimer(maxDelaySec); + public void persist(int maxDelaySec, AuthenticationInfo subject) { + startDelayedPersistTimer(maxDelaySec, subject); } - public void unpersist() throws IOException { - repo.remove(id()); + public void unpersist(AuthenticationInfo subject) throws IOException { + repo.remove(id(), subject); } - private void startDelayedPersistTimer(int maxDelaySec) { + private void startDelayedPersistTimer(int maxDelaySec, final AuthenticationInfo subject) { synchronized (this) { if (delayedPersist != null) { return; @@ -510,7 +510,7 @@ private void startDelayedPersistTimer(int maxDelaySec) { @Override public void run() { try { - persist(); + persist(subject); } catch (IOException e) { logger.error(e.getMessage(), e); } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index 58a552d9ae0..bf0417d6e10 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -43,6 +43,7 @@ import org.apache.zeppelin.resource.ResourcePoolUtils; import org.apache.zeppelin.scheduler.SchedulerFactory; import org.apache.zeppelin.search.SearchService; +import org.apache.zeppelin.user.AuthenticationInfo; import org.apache.zeppelin.user.Credentials; import org.quartz.CronScheduleBuilder; import org.quartz.CronTrigger; @@ -131,12 +132,12 @@ public Notebook(ZeppelinConfiguration conf, NotebookRepo notebookRepo, * @return * @throws IOException */ - public Note createNote() throws IOException { + public Note createNote(AuthenticationInfo subject) throws IOException { Note note; if (conf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_AUTO_INTERPRETER_BINDING)) { - note = createNote(replFactory.getDefaultInterpreterSettingList()); + note = createNote(replFactory.getDefaultInterpreterSettingList(), subject); } else { - note = createNote(null); + note = createNote(null, subject); } notebookIndex.addIndexDoc(note); return note; @@ -148,7 +149,8 @@ public Note createNote() throws IOException { * @return * @throws IOException */ - public Note createNote(List interpreterIds) throws IOException { + public Note createNote(List interpreterIds, AuthenticationInfo subject) + throws IOException { NoteInterpreterLoader intpLoader = new NoteInterpreterLoader(replFactory); Note note = new Note(notebookRepo, intpLoader, jobListenerFactory, notebookIndex, credentials); intpLoader.setNoteId(note.id()); @@ -160,7 +162,7 @@ public Note createNote(List interpreterIds) throws IOException { } notebookIndex.addIndexDoc(note); - note.persist(); + note.persist(subject); return note; } @@ -188,7 +190,8 @@ public String exportNote(String noteId) throws IOException, IllegalArgumentExcep * @return notebook ID * @throws IOException */ - public Note importNote(String sourceJson, String noteName) throws IOException { + public Note importNote(String sourceJson, String noteName, AuthenticationInfo subject) + throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); @@ -197,7 +200,7 @@ public Note importNote(String sourceJson, String noteName) throws IOException { Note newNote; try { Note oldNote = gson.fromJson(reader, Note.class); - newNote = createNote(); + newNote = createNote(subject); if (noteName != null) newNote.setName(noteName); else @@ -207,7 +210,7 @@ public Note importNote(String sourceJson, String noteName) throws IOException { newNote.addCloneParagraph(p); } - newNote.persist(); + newNote.persist(subject); } catch (IOException e) { logger.error(e.toString(), e); throw e; @@ -223,14 +226,14 @@ public Note importNote(String sourceJson, String noteName) throws IOException { * @return noteId * @throws IOException, CloneNotSupportedException, IllegalArgumentException */ - public Note cloneNote(String sourceNoteID, String newNoteName) throws + public Note cloneNote(String sourceNoteID, String newNoteName, AuthenticationInfo subject) throws IOException, CloneNotSupportedException, IllegalArgumentException { Note sourceNote = getNote(sourceNoteID); if (sourceNote == null) { throw new IllegalArgumentException(sourceNoteID + "not found"); } - Note newNote = createNote(); + Note newNote = createNote(subject); if (newNoteName != null) { newNote.setName(newNoteName); } @@ -244,7 +247,7 @@ public Note cloneNote(String sourceNoteID, String newNoteName) throws } notebookIndex.addIndexDoc(newNote); - newNote.persist(); + newNote.persist(subject); return newNote; } @@ -282,7 +285,7 @@ public Note getNote(String id) { } } - public void removeNote(String id) { + public void removeNote(String id, AuthenticationInfo subject) { Note note; synchronized (notes) { @@ -315,21 +318,22 @@ public void removeNote(String id) { ResourcePoolUtils.removeResourcesBelongsToNote(id); try { - note.unpersist(); + note.unpersist(subject); } catch (IOException e) { logger.error(e.toString(), e); } } - public void checkpointNote(String noteId, String checkpointMessage) throws IOException { - notebookRepo.checkpoint(noteId, checkpointMessage); + public void checkpointNote(String noteId, String checkpointMessage, AuthenticationInfo subject) + throws IOException { + notebookRepo.checkpoint(noteId, checkpointMessage, subject); } @SuppressWarnings("rawtypes") - private Note loadNoteFromRepo(String id) { + private Note loadNoteFromRepo(String id, AuthenticationInfo subject) { Note note = null; try { - note = notebookRepo.get(id); + note = notebookRepo.get(id, subject); } catch (IOException e) { logger.error("Failed to load " + id, e); } @@ -403,10 +407,10 @@ private Note loadNoteFromRepo(String id) { } private void loadAllNotes() throws IOException { - List noteInfos = notebookRepo.list(); + List noteInfos = notebookRepo.list(null); for (NoteInfo info : noteInfos) { - loadNoteFromRepo(info.getId()); + loadNoteFromRepo(info.getId(), null); } } @@ -417,7 +421,7 @@ private void loadAllNotes() throws IOException { * @return * @throws IOException */ - public void reloadAllNotes() throws IOException { + public void reloadAllNotes(AuthenticationInfo subject) throws IOException { synchronized (notes) { notes.clear(); } @@ -429,9 +433,9 @@ public void reloadAllNotes() throws IOException { } } - List noteInfos = notebookRepo.list(); + List noteInfos = notebookRepo.list(subject); for (NoteInfo info : noteInfos) { - loadNoteFromRepo(info.getId()); + loadNoteFromRepo(info.getId(), subject); } } @@ -539,12 +543,12 @@ private long getUnixTimeLastRunParagraph(Paragraph paragraph) { } public List> getJobListforNotebook(boolean needsReload, - long lastUpdateServerUnixTime) { + long lastUpdateServerUnixTime, AuthenticationInfo subject) { final String CRON_TYPE_NOTEBOOK_KEYWORD = "cron"; if (needsReload) { try { - reloadAllNotes(); + reloadAllNotes(subject); } catch (IOException e) { logger.error("Fail to reload notes from repository"); } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/AzureNotebookRepo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/AzureNotebookRepo.java index 3a3bffdd800..fdb6bbfc8cd 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/AzureNotebookRepo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/AzureNotebookRepo.java @@ -29,6 +29,7 @@ import org.apache.zeppelin.notebook.NoteInfo; import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.scheduler.Job; +import org.apache.zeppelin.user.AuthenticationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; @@ -70,7 +71,7 @@ public AzureNotebookRepo(ZeppelinConfiguration conf) } @Override - public List list() throws IOException { + public List list(AuthenticationInfo subject) throws IOException { List infos = new LinkedList(); NoteInfo info = null; @@ -134,12 +135,12 @@ private Note getNote(String noteId) throws IOException { } @Override - public Note get(String noteId) throws IOException { + public Note get(String noteId, AuthenticationInfo subject) throws IOException { return getNote(noteId); } @Override - public void save(Note note) throws IOException { + public void save(Note note, AuthenticationInfo subject) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); @@ -186,7 +187,7 @@ private void delete(ListFileItem item) throws StorageException { } @Override - public void remove(String noteId) throws IOException { + public void remove(String noteId, AuthenticationInfo subject) throws IOException { try { CloudFileDirectory dir = rootDir.getDirectoryReference(noteId); @@ -205,20 +206,21 @@ public void close() { } @Override - public Revision checkpoint(String noteId, String checkpointMsg) throws IOException { + public Revision checkpoint(String noteId, String checkpointMsg, AuthenticationInfo subject) + throws IOException { // no-op LOG.info("Checkpoint feature isn't supported in {}", this.getClass().toString()); return null; } @Override - public Note get(String noteId, Revision rev) throws IOException { + public Note get(String noteId, Revision rev, AuthenticationInfo subject) throws IOException { // Auto-generated method stub return null; } @Override - public List revisionHistory(String noteId) { + public List revisionHistory(String noteId, AuthenticationInfo subject) { // Auto-generated method stub return null; } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/GitNotebookRepo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/GitNotebookRepo.java index 2ab7c60f2ff..243e4d025b7 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/GitNotebookRepo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/GitNotebookRepo.java @@ -23,6 +23,7 @@ import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.notebook.Note; +import org.apache.zeppelin.user.AuthenticationInfo; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.NoHeadException; @@ -65,8 +66,8 @@ public GitNotebookRepo(ZeppelinConfiguration conf) throws IOException { } @Override - public synchronized void save(Note note) throws IOException { - super.save(note); + public synchronized void save(Note note, AuthenticationInfo subject) throws IOException { + super.save(note, subject); } /* implemented as git add+commit @@ -76,7 +77,7 @@ public synchronized void save(Note note) throws IOException { * @see org.apache.zeppelin.notebook.repo.VFSNotebookRepo#checkpoint(String, String) */ @Override - public Revision checkpoint(String pattern, String commitMessage) { + public Revision checkpoint(String pattern, String commitMessage, AuthenticationInfo subject) { Revision revision = null; try { List gitDiff = git.diff().call(); @@ -96,13 +97,13 @@ public Revision checkpoint(String pattern, String commitMessage) { } @Override - public Note get(String noteId, Revision rev) throws IOException { + public Note get(String noteId, Revision rev, AuthenticationInfo subject) throws IOException { //TODO(bzz): something like 'git checkout rev', that will not change-the-world though - return super.get(noteId); + return super.get(noteId, subject); } @Override - public List revisionHistory(String noteId) { + public List revisionHistory(String noteId, AuthenticationInfo subject) { List history = Lists.newArrayList(); LOG.debug("Listing history for {}:", noteId); try { diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepo.java index 855b7ad47da..86247927d87 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepo.java @@ -23,15 +23,44 @@ import org.apache.zeppelin.annotation.ZeppelinApi; import org.apache.zeppelin.notebook.Note; import org.apache.zeppelin.notebook.NoteInfo; +import org.apache.zeppelin.user.AuthenticationInfo; /** * Notebook repository (persistence layer) abstraction */ public interface NotebookRepo { - @ZeppelinApi public List list() throws IOException; - @ZeppelinApi public Note get(String noteId) throws IOException; - @ZeppelinApi public void save(Note note) throws IOException; - @ZeppelinApi public void remove(String noteId) throws IOException; + /** + * Lists notebook information about all notebooks in storage. + * @param subject contains user information. + * @return + * @throws IOException + */ + @ZeppelinApi public List list(AuthenticationInfo subject) throws IOException; + + /** + * Get the notebook with the given id. + * @param noteId is notebook id. + * @param subject contains user information. + * @return + * @throws IOException + */ + @ZeppelinApi public Note get(String noteId, AuthenticationInfo subject) throws IOException; + + /** + * Save given note in storage + * @param note is the note itself. + * @param subject contains user information. + * @throws IOException + */ + @ZeppelinApi public void save(Note note, AuthenticationInfo subject) throws IOException; + + /** + * Remove note with given id. + * @param noteId is the note id. + * @param subject contains user information. + * @throws IOException + */ + @ZeppelinApi public void remove(String noteId, AuthenticationInfo subject) throws IOException; /** * Release any underlying resources @@ -39,8 +68,9 @@ public interface NotebookRepo { @ZeppelinApi public void close(); /** - * Versioning API + * Versioning API (optional, preferred to have). */ + /** * chekpoint (set revision) for notebook. * @param noteId Id of the Notebook @@ -48,7 +78,8 @@ public interface NotebookRepo { * @return Rev * @throws IOException */ - @ZeppelinApi public Revision checkpoint(String noteId, String checkpointMsg) throws IOException; + @ZeppelinApi public Revision checkpoint(String noteId, String checkpointMsg, + AuthenticationInfo subject) throws IOException; /** * Get particular revision of the Notebook. @@ -58,7 +89,8 @@ public interface NotebookRepo { * @return a Notebook * @throws IOException */ - @ZeppelinApi public Note get(String noteId, Revision rev) throws IOException; + @ZeppelinApi public Note get(String noteId, Revision rev, AuthenticationInfo subject) + throws IOException; /** * List of revisions of the given Notebook. @@ -66,7 +98,7 @@ public interface NotebookRepo { * @param noteId id of the Notebook * @return list of revisions */ - @ZeppelinApi public List revisionHistory(String noteId); + @ZeppelinApi public List revisionHistory(String noteId, AuthenticationInfo subject); /** * Represents the 'Revision' a point in life of the notebook @@ -81,4 +113,5 @@ public Revision(String revId, String message, int time) { public String message; public int time; } + } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java index 389c6fd7d7a..b396da053d3 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java @@ -31,6 +31,7 @@ import org.apache.zeppelin.notebook.Note; import org.apache.zeppelin.notebook.NoteInfo; import org.apache.zeppelin.notebook.Paragraph; +import org.apache.zeppelin.user.AuthenticationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -114,37 +115,37 @@ private void initializeDefaultStorage(ZeppelinConfiguration conf) { * Lists Notebooks from the first repository */ @Override - public List list() throws IOException { - return getRepo(0).list(); + public List list(AuthenticationInfo subject) throws IOException { + return getRepo(0).list(subject); } /* list from specific repo (for tests) */ - List list(int repoIndex) throws IOException { - return getRepo(repoIndex).list(); + List list(int repoIndex, AuthenticationInfo subject) throws IOException { + return getRepo(repoIndex).list(subject); } /** * Returns from Notebook from the first repository */ @Override - public Note get(String noteId) throws IOException { - return getRepo(0).get(noteId); + public Note get(String noteId, AuthenticationInfo subject) throws IOException { + return getRepo(0).get(noteId, subject); } /* get note from specific repo (for tests) */ - Note get(int repoIndex, String noteId) throws IOException { - return getRepo(repoIndex).get(noteId); + Note get(int repoIndex, String noteId, AuthenticationInfo subject) throws IOException { + return getRepo(repoIndex).get(noteId, subject); } /** * Saves to all repositories */ @Override - public void save(Note note) throws IOException { - getRepo(0).save(note); + public void save(Note note, AuthenticationInfo subject) throws IOException { + getRepo(0).save(note, subject); if (getRepoCount() > 1) { try { - getRepo(1).save(note); + getRepo(1).save(note, subject); } catch (IOException e) { LOG.info(e.getMessage() + ": Failed to write to secondary storage"); @@ -153,14 +154,14 @@ public void save(Note note) throws IOException { } /* save note to specific repo (for tests) */ - void save(int repoIndex, Note note) throws IOException { - getRepo(repoIndex).save(note); + void save(int repoIndex, Note note, AuthenticationInfo subject) throws IOException { + getRepo(repoIndex).save(note, subject); } @Override - public void remove(String noteId) throws IOException { + public void remove(String noteId, AuthenticationInfo subject) throws IOException { for (NotebookRepo repo : repos) { - repo.remove(noteId); + repo.remove(noteId, subject); } /* TODO(khalid): handle case when removing from secondary storage fails */ } @@ -174,8 +175,8 @@ void sync(int sourceRepoIndex, int destRepoIndex) throws IOException { LOG.info("Sync started"); NotebookRepo srcRepo = getRepo(sourceRepoIndex); NotebookRepo dstRepo = getRepo(destRepoIndex); - List srcNotes = srcRepo.list(); - List dstNotes = dstRepo.list(); + List srcNotes = srcRepo.list(null); + List dstNotes = dstRepo.list(null); Map> noteIDs = notesCheckDiff(srcNotes, srcRepo, dstNotes, dstRepo); List pushNoteIDs = noteIDs.get(pushKey); @@ -210,7 +211,7 @@ public void sync() throws IOException { private void pushNotes(List ids, NotebookRepo localRepo, NotebookRepo remoteRepo) throws IOException { for (String id : ids) { - remoteRepo.save(localRepo.get(id)); + remoteRepo.save(localRepo.get(id, null), null); } } @@ -242,8 +243,8 @@ private Map> notesCheckDiff(List sourceNotes, dnote = containsID(destNotes, snote.getId()); if (dnote != null) { /* note exists in source and destination storage systems */ - sdate = lastModificationDate(sourceRepo.get(snote.getId())); - ddate = lastModificationDate(destRepo.get(dnote.getId())); + sdate = lastModificationDate(sourceRepo.get(snote.getId(), null)); + ddate = lastModificationDate(destRepo.get(dnote.getId(), null)); if (sdate.after(ddate)) { /* source contains more up to date note - push */ pushIDs.add(snote.getId()); @@ -354,7 +355,8 @@ public void close() { //checkpoint to all available storages @Override - public Revision checkpoint(String noteId, String checkpointMsg) throws IOException { + public Revision checkpoint(String noteId, String checkpointMsg, AuthenticationInfo subject) + throws IOException { int repoCount = getRepoCount(); int repoBound = Math.min(repoCount, getMaxRepoNum()); int errorCount = 0; @@ -363,7 +365,7 @@ public Revision checkpoint(String noteId, String checkpointMsg) throws IOExcepti Revision rev = null; for (int i = 0; i < repoBound; i++) { try { - allRepoCheckpoints.add(getRepo(i).checkpoint(noteId, checkpointMsg)); + allRepoCheckpoints.add(getRepo(i).checkpoint(noteId, checkpointMsg, subject)); } catch (IOException e) { LOG.warn("Couldn't checkpoint in {} storage with index {} for note {}", getRepo(i).getClass().toString(), i, noteId); @@ -387,13 +389,13 @@ public Revision checkpoint(String noteId, String checkpointMsg) throws IOExcepti } @Override - public Note get(String noteId, Revision rev) throws IOException { + public Note get(String noteId, Revision rev, AuthenticationInfo subject) throws IOException { // Auto-generated method stub return null; } @Override - public List revisionHistory(String noteId) { + public List revisionHistory(String noteId, AuthenticationInfo subject) { // Auto-generated method stub return null; } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/S3NotebookRepo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/S3NotebookRepo.java index c760667f3d8..fc6918622c4 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/S3NotebookRepo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/S3NotebookRepo.java @@ -38,6 +38,7 @@ import org.apache.zeppelin.notebook.NoteInfo; import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.scheduler.Job.Status; +import org.apache.zeppelin.user.AuthenticationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -136,7 +137,7 @@ private EncryptionMaterialsProvider createCustomProvider(ZeppelinConfiguration c } @Override - public List list() throws IOException { + public List list(AuthenticationInfo subject) throws IOException { List infos = new LinkedList<>(); NoteInfo info; try { @@ -196,12 +197,12 @@ private NoteInfo getNoteInfo(String key) throws IOException { } @Override - public Note get(String noteId) throws IOException { + public Note get(String noteId, AuthenticationInfo subject) throws IOException { return getNote(user + "/" + "notebook" + "/" + noteId + "/" + "note.json"); } @Override - public void save(Note note) throws IOException { + public void save(Note note, AuthenticationInfo subject) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); @@ -224,7 +225,7 @@ public void save(Note note) throws IOException { } @Override - public void remove(String noteId) throws IOException { + public void remove(String noteId, AuthenticationInfo subject) throws IOException { String key = user + "/" + "notebook" + "/" + noteId; final ListObjectsRequest listObjectsRequest = new ListObjectsRequest() .withBucketName(bucketName).withPrefix(key); @@ -249,19 +250,20 @@ public void close() { } @Override - public Revision checkpoint(String noteId, String checkpointMsg) throws IOException { + public Revision checkpoint(String noteId, String checkpointMsg, AuthenticationInfo subject) + throws IOException { // Auto-generated method stub return null; } @Override - public Note get(String noteId, Revision rev) throws IOException { + public Note get(String noteId, Revision rev, AuthenticationInfo subject) throws IOException { // Auto-generated method stub return null; } @Override - public List revisionHistory(String noteId) { + public List revisionHistory(String noteId, AuthenticationInfo subject) { // Auto-generated method stub return null; } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepo.java index 06cf25f1487..152e0875a15 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepo.java @@ -40,6 +40,7 @@ import org.apache.zeppelin.notebook.NoteInfo; import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.scheduler.Job.Status; +import org.apache.zeppelin.user.AuthenticationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -107,7 +108,7 @@ private boolean isDirectory(FileObject fo) throws IOException { } @Override - public List list() throws IOException { + public List list(AuthenticationInfo subject) throws IOException { FileObject rootDir = getRootDir(); FileObject[] children = rootDir.getChildren(); @@ -182,7 +183,7 @@ private NoteInfo getNoteInfo(FileObject noteDir) throws IOException { } @Override - public Note get(String noteId) throws IOException { + public Note get(String noteId, AuthenticationInfo subject) throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD); @@ -204,7 +205,7 @@ protected FileObject getRootDir() throws IOException { } @Override - public synchronized void save(Note note) throws IOException { + public synchronized void save(Note note, AuthenticationInfo subject) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); @@ -230,7 +231,7 @@ public synchronized void save(Note note) throws IOException { } @Override - public void remove(String noteId) throws IOException { + public void remove(String noteId, AuthenticationInfo subject) throws IOException { FileObject rootDir = fsManager.resolveFile(getPath("/")); FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD); @@ -253,19 +254,20 @@ public void close() { } @Override - public Revision checkpoint(String noteId, String checkpointMsg) throws IOException { + public Revision checkpoint(String noteId, String checkpointMsg, AuthenticationInfo subject) + throws IOException { // Auto-generated method stub return null; } @Override - public Note get(String noteId, Revision rev) throws IOException { + public Note get(String noteId, Revision rev, AuthenticationInfo subject) throws IOException { // Auto-generated method stub return null; } @Override - public List revisionHistory(String noteId) { + public List revisionHistory(String noteId, AuthenticationInfo subject) { // Auto-generated method stub return null; } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepo.java index 2c249c9d4ec..d2f6ca2f755 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepo.java @@ -29,6 +29,7 @@ import org.apache.zeppelin.notebook.repo.NotebookRepo; import org.apache.zeppelin.notebook.repo.zeppelinhub.rest.ZeppelinhubRestApiHandler; import org.apache.zeppelin.notebook.repo.zeppelinhub.websocket.Client; +import org.apache.zeppelin.user.AuthenticationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -141,7 +142,7 @@ String getZeppelinHubUrl(ZeppelinConfiguration conf) { } @Override - public List list() throws IOException { + public List list(AuthenticationInfo subject) throws IOException { String response = restApiClient.asyncGet(""); List notes = GSON.fromJson(response, new TypeToken>() {}.getType()); if (notes == null) { @@ -152,7 +153,7 @@ public List list() throws IOException { } @Override - public Note get(String noteId) throws IOException { + public Note get(String noteId, AuthenticationInfo subject) throws IOException { if (StringUtils.isBlank(noteId)) { return EMPTY_NOTE; } @@ -167,7 +168,7 @@ public Note get(String noteId) throws IOException { } @Override - public void save(Note note) throws IOException { + public void save(Note note, AuthenticationInfo subject) throws IOException { if (note == null) { throw new IOException("Zeppelinhub failed to save empty note"); } @@ -177,7 +178,7 @@ public void save(Note note) throws IOException { } @Override - public void remove(String noteId) throws IOException { + public void remove(String noteId, AuthenticationInfo subject) throws IOException { restApiClient.asyncDel(noteId); LOG.info("ZeppelinHub REST API removing note {} ", noteId); } @@ -188,19 +189,20 @@ public void close() { } @Override - public Revision checkpoint(String noteId, String checkpointMsg) throws IOException { + public Revision checkpoint(String noteId, String checkpointMsg, AuthenticationInfo subject) + throws IOException { // Auto-generated method stub return null; } @Override - public Note get(String noteId, Revision rev) throws IOException { + public Note get(String noteId, Revision rev, AuthenticationInfo subject) throws IOException { // Auto-generated method stub return null; } @Override - public List revisionHistory(String noteId) { + public List revisionHistory(String noteId, AuthenticationInfo subject) { // Auto-generated method stub return null; } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java index 53749d1ddea..509caf94326 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java @@ -109,7 +109,7 @@ public void tearDown() throws Exception { @Test public void testSelectingReplImplementation() throws IOException { - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); // run with defatul repl @@ -148,8 +148,8 @@ public void testReloadAllNotes() throws IOException { assertEquals(notes.size(), 0); // load copied notebook on memory when reloadAllNotes() is called - Note copiedNote = notebookRepo.get("2A94M5J1Z"); - notebook.reloadAllNotes(); + Note copiedNote = notebookRepo.get("2A94M5J1Z", null); + notebook.reloadAllNotes(null); notes = notebook.getAllNotes(); assertEquals(notes.size(), 1); assertEquals(notes.get(0).id(), copiedNote.id()); @@ -164,14 +164,14 @@ public void testReloadAllNotes() throws IOException { assertEquals(notes.size(), 1); // delete notebook from notebook list when reloadAllNotes() is called - notebook.reloadAllNotes(); + notebook.reloadAllNotes(null); notes = notebook.getAllNotes(); assertEquals(notes.size(), 0); } @Test public void testPersist() throws IOException, SchedulerException, RepositoryException { - Note note = notebook.createNote(); + Note note = notebook.createNote(null); // run with default repl Paragraph p1 = note.addParagraph(); @@ -179,7 +179,7 @@ public void testPersist() throws IOException, SchedulerException, RepositoryExce config.put("enabled", true); p1.setConfig(config); p1.setText("hello world"); - note.persist(); + note.persist(null); Notebook notebook2 = new Notebook( conf, notebookRepo, schedulerFactory, @@ -189,7 +189,7 @@ public void testPersist() throws IOException, SchedulerException, RepositoryExce @Test public void testClearParagraphOutput() throws IOException, SchedulerException{ - Note note = notebook.createNote(); + Note note = notebook.createNote(null); Paragraph p1 = note.addParagraph(); Map config = p1.getConfig(); config.put("enabled", true); @@ -207,7 +207,7 @@ public void testClearParagraphOutput() throws IOException, SchedulerException{ @Test public void testRunAll() throws IOException { - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); // p1 @@ -240,13 +240,13 @@ public void testRunAll() throws IOException { assertNull(p2.getResult()); assertEquals("repl1: p3", p3.getResult().message()); - notebook.removeNote(note.getId()); + notebook.removeNote(note.getId(), null); } @Test public void testSchedule() throws InterruptedException, IOException{ // create a note and a paragraph - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); Paragraph p = note.addParagraph(); @@ -278,7 +278,7 @@ public void testSchedule() throws InterruptedException, IOException{ @Test public void testAutoRestartInterpreterAfterSchedule() throws InterruptedException, IOException{ // create a note and a paragraph - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); Paragraph p = note.addParagraph(); @@ -319,7 +319,7 @@ public void testAutoRestartInterpreterAfterSchedule() throws InterruptedExceptio @Test public void testCloneNote() throws IOException, CloneNotSupportedException, InterruptedException { - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); final Paragraph p = note.addParagraph(); @@ -328,7 +328,7 @@ public void testCloneNote() throws IOException, CloneNotSupportedException, while(p.isTerminated()==false || p.getResult()==null) Thread.yield(); p.setStatus(Status.RUNNING); - Note cloneNote = notebook.cloneNote(note.getId(), "clone note"); + Note cloneNote = notebook.cloneNote(note.getId(), "clone note", null); Paragraph cp = cloneNote.paragraphs.get(0); assertEquals(cp.getStatus(), Status.READY); @@ -340,7 +340,7 @@ public void testCloneNote() throws IOException, CloneNotSupportedException, @Test public void testResourceRemovealOnParagraphNoteRemove() throws IOException { - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) { intpGroup.setResourcePool(new LocalResourcePool(intpGroup.getId())); @@ -361,7 +361,7 @@ public void testResourceRemovealOnParagraphNoteRemove() throws IOException { assertEquals(1, ResourcePoolUtils.getAllResources().size()); // remove note - notebook.removeNote(note.id()); + notebook.removeNote(note.id(), null); assertEquals(0, ResourcePoolUtils.getAllResources().size()); } @@ -369,7 +369,7 @@ public void testResourceRemovealOnParagraphNoteRemove() throws IOException { public void testAngularObjectRemovalOnNotebookRemove() throws InterruptedException, IOException { // create a note and a paragraph - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); AngularObjectRegistry registry = note.getNoteReplLoader() @@ -388,7 +388,7 @@ public void testAngularObjectRemovalOnNotebookRemove() throws InterruptedExcepti registry.add("o3", "object3", null, null); // remove notebook - notebook.removeNote(note.id()); + notebook.removeNote(note.id(), null); // notebook scope or paragraph scope object should be removed assertNull(registry.get("o1", note.id(), null)); @@ -402,7 +402,7 @@ public void testAngularObjectRemovalOnNotebookRemove() throws InterruptedExcepti public void testAngularObjectRemovalOnParagraphRemove() throws InterruptedException, IOException { // create a note and a paragraph - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); AngularObjectRegistry registry = note.getNoteReplLoader() @@ -435,7 +435,7 @@ public void testAngularObjectRemovalOnParagraphRemove() throws InterruptedExcept public void testAngularObjectRemovalOnInterpreterRestart() throws InterruptedException, IOException { // create a note and a paragraph - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); AngularObjectRegistry registry = note.getNoteReplLoader() @@ -456,13 +456,13 @@ public void testAngularObjectRemovalOnInterpreterRestart() throws InterruptedExc // local and global scope object should be removed assertNull(registry.get("o1", note.id(), null)); assertNull(registry.get("o2", null, null)); - notebook.removeNote(note.id()); + notebook.removeNote(note.id(), null); } @Test public void testPermissions() throws IOException { // create a note and a paragraph - Note note = notebook.createNote(); + Note note = notebook.createNote(null); NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); // empty owners, readers and writers means note is public assertEquals(notebookAuthorization.isOwner(note.id(), @@ -501,13 +501,13 @@ public void testPermissions() throws IOException { assertEquals(notebookAuthorization.isReader(note.id(), new HashSet(Arrays.asList("user3"))), true); - notebook.removeNote(note.id()); + notebook.removeNote(note.id(), null); } @Test public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedException, IOException { - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); ArrayList paragraphs = new ArrayList<>(); @@ -544,7 +544,7 @@ public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedExc @Test public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException { // create a notes - Note note1 = notebook.createNote(); + Note note1 = notebook.createNote(null); Paragraph p1 = note1.addParagraph(); p1.setText("getId"); @@ -559,8 +559,8 @@ public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException { InterpreterResult result = p1.getResult(); // remove note and recreate - notebook.removeNote(note1.getId()); - note1 = notebook.createNote(); + notebook.removeNote(note1.getId(), null); + note1 = notebook.createNote(null); p1 = note1.addParagraph(); p1.setText("getId"); @@ -568,16 +568,16 @@ public void testPerSessionInterpreterCloseOnNoteRemoval() throws IOException { while (p1.getStatus() != Status.FINISHED) Thread.yield(); assertNotEquals(p1.getResult().message(), result.message()); - notebook.removeNote(note1.getId()); + notebook.removeNote(note1.getId(), null); } @Test public void testPerSessionInterpreter() throws IOException { // create two notes - Note note1 = notebook.createNote(); + Note note1 = notebook.createNote(null); Paragraph p1 = note1.addParagraph(); - Note note2 = notebook.createNote(); + Note note2 = notebook.createNote(null); Paragraph p2 = note2.addParagraph(); p1.setText("getId"); @@ -608,14 +608,14 @@ public void testPerSessionInterpreter() throws IOException { assertNotEquals(p1.getResult().message(), p2.getResult().message()); - notebook.removeNote(note1.getId()); - notebook.removeNote(note2.getId()); + notebook.removeNote(note1.getId(), null); + notebook.removeNote(note2.getId(), null); } @Test public void testPerSessionInterpreterCloseOnUnbindInterpreterSetting() throws IOException { // create a notes - Note note1 = notebook.createNote(); + Note note1 = notebook.createNote(null); Paragraph p1 = note1.addParagraph(); p1.setText("getId"); @@ -640,13 +640,13 @@ public void testPerSessionInterpreterCloseOnUnbindInterpreterSetting() throws IO assertNotEquals(result.message(), p1.getResult().message()); - notebook.removeNote(note1.getId()); + notebook.removeNote(note1.getId(), null); } @Test public void testNormalizeNoteName() throws IOException { // create a notes - Note note1 = notebook.createNote(); + Note note1 = notebook.createNote(null); note1.setName("MyNote"); assertEquals(note1.getName(), "MyNote"); @@ -666,7 +666,7 @@ public void testNormalizeNoteName() throws IOException { note1.setName("\\\\\\MyNote///sub"); assertEquals(note1.getName(), "/MyNote/sub"); - notebook.removeNote(note1.getId()); + notebook.removeNote(note1.getId(), null); } private void delete(File file){ diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/GitNotebookRepoTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/GitNotebookRepoTest.java index fe020cbafc5..39db0fe6020 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/GitNotebookRepoTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/GitNotebookRepoTest.java @@ -97,7 +97,7 @@ public void initNonemptyNotebookDir() throws IOException, GitAPIException { assertThat(git).isNotNull(); assertThat(dotGit.exists()).isEqualTo(true); - assertThat(notebookRepo.list()).isNotEmpty(); + assertThat(notebookRepo.list(null)).isNotEmpty(); List diff = git.diff().call(); // no commit, diff isn't empty @@ -108,10 +108,10 @@ public void initNonemptyNotebookDir() throws IOException, GitAPIException { public void showNotebookHistory() throws GitAPIException, IOException { //given notebookRepo = new GitNotebookRepo(conf); - assertThat(notebookRepo.list()).isNotEmpty(); + assertThat(notebookRepo.list(null)).isNotEmpty(); //when - List testNotebookHistory = notebookRepo.revisionHistory(TEST_NOTE_ID); + List testNotebookHistory = notebookRepo.revisionHistory(TEST_NOTE_ID, null); //then //no initial commit, empty history @@ -122,17 +122,17 @@ public void showNotebookHistory() throws GitAPIException, IOException { public void addCheckpoint() throws IOException { // initial checks notebookRepo = new GitNotebookRepo(conf); - assertThat(notebookRepo.list()).isNotEmpty(); - assertThat(containsNote(notebookRepo.list(), TEST_NOTE_ID)).isTrue(); - assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID)).isEmpty(); + assertThat(notebookRepo.list(null)).isNotEmpty(); + assertThat(containsNote(notebookRepo.list(null), TEST_NOTE_ID)).isTrue(); + assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null)).isEmpty(); - notebookRepo.checkpoint(TEST_NOTE_ID, "first commit"); - List notebookHistoryBefore = notebookRepo.revisionHistory(TEST_NOTE_ID); - assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID)).isNotEmpty(); + notebookRepo.checkpoint(TEST_NOTE_ID, "first commit", null); + List notebookHistoryBefore = notebookRepo.revisionHistory(TEST_NOTE_ID, null); + assertThat(notebookRepo.revisionHistory(TEST_NOTE_ID, null)).isNotEmpty(); int initialCount = notebookHistoryBefore.size(); // add changes to note - Note note = notebookRepo.get(TEST_NOTE_ID); + Note note = notebookRepo.get(TEST_NOTE_ID, null); Paragraph p = note.addParagraph(); Map config = p.getConfig(); config.put("enabled", true); @@ -140,11 +140,11 @@ public void addCheckpoint() throws IOException { p.setText("%md checkpoint test text"); // save and checkpoint note - notebookRepo.save(note); - notebookRepo.checkpoint(TEST_NOTE_ID, "second commit"); + notebookRepo.save(note, null); + notebookRepo.checkpoint(TEST_NOTE_ID, "second commit", null); // see if commit is added - List notebookHistoryAfter = notebookRepo.revisionHistory(TEST_NOTE_ID); + List notebookHistoryAfter = notebookRepo.revisionHistory(TEST_NOTE_ID, null); assertThat(notebookHistoryAfter.size()).isEqualTo(initialCount + 1); } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java index 138977ea393..fe7e3fc2de2 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java @@ -118,16 +118,16 @@ public void testRepoCount() throws IOException { public void testSyncOnCreate() throws IOException { /* check that both storage systems are empty */ assertTrue(notebookRepoSync.getRepoCount() > 1); - assertEquals(0, notebookRepoSync.list(0).size()); - assertEquals(0, notebookRepoSync.list(1).size()); + assertEquals(0, notebookRepoSync.list(0, null).size()); + assertEquals(0, notebookRepoSync.list(1, null).size()); /* create note */ - Note note = notebookSync.createNote(); + Note note = notebookSync.createNote(null); // check that automatically saved on both storages - assertEquals(1, notebookRepoSync.list(0).size()); - assertEquals(1, notebookRepoSync.list(1).size()); - assertEquals(notebookRepoSync.list(0).get(0).getId(),notebookRepoSync.list(1).get(0).getId()); + assertEquals(1, notebookRepoSync.list(0, null).size()); + assertEquals(1, notebookRepoSync.list(1, null).size()); + assertEquals(notebookRepoSync.list(0, null).get(0).getId(),notebookRepoSync.list(1, null).get(0).getId()); } @@ -135,22 +135,22 @@ public void testSyncOnCreate() throws IOException { public void testSyncOnDelete() throws IOException { /* create note */ assertTrue(notebookRepoSync.getRepoCount() > 1); - assertEquals(0, notebookRepoSync.list(0).size()); - assertEquals(0, notebookRepoSync.list(1).size()); + assertEquals(0, notebookRepoSync.list(0, null).size()); + assertEquals(0, notebookRepoSync.list(1, null).size()); - Note note = notebookSync.createNote(); + Note note = notebookSync.createNote(null); /* check that created in both storage systems */ - assertEquals(1, notebookRepoSync.list(0).size()); - assertEquals(1, notebookRepoSync.list(1).size()); - assertEquals(notebookRepoSync.list(0).get(0).getId(),notebookRepoSync.list(1).get(0).getId()); + assertEquals(1, notebookRepoSync.list(0, null).size()); + assertEquals(1, notebookRepoSync.list(1, null).size()); + assertEquals(notebookRepoSync.list(0, null).get(0).getId(),notebookRepoSync.list(1, null).get(0).getId()); /* remove Note */ - notebookSync.removeNote(notebookRepoSync.list(0).get(0).getId()); + notebookSync.removeNote(notebookRepoSync.list(0, null).get(0).getId(), null); /* check that deleted in both storages */ - assertEquals(0, notebookRepoSync.list(0).size()); - assertEquals(0, notebookRepoSync.list(1).size()); + assertEquals(0, notebookRepoSync.list(0, null).size()); + assertEquals(0, notebookRepoSync.list(1, null).size()); } @@ -158,7 +158,7 @@ public void testSyncOnDelete() throws IOException { public void testSyncUpdateMain() throws IOException { /* create note */ - Note note = notebookSync.createNote(); + Note note = notebookSync.createNote(null); Paragraph p1 = note.addParagraph(); Map config = p1.getConfig(); config.put("enabled", true); @@ -170,37 +170,37 @@ public void testSyncUpdateMain() throws IOException { /* new paragraph not yet saved into storages */ assertEquals(0, notebookRepoSync.get(0, - notebookRepoSync.list(0).get(0).getId()).getParagraphs().size()); + notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); assertEquals(0, notebookRepoSync.get(1, - notebookRepoSync.list(1).get(0).getId()).getParagraphs().size()); + notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size()); /* save to storage under index 0 (first storage) */ - notebookRepoSync.save(0, note); + notebookRepoSync.save(0, note, null); /* check paragraph saved to first storage */ assertEquals(1, notebookRepoSync.get(0, - notebookRepoSync.list(0).get(0).getId()).getParagraphs().size()); + notebookRepoSync.list(0, null).get(0).getId(), null).getParagraphs().size()); /* check paragraph isn't saved to second storage */ assertEquals(0, notebookRepoSync.get(1, - notebookRepoSync.list(1).get(0).getId()).getParagraphs().size()); + notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size()); /* apply sync */ notebookRepoSync.sync(); /* check whether added to second storage */ assertEquals(1, notebookRepoSync.get(1, - notebookRepoSync.list(1).get(0).getId()).getParagraphs().size()); + notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size()); /* check whether same paragraph id */ assertEquals(p1.getId(), notebookRepoSync.get(0, - notebookRepoSync.list(0).get(0).getId()).getLastParagraph().getId()); + notebookRepoSync.list(0, null).get(0).getId(), null).getLastParagraph().getId()); assertEquals(p1.getId(), notebookRepoSync.get(1, - notebookRepoSync.list(1).get(0).getId()).getLastParagraph().getId()); + notebookRepoSync.list(1, null).get(0).getId(), null).getLastParagraph().getId()); } @Test public void testSyncOnReloadedList() throws IOException { /* check that both storage repos are empty */ assertTrue(notebookRepoSync.getRepoCount() > 1); - assertEquals(0, notebookRepoSync.list(0).size()); - assertEquals(0, notebookRepoSync.list(1).size()); + assertEquals(0, notebookRepoSync.list(0, null).size()); + assertEquals(0, notebookRepoSync.list(1, null).size()); File srcDir = new File("src/test/resources/2A94M5J1Z"); File destDir = new File(secNotebookDir + "/2A94M5J1Z"); @@ -211,13 +211,13 @@ public void testSyncOnReloadedList() throws IOException { } catch (IOException e) { LOG.error(e.toString(), e); } - assertEquals(0, notebookRepoSync.list(0).size()); - assertEquals(1, notebookRepoSync.list(1).size()); + assertEquals(0, notebookRepoSync.list(0, null).size()); + assertEquals(1, notebookRepoSync.list(1, null).size()); // After reloading notebooks repos should be synchronized - notebookSync.reloadAllNotes(); - assertEquals(1, notebookRepoSync.list(0).size()); - assertEquals(1, notebookRepoSync.list(1).size()); + notebookSync.reloadAllNotes(null); + assertEquals(1, notebookRepoSync.list(0, null).size()); + assertEquals(1, notebookRepoSync.list(1, null).size()); } @Test @@ -236,15 +236,15 @@ public void testCheckpointOneStorage() throws IOException, SchedulerException { GitNotebookRepo gitRepo = (GitNotebookRepo) vRepoSync.getRepo(0); // no notes - assertThat(vRepoSync.list().size()).isEqualTo(0); + assertThat(vRepoSync.list(null).size()).isEqualTo(0); // create note - Note note = vNotebookSync.createNote(); - assertThat(vRepoSync.list().size()).isEqualTo(1); + Note note = vNotebookSync.createNote(null); + assertThat(vRepoSync.list(null).size()).isEqualTo(1); - String noteId = vRepoSync.list().get(0).getId(); + String noteId = vRepoSync.list(null).get(0).getId(); // first checkpoint - vRepoSync.checkpoint(noteId, "checkpoint message"); - int vCount = gitRepo.revisionHistory(noteId).size(); + vRepoSync.checkpoint(noteId, "checkpoint message", null); + int vCount = gitRepo.revisionHistory(noteId, null).size(); assertThat(vCount).isEqualTo(1); Paragraph p = note.addParagraph(); @@ -254,9 +254,9 @@ public void testCheckpointOneStorage() throws IOException, SchedulerException { p.setText("%md checkpoint test"); // save and checkpoint again - vRepoSync.save(note); - vRepoSync.checkpoint(noteId, "checkpoint message 2"); - assertThat(gitRepo.revisionHistory(noteId).size()).isEqualTo(vCount + 1); + vRepoSync.save(note, null); + vRepoSync.checkpoint(noteId, "checkpoint message 2", null); + assertThat(gitRepo.revisionHistory(noteId, null).size()).isEqualTo(vCount + 1); } static void delete(File file){ diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java index e5915a97299..0550e901a20 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/VFSNotebookRepoTest.java @@ -93,7 +93,7 @@ public void tearDown() throws Exception { @Test public void testInvalidJsonFile() throws IOException { // given - int numNotes = notebookRepo.list().size(); + int numNotes = notebookRepo.list(null).size(); // when create invalid json file File testNoteDir = new File(mainNotebookDir, "test"); @@ -101,12 +101,12 @@ public void testInvalidJsonFile() throws IOException { FileUtils.writeStringToFile(new File(testNoteDir, "note.json"), ""); // then - assertEquals(numNotes, notebookRepo.list().size()); + assertEquals(numNotes, notebookRepo.list(null).size()); } @Test public void testSaveNotebook() throws IOException, InterruptedException { - Note note = notebook.createNote(); + Note note = notebook.createNote(null); note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); Paragraph p1 = note.addParagraph(); @@ -133,7 +133,7 @@ public void testSaveNotebook() throws IOException, InterruptedException { } note.setName("SaveTest"); - notebookRepo.save(note); + notebookRepo.save(note, null); assertEquals(note.getName(), "SaveTest"); } @@ -146,7 +146,7 @@ public NotebookWriter(Note note) { @Override public void run() { try { - notebookRepo.save(note); + notebookRepo.save(note, null); } catch (IOException e) { LOG.error(e.toString(), e); } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepoTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepoTest.java index 1e83354fc9f..938521a3ab8 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepoTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/zeppelinhub/ZeppelinHubRepoTest.java @@ -123,14 +123,14 @@ public void testGetZeppelinHubWsEndpoint() { @Test public void testGetAllNotes() throws IOException { - List notebooks = repo.list(); + List notebooks = repo.list(null); assertThat(notebooks).isNotEmpty(); assertThat(notebooks.size()).isEqualTo(3); } @Test public void testGetNote() throws IOException { - Note notebook = repo.get("AAAAA"); + Note notebook = repo.get("AAAAA", null); assertThat(notebook).isNotNull(); assertThat(notebook.id()).isEqualTo("2A94M5J1Z"); } @@ -138,13 +138,13 @@ public void testGetNote() throws IOException { @Test public void testRemoveNote() throws IOException { // not suppose to throw - repo.remove("AAAAA"); + repo.remove("AAAAA", null); } @Test public void testRemoveNoteError() throws IOException { // not suppose to throw - repo.remove("BBBBB"); + repo.remove("BBBBB", null); } } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java index dcb68c82dc8..36419294b83 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/search/LuceneSearchTest.java @@ -204,7 +204,7 @@ public void canNotSearchBeforeIndexing() { //when Paragraph p1 = note1.getLastParagraph(); p1.setText("no no no"); - note1.persist(); + note1.persist(null); //then assertThat(resultForQuery("Notebook1").size()).isEqualTo(1); @@ -228,7 +228,7 @@ public void canNotSearchBeforeIndexing() { //when note1.setName("NotebookN"); - note1.persist(); + note1.persist(null); //then assertThat(resultForQuery("Notebook1")).isEmpty();