You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by me...@apache.org on 2022/06/08 11:41:19 UTC

[ranger] 02/02: RANGER-3740: Ranger- Add an API to refresh tag cache -- follow-up patch

This is an automated email from the ASF dual-hosted git repository.

mehul pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git

commit 2a057768fc6a345fce013a89c72d5d67d0df666d
Author: Kishor Gollapalliwar <ki...@gmail.com>
AuthorDate: Tue May 31 16:43:04 2022 +0530

    RANGER-3740: Ranger- Add an API to refresh tag cache -- follow-up patch
    
    Signed-off-by: Mehul Parikh <me...@apache.org>
---
 .../main/java/org/apache/ranger/rest/TagREST.java  | 47 ++++++++++++++++++----
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/security-admin/src/main/java/org/apache/ranger/rest/TagREST.java b/security-admin/src/main/java/org/apache/ranger/rest/TagREST.java
index 79dbdc76d..01df04e3f 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/TagREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/TagREST.java
@@ -602,6 +602,11 @@ public class TagREST {
         return ret;
     }
 
+    /**
+     * Resets/ removes tag policy cache for given service.
+     * @param serviceName non-empty service-name
+     * @return {@code true} if successfully reseted/ removed for given service, {@code false} otherwise.
+     */
     @GET
     @Path(TagRESTConstants.TAGS_RESOURCE + "cache/reset")
     @Produces({ "application/json", "application/xml" })
@@ -610,18 +615,20 @@ public class TagREST {
             LOG.debug("==> TagREST.resetTagCache({})", serviceName);
         }
 
+        if (StringUtils.isEmpty(serviceName)) {
+            throw restErrorUtil.createRESTException("Required parameter [serviceName] is missing.", MessageEnums.INVALID_INPUT_DATA);
+        }
+
         // check for ADMIN access
         if (!bizUtil.isAdmin()) {
             boolean isServiceAdmin = false;
             String  loggedInUser   = bizUtil.getCurrentUserLoginId();
 
-            if (StringUtils.isNotEmpty(serviceName)) {
-                try {
-                    RangerService rangerService = svcStore.getServiceByName(serviceName);
-                    isServiceAdmin = bizUtil.isUserServiceAdmin(rangerService, loggedInUser);
-                } catch (Exception e) {
-                    LOG.warn("Failed to find if user [" + loggedInUser + "] has service admin privileges on service [" + serviceName + "]", e);
-                }
+            try {
+                RangerService rangerService = svcStore.getServiceByName(serviceName);
+                isServiceAdmin = bizUtil.isUserServiceAdmin(rangerService, loggedInUser);
+            } catch (Exception e) {
+                LOG.warn("Failed to find if user [" + loggedInUser + "] has service admin privileges on service [" + serviceName + "]", e);
             }
 
             if (!isServiceAdmin) {
@@ -638,6 +645,32 @@ public class TagREST {
         return ret;
     }
 
+    /**
+     * Resets/ removes tag policy cache for all.
+     * @return {@code true} if successfully reseted/ removed, {@code false} otherwise.
+     */
+    @GET
+    @Path(TagRESTConstants.TAGS_RESOURCE + "cache/reset-all")
+    @Produces({ "application/json", "application/xml" })
+    public boolean resetTagCacheAll() {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("==> TagREST.resetTagCacheAll()");
+        }
+
+        // check for ADMIN access
+        if (!bizUtil.isAdmin()) {
+            throw restErrorUtil.createRESTException("User cannot reset policy cache", MessageEnums.OPER_NO_PERMISSION);
+        }
+
+        boolean ret = tagStore.resetTagCache(null);
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("<== TagREST.resetTagCacheAll(): ret={}", ret);
+        }
+
+        return ret;
+    }
+
     @POST
     @Path(TagRESTConstants.RESOURCES_RESOURCE)
     @Produces({ "application/json", "application/xml" })