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

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


The following commit(s) were added to refs/heads/master by this push:
     new af3252c54 RANGER-4695: updated API to find zones for a resource to 
handle deleted services
af3252c54 is described below

commit af3252c54d1b7728bcb132c71a4dfe0c14bdaf77
Author: Madhan Neethiraj <[email protected]>
AuthorDate: Thu Feb 8 02:41:36 2024 -0800

    RANGER-4695: updated API to find zones for a resource to handle deleted 
services
---
 .../org/apache/ranger/plugin/store/ServiceStore.java  |  2 ++
 .../org/apache/ranger/biz/RangerPolicyAdminCache.java | 14 ++++++++++++++
 .../java/org/apache/ranger/biz/ServiceDBStore.java    | 19 +++++++++++++++++++
 3 files changed, 35 insertions(+)

diff --git 
a/agents-common/src/main/java/org/apache/ranger/plugin/store/ServiceStore.java 
b/agents-common/src/main/java/org/apache/ranger/plugin/store/ServiceStore.java
index 8ad3e12c8..97072391e 100644
--- 
a/agents-common/src/main/java/org/apache/ranger/plugin/store/ServiceStore.java
+++ 
b/agents-common/src/main/java/org/apache/ranger/plugin/store/ServiceStore.java
@@ -59,6 +59,8 @@ public interface ServiceStore {
 
        void deleteService(Long id) throws Exception;
 
+       boolean serviceExists(String name) throws Exception;
+
        RangerService getService(Long id) throws Exception;
 
        RangerService getServiceByName(String name) throws Exception;
diff --git 
a/security-admin/src/main/java/org/apache/ranger/biz/RangerPolicyAdminCache.java
 
b/security-admin/src/main/java/org/apache/ranger/biz/RangerPolicyAdminCache.java
index a64e427c5..5bd3a0934 100644
--- 
a/security-admin/src/main/java/org/apache/ranger/biz/RangerPolicyAdminCache.java
+++ 
b/security-admin/src/main/java/org/apache/ranger/biz/RangerPolicyAdminCache.java
@@ -68,6 +68,20 @@ public class RangerPolicyAdminCache {
                        return null;
                }
 
+               try {
+                       if (!svcStore.serviceExists(serviceName)) {
+                               LOG.warn("Service:[" + serviceName + "] does 
not exist in service-store. Returning null policy-engine!");
+
+                               policyAdminCache.remove(serviceName);
+
+                               return null;
+                       }
+               } catch (Exception exception) {
+                       LOG.error("Failed to check if service:[" + serviceName 
+ "] exists in service-store", exception);
+
+                       return null;
+               }
+
                long        policyVersion;
                long        roleVersion;
                RangerRoles roles;
diff --git 
a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java 
b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
index 00a3d9c47..cccc47fbe 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
@@ -1933,6 +1933,25 @@ public class ServiceDBStore extends AbstractServiceStore 
{
                return policies;
        }
 
+       @Override
+       public boolean serviceExists(String name) {
+               boolean ret = false;
+
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("==> ServiceDBStore.serviceExists({})", name);
+               }
+
+               Long id = daoMgr.getXXService().findIdByName(name);
+
+               ret = id != null;
+
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("<== ServiceDBStore.serviceExists({}): 
ret={}", name, ret);
+               }
+
+               return ret;
+       }
+
        @Override
        public RangerService getService(Long id) throws Exception {
                if(LOG.isDebugEnabled()) {

Reply via email to