From ca8d7fc72bab29ac6a6e866e68bb9a2891eee3c4 Mon Sep 17 00:00:00 2001 From: Anand Nadar Date: Wed, 21 Feb 2024 22:20:21 -0800 Subject: [PATCH] RANGER-4724: updated importServiceTags API to handle missing service name in resources Signed-off-by: Madhan Neethiraj --- .../org/apache/ranger/rest/ServiceTagsProcessor.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/security-admin/src/main/java/org/apache/ranger/rest/ServiceTagsProcessor.java b/security-admin/src/main/java/org/apache/ranger/rest/ServiceTagsProcessor.java index f29304036d..ecdf504e3a 100644 --- a/security-admin/src/main/java/org/apache/ranger/rest/ServiceTagsProcessor.java +++ b/security-admin/src/main/java/org/apache/ranger/rest/ServiceTagsProcessor.java @@ -144,6 +144,10 @@ private void addOrUpdate(ServiceTags serviceTags) throws Exception { for (int i = 0; i < resources.size(); i++) { resource = resources.get(i); + if (StringUtils.isBlank(resource.getServiceName())) { + resource.setServiceName(serviceTags.getServiceName()); + } + RangerServiceResource existing = null; String resourceSignature = null; Long resourceId = resource.getId(); @@ -178,9 +182,6 @@ private void addOrUpdate(ServiceTags serviceTags) throws Exception { perf = RangerPerfTracer.getPerfTracer(PERF_LOG_ADD_OR_UPDATE, "tags.createOrUpdate_service_resource(" + resourceId + ")"); } if (existing == null) { - if (StringUtils.isBlank(resource.getServiceName())) { - resource.setServiceName(serviceTags.getServiceName()); - } resourceInStore = tagStore.createServiceResource(resource); } else if (StringUtils.isEmpty(resource.getServiceName()) || MapUtils.isEmpty(resource.getResourceElements())) { @@ -515,11 +516,13 @@ private void delete(ServiceTags serviceTags) throws Exception { if (CollectionUtils.isNotEmpty(serviceResources)) { for (RangerServiceResource serviceResource : serviceResources) { + if (StringUtils.isBlank(serviceResource.getServiceName())) { + serviceResource.setServiceName(serviceTags.getServiceName()); + } RangerServiceResource objToDelete = null; try { - if (StringUtils.isNotBlank(serviceResource.getGuid())) { objToDelete = tagStore.getServiceResourceByGuid(serviceResource.getGuid()); }