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()); }