DRILL-7849: Display error message when cannot enable storage plugin
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
index 1ed9128..1e3b640 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
@@ -154,8 +154,9 @@
         model);
   }
 
-  @GET
+  @POST
   @Path("/storage/{name}/enable/{val}")
+  @Consumes(MediaType.APPLICATION_JSON)
   @Produces(MediaType.APPLICATION_JSON)
   public JsonResult enablePlugin(@PathParam("name") String name, @PathParam("val") Boolean enable) {
     try {
@@ -170,6 +171,17 @@
   }
 
   /**
+   * @deprecated use the method with POST request {@link #enablePlugin} instead
+   */
+  @GET
+  @Path("/storage/{name}/enable/{val}")
+  @Produces(MediaType.APPLICATION_JSON)
+  @Deprecated
+  public JsonResult enablePluginViaGet(@PathParam("name") String name, @PathParam("val") Boolean enable) {
+    return enablePlugin(name, enable);
+  }
+
+  /**
    * Regex allows the following paths:
    * /storage/{name}/export
    * "/storage/{name}/export/{format}
diff --git a/exec/java-exec/src/main/resources/rest/alertModals.ftl b/exec/java-exec/src/main/resources/rest/alertModals.ftl
index 74d4565..6869d53 100644
--- a/exec/java-exec/src/main/resources/rest/alertModals.ftl
+++ b/exec/java-exec/src/main/resources/rest/alertModals.ftl
@@ -48,26 +48,29 @@
 <script>
     //Populate the alert modal with the right message params and show
     function populateAndShowAlert(errorMsg, inputValues) {
+      let errorModal=$('#errorModal');
+      let title;
+      let body;
       if (!(errorMsg in errorMap)) {
         //Using default errorId to represent message
-        modalHeader.innerHTML=errorMsg;
-        modalBody.innerHTML="[Auto Description] "+JSON.stringify(inputValues);
+        title=errorMsg;
+        body="[Auto Description] "+JSON.stringify(inputValues);
       } else {
-        modalHeader.innerHTML=errorMap[errorMsg].msgHeader;
-        modalBody.innerHTML=errorMap[errorMsg].msgBody;
+        title=errorMap[errorMsg].msgHeader;
+        body=errorMap[errorMsg].msgBody;
       }
       //Check if substitutions are needed
-      let updatedHtml=modalBody.innerHTML;
       if (inputValues != null) {
-        var inputValuesKeys = Object.keys(inputValues);
+        let inputValuesKeys = Object.keys(inputValues);
         for (i=0; i<inputValuesKeys.length; ++i) {
-            let currKey=inputValuesKeys[i];
-            updatedHtml=updatedHtml.replace(currKey, escapeHtml(inputValues[currKey]));
+          let currKey=inputValuesKeys[i];
+          body=body.replace(currKey, escapeHtml(inputValues[currKey]));
         }
-        modalBody.innerHTML=updatedHtml;
       }
+      errorModal.find('.modal-title').text(title);
+      errorModal.find('.modal-body').html(body);
       //Show Alert
-      $('#errorModal').modal('show');
+      errorModal.modal('show');
     }
 
     function escapeHtml(str) {
@@ -105,9 +108,13 @@
             msgHeader:"   ERROR: No Query to execute",
             msgBody:"Please provide a query. The query textbox cannot be empty."
         },
+        "pluginEnablingFailure": {
+            msgHeader:"   ERROR: Unable to enable/disable plugin",
+            msgBody:"<span style='font-family:courier;white-space:pre'>_pluginName_</span>: _errorMessage_"
+        },
         "errorId": {
             msgHeader:"~header~",
             msgBody:"Description unavailable"
         }
     }
-</script>
\ No newline at end of file
+</script>
diff --git a/exec/java-exec/src/main/resources/rest/confirmationModals.ftl b/exec/java-exec/src/main/resources/rest/confirmationModals.ftl
index 5df8057..8801781 100644
--- a/exec/java-exec/src/main/resources/rest/confirmationModals.ftl
+++ b/exec/java-exec/src/main/resources/rest/confirmationModals.ftl
@@ -44,9 +44,10 @@
 <script>
     //Populate the confirmation modal with the right message params and show
     function showConfirmationDialog(confirmationMessage, okCallback) {
-      modalBody.innerHTML = confirmationMessage;
+      let confirmationModal = $('#confirmationModal');
+      confirmationModal.find('.modal-body').html(confirmationMessage);
       //Show dialog
-      $('#confirmationModal').modal('show');
+      confirmationModal.modal('show');
       $('#confirmationOk').unbind('click')
           .click(okCallback);
       $('#confirmationCancel').focus();
diff --git a/exec/java-exec/src/main/resources/rest/static/js/serverMessage.js b/exec/java-exec/src/main/resources/rest/static/js/serverMessage.js
index 6c47592..d426f25 100644
--- a/exec/java-exec/src/main/resources/rest/static/js/serverMessage.js
+++ b/exec/java-exec/src/main/resources/rest/static/js/serverMessage.js
@@ -20,6 +20,7 @@
             .addClass("alert-info")
             .text(data.result).alert();
         setTimeout(function() { window.location.href = "/storage"; }, 800);
+        return true;
     } else {
         messageEl.addClass("d-none");
         // Wait a fraction of a second before showing the message again. This
@@ -31,5 +32,6 @@
                 .addClass("alert-danger")
                 .text("Please retry: " + data.result).alert();
         }, 200);
+        return false;
     }
 }
diff --git a/exec/java-exec/src/main/resources/rest/storage/list.ftl b/exec/java-exec/src/main/resources/rest/storage/list.ftl
index 52b70ab..5d4b6ae 100644
--- a/exec/java-exec/src/main/resources/rest/storage/list.ftl
+++ b/exec/java-exec/src/main/resources/rest/storage/list.ftl
@@ -210,8 +210,12 @@
         showConfirmationDialog('"' + name + '"' + ' plugin will be disabled. Proceed?', proceed);
       }
       function proceed() {
-        $.get("/storage/" + encodeURIComponent(name) + "/enable/" + flag, function() {
-          location.reload();
+        $.post("/storage/" + encodeURIComponent(name) + "/enable/" + flag, function(data) {
+          if (data.result === "Success") {
+            location.reload();
+          } else {
+              populateAndShowAlert('pluginEnablingFailure', {'_pluginName_': name,'_errorMessage_': data.result});
+          }
         });
       }
     }
@@ -290,6 +294,7 @@
       });
     });
   </script>
+  <#include "*/alertModals.ftl">
 </#macro>
 
 <@page_html/>
\ No newline at end of file
diff --git a/exec/java-exec/src/main/resources/rest/storage/update.ftl b/exec/java-exec/src/main/resources/rest/storage/update.ftl
index 851d2ef..224eb52 100644
--- a/exec/java-exec/src/main/resources/rest/storage/update.ftl
+++ b/exec/java-exec/src/main/resources/rest/storage/update.ftl
@@ -121,9 +121,10 @@
         proceed();
       }
       function proceed() {
-        $.get("/storage/" + encodeURIComponent("${model.getPlugin().getName()}") + "/enable/<#if model.getPlugin().enabled()>false<#else>true</#if>", function(data) {
-          $("#message").removeClass("d-none").text(data.result).alert();
-          setTimeout(function() { location.reload(); }, 800);
+        $.post("/storage/" + encodeURIComponent("${model.getPlugin().getName()}") + "/enable/" + !enabled, function(data) {
+          if (serverMessage(data)) {
+              setTimeout(function() { location.reload(); }, 800);
+          }
         });
       }
     });