diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java index cb50a8a9a7..373ca265ec 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/InterpreterRestApi.java @@ -80,6 +80,28 @@ public class InterpreterRestApi { return new JsonResponse<>(Status.OK, "", interpreterFactory.get()).build(); } + + /** + * Get a setting + */ + @GET + @Path("setting/{settingId}") + @ZeppelinApi + public Response getSetting(@PathParam("settingId") String settingId) { + try { + InterpreterSetting setting = interpreterFactory.get(settingId); + if (setting == null) { + return new JsonResponse<>(Status.NOT_FOUND).build(); + } else { + return new JsonResponse<>(Status.OK, "", setting).build(); + } + } catch (NullPointerException e){ + logger.error("Exception in InterpreterRestApi while creating ", e); + return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), + ExceptionUtils.getStackTrace(e)) .build(); + } + } + /** * Add new interpreter setting * 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 ada6c070cf..dbc1449970 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 @@ -21,6 +21,8 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; @@ -93,6 +95,17 @@ public class InterpreterRestApiTest extends AbstractTestRestApi { get.releaseConnection(); } + @Test + public void testGetNonExistInterpreterSetting() throws IOException { + // when + String nonExistInterpreterSettingId = "apache_.zeppelin_1s_.aw3some$"; + GetMethod get = httpGet("/interpreter/setting/" + nonExistInterpreterSettingId); + get.releaseConnection(); + + // when + assertThat("Test get method:", get, isNotFound()); + } + @Test public void testSettingsCRUD() throws IOException { // Call Create Setting REST API @@ -111,6 +124,18 @@ public class InterpreterRestApiTest extends AbstractTestRestApi { String newSettingId = body.toString().split(",")[0].split("=")[1]; post.releaseConnection(); + // Call Read Setting API + GetMethod get = httpGet("/interpreter/setting/" + newSettingId); + String rawResponse = get.getResponseBodyAsString(); + LOG.info("testSettingCRUD get response\n" + rawResponse); + get.releaseConnection(); + JsonObject response = gson.fromJson(rawResponse, JsonElement.class) + .getAsJsonObject(); + assertThat("Test get method:", get, isAllowed()); + InterpreterSetting created = gson.fromJson(response.getAsJsonObject("body"), + InterpreterSetting.class); + assertEquals(newSettingId, created.getId()); + // Call Update Setting REST API jsonRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"Otherpropvalue\"}," + "\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," +