Skip to content

Commit

Permalink
DRILL-7922: Add feature of viewing external profile in web UI (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon-WTF authored and luocooong committed Jul 18, 2021
1 parent 512ac6c commit d71864a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
Expand Down Expand Up @@ -57,11 +59,14 @@
import org.apache.drill.exec.store.sys.PersistentStoreProvider;
import org.apache.drill.exec.work.WorkManager;
import org.apache.drill.exec.work.foreman.Foreman;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.glassfish.jersey.server.mvc.Viewable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.drill.shaded.guava.com.google.common.base.Joiner;
import org.apache.drill.shaded.guava.com.google.common.collect.Lists;
import org.apache.drill.shaded.guava.com.google.common.cache.Cache;
import org.apache.drill.shaded.guava.com.google.common.cache.CacheBuilder;

@Path("/")
@RolesAllowed(DrillUserPrincipal.AUTHENTICATED_ROLE)
Expand Down Expand Up @@ -244,6 +249,9 @@ public String getQueriesPerPage() {
//max Param to cap listing of profiles
private static final String MAX_QPROFILES_PARAM = "max";

private static final Cache<String, String> PROFILE_CACHE = CacheBuilder
.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES).build();

@GET
@Path("/profiles.json")
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -375,7 +383,14 @@ private QueryProfile getQueryProfile(String queryId) {
@Produces(MediaType.APPLICATION_JSON)
public String getProfileJSON(@PathParam("queryid") String queryId) {
try {
return new String(work.getContext().getProfileStoreContext().getProfileStoreConfig().getSerializer().serialize(getQueryProfile(queryId)));
String profileData = PROFILE_CACHE.getIfPresent(queryId);
if (profileData == null) {
return new String(work.getContext().getProfileStoreContext()
.getProfileStoreConfig().getSerializer().serialize(getQueryProfile(queryId)));
} else {
PROFILE_CACHE.invalidate(queryId);
return profileData;
}
} catch (Exception e) {
logger.debug("Failed to serialize profile for: " + queryId);
return ("{ 'message' : 'error (unable to serialize profile)' }");
Expand All @@ -395,6 +410,27 @@ public Viewable getProfile(@PathParam("queryid") String queryId){
}
}

@POST
@Path("/profiles/view")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
public Viewable viewProfile(@FormDataParam("profileData") String content) {
try {
QueryProfile profile = work.getContext().getProfileStoreContext()
.getProfileStoreConfig().getSerializer().deserialize(content.getBytes());
PROFILE_CACHE.put(profile.getQueryId(), content);
ProfileWrapper wrapper = new ProfileWrapper(profile,
work.getContext().getConfig(), request);
return ViewableWithPermissions.create(authEnabled.get(),
"/rest/profile/profile.ftl", sc, wrapper);
} catch (Exception | Error e) {
logger.error("Exception was thrown when parsing profile {} :\n{}",
content, e);
return ViewableWithPermissions.create(authEnabled.get(),
"/rest/errorMessage.ftl", sc, e);
}
}

@GET
@Path("/profiles/cancel/{queryid}")
@Produces(MediaType.TEXT_PLAIN)
Expand Down
13 changes: 13 additions & 0 deletions exec/java-exec/src/main/resources/rest/profile/list.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
$("#queryCancelModal").modal("show");
}
//Trigger the click event of file input and submit the file selected to the server
function viewProfile() {
$("#view-profile-file").change(function() {
$("#view-profile").submit();
this.value = null;
});
$("#view-profile-file").trigger("click");
}
</script>

<!-- CSS to control DataTable Elements -->
Expand Down Expand Up @@ -173,6 +181,11 @@
<input id="fetchMax" type="text" size="5" name="max" value="" style="text-align: right" />
<input type="submit" value="Reload"/>
</form></td>
<td align="right" width="1px">
<form id="view-profile" action="/profiles/view" enctype='multipart/form-data' method="post">
<input type="file" id="view-profile-file" name="profileData" style="display: none"/>
<input type="button" value="View" onclick = "viewProfile()"/>
</form></td>
</tr></table>
<!-- Placed after textbox to allow for DOM to contain "fetchMax" element -->
<script type="text/javascript" language="javascript">
Expand Down

0 comments on commit d71864a

Please sign in to comment.