mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Add rest api for clear all paragraph result and add test
This commit is contained in:
parent
98d7604a0f
commit
3d191410ad
2 changed files with 64 additions and 4 deletions
|
|
@ -461,6 +461,30 @@ public class NotebookRestApi {
|
|||
return new JsonResponse(Status.OK, "").build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear result of all paragraphs REST API
|
||||
*
|
||||
* @param noteId ID of Note
|
||||
* @return JSON with status.ok
|
||||
*/
|
||||
@POST
|
||||
@Path("{noteId}/clear")
|
||||
@ZeppelinApi
|
||||
public Response clearAllParagraphOutput(@PathParam("noteId") String noteId)
|
||||
throws IOException {
|
||||
LOG.info("clear all paragraph output of note {}", noteId);
|
||||
|
||||
if (!noteId.isEmpty()) {
|
||||
Note note = notebook.getNote(noteId);
|
||||
if (note == null) {
|
||||
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
|
||||
}
|
||||
note.clearAllParagraphOutput();
|
||||
}
|
||||
|
||||
return new JsonResponse(Status.OK, "").build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run note jobs REST API
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,15 +18,14 @@
|
|||
package org.apache.zeppelin.rest;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.PutMethod;
|
||||
import org.apache.zeppelin.interpreter.InterpreterResult;
|
||||
import org.apache.zeppelin.notebook.Note;
|
||||
import org.apache.zeppelin.notebook.NotebookAuthorization;
|
||||
import org.apache.zeppelin.notebook.NotebookAuthorizationInfoSaving;
|
||||
import org.apache.zeppelin.notebook.Paragraph;
|
||||
import org.apache.zeppelin.server.ZeppelinServer;
|
||||
import org.apache.zeppelin.user.AuthenticationInfo;
|
||||
import org.junit.AfterClass;
|
||||
|
|
@ -37,12 +36,12 @@ import org.junit.Test;
|
|||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
|
|
@ -179,6 +178,43 @@ public class NotebookRestApiTest extends AbstractTestRestApi {
|
|||
ZeppelinServer.notebook.removeNote(clonedNoteId, anonymous);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearAllParagraphOutput() throws IOException {
|
||||
// Create note and set result explicitly
|
||||
Note note = ZeppelinServer.notebook.createNote(anonymous);
|
||||
Paragraph p1 = note.addParagraph();
|
||||
InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TEXT, "result");
|
||||
p1.setResult(result);
|
||||
|
||||
Paragraph p2 = note.addParagraph();
|
||||
p2.setReturn(result, new Throwable());
|
||||
|
||||
// clear paragraph result
|
||||
PostMethod post = httpPost("/notebook/" + note.getId() + "/clear", "");
|
||||
LOG.info("test clear paragraph output response\n" + post.getResponseBodyAsString());
|
||||
assertThat(post, isAllowed());
|
||||
post.releaseConnection();
|
||||
|
||||
// check if paragraph results are cleared
|
||||
GetMethod get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p1.getId());
|
||||
assertThat(get, isAllowed());
|
||||
Map<String, Object> resp1 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
Map<String, Object> resp1Body = (Map<String, Object>) resp1.get("body");
|
||||
assertNull(resp1Body.get("result"));
|
||||
|
||||
get = httpGet("/notebook/" + note.getId() + "/paragraph/" + p2.getId());
|
||||
assertThat(get, isAllowed());
|
||||
Map<String, Object> resp2 = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
Map<String, Object> resp2Body = (Map<String, Object>) resp2.get("body");
|
||||
assertNull(resp2Body.get("result"));
|
||||
get.releaseConnection();
|
||||
|
||||
//cleanup
|
||||
ZeppelinServer.notebook.removeNote(note.getId(), anonymous);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue