Skip to content

Commit

Permalink
RANGER-4727: failure to delete tagDef should return appropriate error…
Browse files Browse the repository at this point in the history
… message

Signed-off-by: Madhan Neethiraj <[email protected]>
  • Loading branch information
suchnit authored and mneethiraj committed Mar 6, 2024
1 parent a7026dd commit 1fcc15e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
36 changes: 20 additions & 16 deletions security-admin/src/main/java/org/apache/ranger/biz/TagDBStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,15 @@ public RangerTagDef updateTagDef(RangerTagDef tagDef) throws Exception {
@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 + ")");
}
}

Expand All @@ -192,11 +184,7 @@ public void deleteTagDef(Long id) throws Exception {
}

if(id != null) {
RangerTagDef tagDef = rangerTagDefService.read(id);

if(tagDef != null) {
rangerTagDefService.delete(tagDef);
}
deleteTagDef(rangerTagDefService.read(id));
}

if (LOG.isDebugEnabled()) {
Expand Down Expand Up @@ -1382,4 +1370,20 @@ public boolean isInPlaceTagUpdateSupported() {
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");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,12 @@ public WebApplicationException createRESTException(String errorMessage,

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);
Expand Down

0 comments on commit 1fcc15e

Please sign in to comment.