DRILL-6303: Provide a button to copy the Drillbit's JStack shown in /threads

Provides a button in the web UI to copy the thread stack to the user's 
clipboard.

closes #1199


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/2e1568ce
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/2e1568ce
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/2e1568ce

Branch: refs/heads/master
Commit: 2e1568cecd4aafb87c092c6b403a60366cc8f107
Parents: cc440af
Author: Kunal Khatua <kkha...@maprtech.com>
Authored: Sun Mar 25 23:09:43 2018 -0700
Committer: Arina Ielchiieva <arina.yelchiy...@gmail.com>
Committed: Fri Apr 6 11:54:46 2018 +0300

----------------------------------------------------------------------
 .../src/main/resources/rest/threads/threads.ftl | 27 ++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/2e1568ce/exec/java-exec/src/main/resources/rest/threads/threads.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/threads/threads.ftl 
b/exec/java-exec/src/main/resources/rest/threads/threads.ftl
index e393164..14d22f2 100644
--- a/exec/java-exec/src/main/resources/rest/threads/threads.ftl
+++ b/exec/java-exec/src/main/resources/rest/threads/threads.ftl
@@ -17,18 +17,41 @@
   <a href="/queries">back</a><br/>
   <div class="page-header">
   </div>
+  <p align="right">Auto Refresh <span class="badge badge-pill badge-info" 
id="refreshTimeLabel"></span>
+    <button id="clippy" type="button" class="btn btn-default btn-sm" 
onClick="copyThreads();" title="Copy To Clipboard"> 
+      <!-- Refer: https://glyphicons.bootstrapcheatsheets.com/# for correct 
rendering -->
+      <span class="glyphicon glyphicon-copy" 
style="font-size:180%">&#xe205;</span>
+    </button>
+  </p>
   <div id="mainDiv" role="main">
   </div>
   </div>
   <script>
+    var statusUrl = location.protocol + "//" + location.host + 
"/status/threads";
+    var refreshInterval = 3;
+    document.getElementById('refreshTimeLabel').innerHTML = refreshInterval+" 
sec"; 
     var update = function() {
-      $.get("/status/threads", function(data) {
+      $.get(statusUrl, function(data) {
         $("#mainDiv").html("<pre>" + data + "</pre>");
       });
     };
 
+    //Ref: https://stackoverflow.com/a/36640126/8323038
+    function copyThreads() {
+      if (document.selection) { 
+        var range = document.body.createTextRange();
+        range.moveToElementText(document.getElementById("mainDiv"));
+        range.select().createTextRange();
+        document.execCommand("copy");
+      } else if (window.getSelection) {
+        var range = document.createRange();
+        range.selectNode(document.getElementById("mainDiv"));
+        window.getSelection().addRange(range);
+        document.execCommand("copy");
+      }
+    }
     update();
-    setInterval(update, 2000);
+    setInterval(update, refreshInterval*1000);
   </script>
 </#macro>
 

Reply via email to