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 1fcc15e38 RANGER-4727: failure to delete tagDef should return 
appropriate error message
1fcc15e38 is described below

commit 1fcc15e386307a0743798b5d116bd230d82b8779
Author: Subhrat Chaudhary <[email protected]>
AuthorDate: Tue Mar 5 22:15:48 2024 -0800

    RANGER-4727: failure to delete tagDef should return appropriate error 
message
    
    Signed-off-by: Madhan Neethiraj <[email protected]>
---
 .../java/org/apache/ranger/biz/TagDBStore.java     | 36 ++++++++++++----------
 .../org/apache/ranger/common/RESTErrorUtil.java    |  6 +++-
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/security-admin/src/main/java/org/apache/ranger/biz/TagDBStore.java 
b/security-admin/src/main/java/org/apache/ranger/biz/TagDBStore.java
index fb912d4f8..a472fe131 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/TagDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/TagDBStore.java
@@ -165,23 +165,15 @@ public class TagDBStore extends AbstractTagStore {
        @Override
        public void deleteTagDefByName(String name) throws Exception {
                if (LOG.isDebugEnabled()) {
-                       LOG.debug("==> TagDBStore.deleteTagDef(" + name + ")");
+                       LOG.debug("==> TagDBStore.deleteTagDefByName(" + name + 
")");
                }
 
                if (StringUtils.isNotBlank(name)) {
-                       RangerTagDef tagDef = getTagDefByName(name);
-
-                       if(tagDef != null) {
-                               if(LOG.isDebugEnabled()) {
-                                       LOG.debug("Deleting tag-def [name=" + 
name + "; id=" + tagDef.getId() + "]");
-                               }
-
-                               rangerTagDefService.delete(tagDef);
-                       }
+                       deleteTagDef(getTagDefByName(name));
                }
 
                if (LOG.isDebugEnabled()) {
-                       LOG.debug("<== TagDBStore.deleteTagDef(" + name + ")");
+                       LOG.debug("<== TagDBStore.deleteTagDefByName(" + name + 
")");
                }
        }
 
@@ -192,11 +184,7 @@ public class TagDBStore extends AbstractTagStore {
                }
 
                if(id != null) {
-                       RangerTagDef tagDef = rangerTagDefService.read(id);
-
-                       if(tagDef != null) {
-                               rangerTagDefService.delete(tagDef);
-                       }
+                       deleteTagDef(rangerTagDefService.read(id));
                }
 
                if (LOG.isDebugEnabled()) {
@@ -1382,4 +1370,20 @@ public class TagDBStore extends AbstractTagStore {
                initStatics();
                return SUPPORTS_IN_PLACE_TAG_UPDATES;
        }
+
+       private void deleteTagDef(RangerTagDef tagDef) throws Exception {
+               if (tagDef != null) {
+                       if (LOG.isDebugEnabled()) {
+                               LOG.debug("Deleting tag-def [name=" + 
tagDef.getName() + "; id=" + tagDef.getId() + "]");
+                       }
+
+                       List<RangerTag> tagsByType = 
rangerTagService.getTagsByType(tagDef.getName());
+
+                       if (CollectionUtils.isEmpty(tagsByType)) {
+                               rangerTagDefService.delete(tagDef);
+                       } else {
+                               throw new Exception("Cannot delete tag-def: " + 
tagDef.getName() + ". " + tagsByType.size() + " tag instances for this tag-def 
exist");
+                       }
+               }
+       }
 }
diff --git 
a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java 
b/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
index c3af9f9ca..50e13e048 100644
--- a/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
+++ b/security-admin/src/main/java/org/apache/ranger/common/RESTErrorUtil.java
@@ -352,8 +352,12 @@ public class RESTErrorUtil {
 
        public WebApplicationException createRESTException(int responseCode,
                        String logMessage, boolean logError) {
+               VXResponse response = new VXResponse();
+
+               response.setMsgDesc(logMessage);
+
                Response errorResponse = Response
-                               
.status(responseCode).entity(logMessage).build();
+                               .status(responseCode).entity(response).build();
 
                WebApplicationException restException = new 
WebApplicationException(
                                errorResponse);

Reply via email to