This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new aa32f62 [ZEPPELIN-5654] Implement GCSNotebookRepo Move
aa32f62 is described below
commit aa32f6258d8df01def4b2552b244f0071f54a24e
Author: Bagus Nurtomo <[email protected]>
AuthorDate: Sat Feb 19 15:46:35 2022 +0700
[ZEPPELIN-5654] Implement GCSNotebookRepo Move
### What is this PR for?
This is to implement move function that is used for renaming notebooks and
moving it to trash.
Currently it would result in a no op, making users unable to rename
notebooks if using GCS as the notebook repository.
### What type of PR is it?
Feature
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-5654
### How should this be tested?
CI
### Screenshots (if appropriate)
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No?
Author: Bagus Nurtomo <[email protected]>
Closes #4297 from BagusThanatos/implement-move-gcsnotebookrepo and squashes
the following commits:
ebcc8870a3 [Bagus Nurtomo] Remove unused variable
102a8ca4ec [Bagus Nurtomo] Fix Tests
65e7c3e9d5 [Bagus Nurtomo] Add test
4ca5009291 [Bagus Nurtomo] Implement GCSNotebookRepo move
---
.../apache/zeppelin/notebook/repo/GCSNotebookRepo.java | 12 ++++++++++--
.../zeppelin/notebook/repo/GCSNotebookRepoTest.java | 16 ++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git
a/zeppelin-plugins/notebookrepo/gcs/src/main/java/org/apache/zeppelin/notebook/repo/GCSNotebookRepo.java
b/zeppelin-plugins/notebookrepo/gcs/src/main/java/org/apache/zeppelin/notebook/repo/GCSNotebookRepo.java
index 529225a..0f2aed3 100644
---
a/zeppelin-plugins/notebookrepo/gcs/src/main/java/org/apache/zeppelin/notebook/repo/GCSNotebookRepo.java
+++
b/zeppelin-plugins/notebookrepo/gcs/src/main/java/org/apache/zeppelin/notebook/repo/GCSNotebookRepo.java
@@ -201,8 +201,16 @@ public class GCSNotebookRepo implements NotebookRepo {
}
@Override
- public void move(String noteId, String notePath, String newNotePath,
AuthenticationInfo subject) {
-
+ public void move(String noteId, String notePath, String newNotePath,
AuthenticationInfo subject) throws IOException {
+ Preconditions.checkArgument(StringUtils.isNotEmpty(noteId));
+ BlobId sourceBlobId = makeBlobId(noteId, notePath);
+ BlobId destinationBlobId = makeBlobId(noteId, newNotePath);
+ try {
+ storage.get(sourceBlobId).copyTo(destinationBlobId);
+ } catch (Exception se) {
+ throw new IOException("Could not copy from " + sourceBlobId.toString() +
" to " + destinationBlobId.toString() + ": " + se.getMessage(), se);
+ }
+ remove(noteId, notePath, subject);
}
@Override
diff --git
a/zeppelin-plugins/notebookrepo/gcs/src/test/java/org/apache/zeppelin/notebook/repo/GCSNotebookRepoTest.java
b/zeppelin-plugins/notebookrepo/gcs/src/test/java/org/apache/zeppelin/notebook/repo/GCSNotebookRepoTest.java
index 295305b..69ef76f 100644
---
a/zeppelin-plugins/notebookrepo/gcs/src/test/java/org/apache/zeppelin/notebook/repo/GCSNotebookRepoTest.java
+++
b/zeppelin-plugins/notebookrepo/gcs/src/test/java/org/apache/zeppelin/notebook/repo/GCSNotebookRepoTest.java
@@ -96,6 +96,7 @@ public class GCSNotebookRepoTest {
Paragraph p = new Paragraph(note, null);
p.setText("text");
p.setStatus(Status.RUNNING);
+ p.setAuthenticationInfo(new AuthenticationInfo("anonymous", (String)null,
"anonymous"));
note.addParagraph(p);
return note;
}
@@ -186,6 +187,21 @@ public class GCSNotebookRepoTest {
assertThat(storage.get(makeBlobId(runningNote.getId(),
runningNote.getPath()))).isNull();
}
+ @Test
+ public void testMove_nonexistent() throws Exception {
+ try {
+ notebookRepo.move("id", "/name", "/name_new", AUTH_INFO);
+ fail();
+ } catch (IOException e) {}
+ }
+
+ @Test
+ public void testMove() throws Exception {
+ create(runningNote);
+ notebookRepo.move(runningNote.getId(), runningNote.getPath(),
runningNote.getPath() + "_new", AUTH_INFO);
+ assertThat(storage.get(makeBlobId(runningNote.getId(),
runningNote.getPath()))).isNull();
+ }
+
private String makeName(String relativePath) {
if (basePath.isPresent()) {
return basePath.get() + "/" + relativePath;