[ZEPPELIN-2714] Soft-code Spark UI button visualization

This commit is contained in:
Nelson Costa 2017-06-30 10:17:59 +01:00
parent 155a55b560
commit a85864c016
5 changed files with 81 additions and 39 deletions

View file

@ -604,3 +604,26 @@ The role of registered interpreters, settings and interpreters group are describ
</td>
</table>
<br/>
### Get interpreter settings metadata info
<table class="table-configuration">
<col width="200">
<tr>
<td>Description</td>
<td>This ```GET``` method returns interpreter settings metadata info. </td>
</tr>
<tr>
<td>URL</td>
<td>```http://[zeppelin-server]:[zeppelin-port]/api/interpreter/getmetainfos/[setting ID]```</td>
</tr>
<tr>
<td>Success code</td>
<td>200</td>
</tr>
<tr>
<td>Fail code</td>
<td> 500 </td>
</tr>
</table>

View file

@ -184,11 +184,12 @@ public class SparkInterpreter extends Interpreter {
super.onJobStart(jobStart);
int jobId = jobStart.jobId();
String jobGroupId = jobStart.properties().getProperty("spark.jobGroup.id");
String uiEnabled = jobStart.properties().getProperty("spark.ui.enabled");
String jobUrl = getJobUrl(jobId);
String noteId = Utils.getNoteId(jobGroupId);
String paragraphId = Utils.getParagraphId(jobGroupId);
if (jobUrl != null && noteId != null && paragraphId != null) {
if (uiEnabled != "false" && jobUrl != null) {
RemoteEventClientWrapper eventClient = BaseZeppelinContext.getEventClient();
Map<String, String> infos = new java.util.HashMap<>();
infos.put("jobUrl", jobUrl);
@ -1040,21 +1041,20 @@ public class SparkInterpreter extends Interpreter {
}
public void populateSparkWebUrl(InterpreterContext ctx) {
if (sparkUrl == null) {
sparkUrl = getSparkUIUrl();
Map<String, String> infos = new java.util.HashMap<>();
if (sparkUrl != null) {
infos.put("url", sparkUrl);
if (ctx != null && ctx.getClient() != null) {
logger.info("Sending metainfos to Zeppelin server: {}", infos.toString());
getZeppelinContext().setEventClient(ctx.getClient());
ctx.getClient().onMetaInfosReceived(infos);
}
}
sparkUrl = getSparkUIUrl();
Map<String, String> infos = new java.util.HashMap<>();
infos.put("url", sparkUrl);
java.lang.Boolean uiEnabled = java.lang.Boolean.parseBoolean(
property.getProperty("spark.ui.enabled", "true"));
infos.put("sparkUiEnabled", uiEnabled.toString());
if (ctx != null && ctx.getClient() != null) {
logger.info("Sending metainfos to Zeppelin server: {}", infos.toString());
getZeppelinContext().setEventClient(ctx.getClient());
ctx.getClient().onMetaInfosReceived(infos);
}
}
public List<File> currentClassPath() {
private List<File> currentClassPath() {
List<File> paths = classPath(Thread.currentThread().getContextClassLoader());
String[] cps = System.getProperty("java.class.path").split(File.pathSeparator);
if (cps != null) {

View file

@ -250,24 +250,15 @@ public class InterpreterRestApi {
*/
@GET
@Path("getmetainfos/{settingId}")
@ZeppelinApi
public Response getMetaInfo(@Context HttpServletRequest req,
@PathParam("settingId") String settingId) {
String propName = req.getParameter("propName");
if (propName == null) {
return new JsonResponse<>(Status.BAD_REQUEST).build();
}
String propValue = null;
InterpreterSetting interpreterSetting = interpreterSettingManager.get(settingId);
Map<String, String> infos = interpreterSetting.getInfos();
if (infos != null) {
propValue = infos.get(propName);
if (interpreterSetting == null) {
return new JsonResponse<>(Status.NOT_FOUND).build();
}
Map<String, String> respMap = new HashMap<>();
respMap.put(propName, propValue);
logger.debug("Get meta info");
logger.debug("Interpretersetting Id: {}, property Name:{}, property value: {}", settingId,
propName, propValue);
return new JsonResponse<>(Status.OK, respMap).build();
Map<String, String> infos = interpreterSetting.getInfos();
return new JsonResponse<>(Status.OK, "metainfo", infos).build();
}
/**

View file

@ -26,6 +26,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
@ -55,7 +56,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class InterpreterRestApiTest extends AbstractTestRestApi {
Gson gson = new Gson();
AuthenticationInfo anonymous;
private AuthenticationInfo anonymous;
@BeforeClass
public static void init() throws Exception {
@ -365,21 +366,43 @@ public class InterpreterRestApiTest extends AbstractTestRestApi {
delete.releaseConnection();
}
public JsonObject getBodyFieldFromResponse(String rawResponse) {
@Test
public void testGetMetaInfo() throws IOException {
String rawRequest = "{\"name\":\"spark\",\"group\":\"spark\"," +
"\"properties\":{\"propname\":\"propvalue\"}," +
"\"interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]," +
"\"dependencies\":[]," +
"\"option\": { \"remote\": true, \"session\": false }}";
JsonObject jsonRequest = gson.fromJson(rawRequest, JsonElement.class).getAsJsonObject();
PostMethod post = httpPost("/interpreter/setting/", jsonRequest.toString());
InterpreterSetting created = convertResponseToInterpreterSetting(post.getResponseBodyAsString());
String settingId = created.getId();
Map<String, String> infos = new java.util.HashMap<>();
infos.put("key1", "value1");
infos.put("key2", "value2");
ZeppelinServer.notebook.getInterpreterSettingManager().get(settingId).setInfos(infos);
GetMethod get = httpGet("/interpreter/getmetainfos/" + settingId);
assertThat(get, isAllowed());
JsonObject body = getBodyFieldFromResponse(get.getResponseBodyAsString());
assertEquals(body.entrySet().size(), infos.size());
get.releaseConnection();
}
private JsonObject getBodyFieldFromResponse(String rawResponse) {
JsonObject response = gson.fromJson(rawResponse, JsonElement.class).getAsJsonObject();
return response.getAsJsonObject("body");
}
public JsonArray getArrayBodyFieldFromResponse(String rawResponse) {
private JsonArray getArrayBodyFieldFromResponse(String rawResponse) {
JsonObject response = gson.fromJson(rawResponse, JsonElement.class).getAsJsonObject();
return response.getAsJsonArray("body");
}
public InterpreterSetting convertResponseToInterpreterSetting(String rawResponse) {
private InterpreterSetting convertResponseToInterpreterSetting(String rawResponse) {
return gson.fromJson(getBodyFieldFromResponse(rawResponse), InterpreterSetting.class);
}
public static String getSimulatedMarkdownResult(String markdown) {
private static String getSimulatedMarkdownResult(String markdown) {
return String.format("<div class=\"markdown-body\">\n<p>%s</p>\n</div>", markdown);
}
}

View file

@ -754,16 +754,21 @@ function InterpreterCtrl($rootScope, $scope, $http, baseUrlSrv, ngToast, $timeou
}
$scope.showSparkUI = function (settingId) {
$http.get(baseUrlSrv.getRestApiBase() + '/interpreter/getmetainfos/' + settingId + '?propName=url')
$http.get(baseUrlSrv.getRestApiBase() + '/interpreter/getmetainfos/' + settingId)
.success(function (data, status, headers, config) {
let url = data.body.url
if (!url) {
BootstrapDialog.alert({
message: 'No spark application running'
})
if (data.body === undefined || !data.body.url) {
if (data.body !== undefined && data.body.sparkUiEnabled === 'false') {
BootstrapDialog.alert({
message: 'Spark Web UI disabled. Set spark.ui.enabled property'
})
} else {
BootstrapDialog.alert({
message: 'No spark application running'
})
}
return
}
window.open(url, '_blank')
window.open(data.body.url, '_blank')
}).error(function (data, status, headers, config) {
console.log('Error %o %o', status, data.message)
})