This is an automated email from the ASF dual-hosted git repository. madhan pushed a commit to branch ranger-2.4 in repository https://gitbox.apache.org/repos/asf/ranger.git
commit 92010c2ba8a46af278c95efb10a5de9bd32d471a Author: Kishor Gollapalliwar <[email protected]> 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 <[email protected]> (cherry picked from commit 2a057768fc6a345fce013a89c72d5d67d0df666d) --- .../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 5d14f41ea..41b1504a8 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 @@ -606,6 +606,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" }) @@ -614,18 +619,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) { @@ -642,6 +649,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) @Consumes({ "application/json" })
