Explorar o código

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

Pallav Kulshreshtha %!s(int64=9) %!d(string=hai) anos
pai
achega
cef562f22f

+ 11 - 5
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;
   }

+ 3 - 0
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>
 

+ 0 - 2
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>

+ 2 - 4
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;
   }