Skip to content

Commit

Permalink
RANGER-4634: on service deletion, delete associated GDS objects as well
Browse files Browse the repository at this point in the history
Signed-off-by: Madhan Neethiraj <[email protected]>
  • Loading branch information
prashantdev88 authored and mneethiraj committed Jan 9, 2024
1 parent 65b17ec commit 12a1bf5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@ public interface GdsStore {
RangerDatasetInProject getDatasetInProject(Long datasetInProjectId) throws Exception;

PList<RangerDatasetInProject> searchDatasetInProjects(SearchFilter filter) throws Exception;

void deleteAllGdsObjectsForService(Long serviceId) throws Exception;
}
25 changes: 25 additions & 0 deletions security-admin/src/main/java/org/apache/ranger/biz/GdsDBStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,31 @@ public PList<RangerDatasetInProject> searchDatasetInProjects(SearchFilter filter
return ret;
}

@Override
public void deleteAllGdsObjectsForService(Long serviceId) throws Exception {
LOG.debug("==> deleteAllGdsObjectsForService({})", serviceId);

List<XXGdsDataShare> dataShares = daoMgr.getXXGdsDataShare().findByServiceId(serviceId);

if (CollectionUtils.isNotEmpty(dataShares)) {
LOG.info("Deleting {} dataShares associated with service id={}", dataShares.size(), serviceId);

dataShares.forEach(dataShare -> {
try {
LOG.info("Deleting dataShare id={}, name={}", dataShare.getId(), dataShare.getName());

deleteDataShare(dataShare.getId(), true);
} catch (Exception excp) {
LOG.error("failed to delete dataShare id={}, name={}", dataShare.getId(), dataShare.getName(), excp);

throw excp;
}
});
}

LOG.debug("<== deleteAllGdsObjectsForService({})", serviceId);
}

public ServiceGdsInfo getGdsInfoIfUpdated(String serviceName, Long lastKnownVersion) throws Exception {
LOG.debug("==> GdsDBStore.getGdsInfoIfUpdated({}, {})", serviceName , lastKnownVersion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.ranger.authorization.hadoop.config.RangerAdminConfig;
import org.apache.ranger.authorization.utils.StringUtil;
import org.apache.ranger.biz.AssetMgr;
import org.apache.ranger.biz.GdsDBStore;
import org.apache.ranger.biz.PolicyRefUpdater;
import org.apache.ranger.biz.RangerPolicyAdmin;
import org.apache.ranger.biz.RangerBizUtil;
Expand Down Expand Up @@ -239,9 +240,12 @@ public class ServiceREST {
@Autowired
TagDBStore tagStore;

@Autowired
GdsDBStore gdsStore;

@Autowired
RangerTransactionSynchronizationAdapter rangerTransactionSynchronizationAdapter;

private RangerPolicyEngineOptions delegateAdminOptions;
private RangerPolicyEngineOptions policySearchAdminOptions;
private RangerPolicyEngineOptions defaultAdminOptions;
Expand Down Expand Up @@ -4643,7 +4647,10 @@ private String deleteServiceById(Long id) {
bizUtil.hasKMSPermissions("Service", xxServiceDef.getImplclassname());
bizUtil.blockAuditorRoleUser();
}

tagStore.deleteAllTagObjectsForService(service.getName());
gdsStore.deleteAllGdsObjectsForService(id);

deletedServiceName = service.getName();

svcStore.deleteService(id);
Expand Down

0 comments on commit 12a1bf5

Please sign in to comment.