You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by pa...@apache.org on 2016/06/08 13:00:05 UTC

ambari git commit: AMBARI-17055. Show better error message when VIEW USER can not access CAPACITY SCHEDULER View. (Gaurav Nagar via pallavkul)

Repository: ambari
Updated Branches:
  refs/heads/trunk 5276ffef8 -> 20b817f10


AMBARI-17055. Show better error message when VIEW USER can not access CAPACITY SCHEDULER View. (Gaurav Nagar via pallavkul)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/20b817f1
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/20b817f1
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/20b817f1

Branch: refs/heads/trunk
Commit: 20b817f10ebc4b99093b4829534b6fc7d23e5ddc
Parents: 5276ffe
Author: Pallav Kulshreshtha <pa...@gmail.com>
Authored: Wed Jun 8 18:29:21 2016 +0530
Committer: Pallav Kulshreshtha <pa...@gmail.com>
Committed: Wed Jun 8 18:29:21 2016 +0530

----------------------------------------------------------------------
 .../capacityscheduler/ConfigurationService.java     | 16 +++++++++++-----
 .../src/main/resources/ui/app/templates/queues.hbs  |  3 +++
 .../resources/ui/app/templates/queues/index.hbs     |  2 --
 .../apache/ambari/view/utils/ambari/AmbariApi.java  |  6 ++----
 4 files changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/20b817f1/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java b/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java
index 42076fe..2198331 100644
--- a/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java
+++ b/contrib/views/capacity-scheduler/src/main/java/org/apache/ambari/view/capacityscheduler/ConfigurationService.java
@@ -144,6 +144,12 @@ public class ConfigurationService {
     try {
       JSONObject configurations = readFromCluster("");
       response = Response.ok(configurations).build();
+    } catch (AmbariHttpException ex) {
+      if (ex.getResponseCode() == 403) {
+        throw new ServiceFormattedException("You do not have permission to view Capacity Scheduler configuration. Contact your Cluster administrator", ex);
+      } else {
+        throw new ServiceFormattedException(ex.getMessage(), ex);
+      }
     } catch (WebApplicationException ex) {
       throw ex;
     } catch (Exception ex) {
@@ -279,7 +285,7 @@ public class ConfigurationService {
     return false;
   }
 
-  private JSONObject readFromCluster(String url) {
+  private JSONObject readFromCluster(String url) throws AmbariHttpException {
     String response = ambariApi.requestClusterAPI(url);
     if (response == null || response.isEmpty()) {
       return null;
@@ -308,7 +314,7 @@ public class ConfigurationService {
     return jsonObject;
   }
 
-  private JSONObject getConfigurationFromAmbari(String versionTag) {
+  private JSONObject getConfigurationFromAmbari(String versionTag) throws AmbariHttpException {
     String url = String.format(CONFIGURATION_URL_BY_TAG, versionTag);
     JSONObject responseJSON = readFromCluster(url);
     return  responseJSON;
@@ -319,7 +325,7 @@ public class ConfigurationService {
    *
    * @return    the capacity scheduler version tag
    */
-  private String getVersionTag() {
+  private String getVersionTag() throws AmbariHttpException {
     JSONObject json = getDesiredConfigs();
     JSONObject clusters = (JSONObject) json.get("Clusters");
     JSONObject configs = (JSONObject) clusters.get("desired_configs");
@@ -332,7 +338,7 @@ public class ConfigurationService {
    *
    * @return    the cluster name
    */
-  private String getClusterName() {
+  private String getClusterName() throws AmbariHttpException {
     JSONObject json = getDesiredConfigs();
     JSONObject clusters = (JSONObject) json.get("Clusters");
     return (String) clusters.get("cluster_name");
@@ -343,7 +349,7 @@ public class ConfigurationService {
    *
    * @return  the desired config JSON object
    */
-  private JSONObject getDesiredConfigs() {
+  private JSONObject getDesiredConfigs() throws AmbariHttpException {
     JSONObject response = readFromCluster(VERSION_TAG_URL);
     return response;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/20b817f1/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues.hbs b/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues.hbs
index 94cb421..d2e7ff5 100644
--- a/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues.hbs
+++ b/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues.hbs
@@ -113,6 +113,9 @@
 
 {{!-- QUEUE --}}
 <div class="col-md-8 queue-area">
+  {{#unless isOperator}}
+    <div class="alert alert-warning"><strong>Warning!</strong> You do not have permission to edit the Capacity Scheduler configuration. Contact your Cluster administrator.</div>
+  {{/unless}}
   {{outlet}}
 </div>
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/20b817f1/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues/index.hbs
----------------------------------------------------------------------
diff --git a/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues/index.hbs b/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues/index.hbs
index 1c468b5..3578d5a 100644
--- a/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues/index.hbs
+++ b/contrib/views/capacity-scheduler/src/main/resources/ui/app/templates/queues/index.hbs
@@ -15,6 +15,4 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 }}
-
-
 <div class="alert alert-info">Click on a queue to the left for details.</div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/20b817f1/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/AmbariApi.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/AmbariApi.java b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/AmbariApi.java
index 86d8434..cb6d6b0 100644
--- a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/AmbariApi.java
+++ b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/AmbariApi.java
@@ -73,7 +73,7 @@ public class AmbariApi {
    * @return response
    * @throws AmbariApiException
    */
-  public String requestClusterAPI(String path) throws AmbariApiException {
+  public String requestClusterAPI(String path) throws AmbariApiException, AmbariHttpException {
     return requestClusterAPI(path, "GET", null, null);
   }
 
@@ -86,7 +86,7 @@ public class AmbariApi {
    * @return response
    * @throws AmbariApiException IO error or not associated with cluster
    */
-  public String requestClusterAPI(String path, String method, String data, Map<String, String> headers) throws AmbariApiException {
+  public String requestClusterAPI(String path, String method, String data, Map<String, String> headers) throws AmbariApiException, AmbariHttpException {
     String response;
 
     try {
@@ -104,8 +104,6 @@ public class AmbariApi {
       response = IOUtils.toString(inputStream);
     } catch (IOException e) {
       throw new AmbariApiException("RA040 I/O error while requesting Ambari", e);
-    } catch (AmbariHttpException e) {
-      throw new AmbariApiException("RA040 Request to Ambari is unsuccessful with response code "+e.getResponseCode(), e);
     }
     return response;
   }