Skip to content

Commit 0b782da

Browse files
rameeshmRamesh Mani
andauthored
RANGER-5577:API to support bulk delete of resources in DataShare (#936)
* RANGER-5577:API to support bulk delete of resources in DataShare * RANGER-5577:API to support bulk delete of resources in DataShare - Fixed review comments --------- Co-authored-by: Ramesh Mani <rmani@apache.org>
1 parent ba978cf commit 0b782da

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

security-admin/src/main/java/org/apache/ranger/rest/GdsREST.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,32 +1292,36 @@ public void removeSharedResource(@PathParam("id") Long resourceId) {
12921292
@DELETE
12931293
@Path("/resources")
12941294
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.REMOVE_SHARED_RESOURCES + "\")")
1295-
public void removeSharedResources(List<Long> resourceIds) {
1296-
LOG.debug("==> GdsREST.removeSharedResources({})", resourceIds);
1295+
public void removeSharedResources(@QueryParam("id") List<Long> id) {
1296+
LOG.debug("==> GdsREST.removeSharedResources(resourceIds={})", id);
12971297

12981298
RangerPerfTracer perf = null;
12991299

13001300
try {
1301-
if (resourceIds.size() > SHARED_RESOURCES_MAX_BATCH_SIZE) {
1301+
if (id == null) {
1302+
throw new Exception("resourceIds must not be null");
1303+
}
1304+
1305+
if (id.size() > SHARED_RESOURCES_MAX_BATCH_SIZE) {
13021306
throw new Exception("removeSharedResources batch size exceeded the configured limit: Maximum allowed is " + SHARED_RESOURCES_MAX_BATCH_SIZE);
13031307
}
13041308

13051309
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
1306-
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "GdsREST.removeSharedResources(" + resourceIds + ")");
1310+
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "GdsREST.removeSharedResources(" + id + ")");
13071311
}
13081312

1309-
gdsStore.removeSharedResources(resourceIds);
1313+
gdsStore.removeSharedResources(id);
13101314
} catch (WebApplicationException excp) {
13111315
throw excp;
13121316
} catch (Throwable excp) {
1313-
LOG.error("removeSharedResources({}) failed", resourceIds, excp);
1317+
LOG.error("removeSharedResources({}) failed", id, excp);
13141318

13151319
throw restErrorUtil.createRESTException(excp.getMessage());
13161320
} finally {
13171321
RangerPerfTracer.log(perf);
13181322
}
13191323

1320-
LOG.debug("<== GdsREST.removeSharedResources({})", resourceIds);
1324+
LOG.debug("<== GdsREST.removeSharedResources(resourceIds={})", id);
13211325
}
13221326

13231327
@GET

security-admin/src/test/java/org/apache/ranger/rest/TestGdsREST.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,13 @@ public void testRemoveSharedResourcesBatchSizeExceeded() {
962962
assertThrows(WebApplicationException.class, () -> gdsREST.removeSharedResources(resourceIds));
963963
}
964964

965+
@Test
966+
public void testRemoveSharedResourcesNullResourceIds() {
967+
Mockito.when(restErrorUtil.createRESTException(Mockito.anyString())).thenReturn(new WebApplicationException());
968+
969+
assertThrows(WebApplicationException.class, () -> gdsREST.removeSharedResources(null));
970+
}
971+
965972
@Test
966973
public void testGetSharedResource() {
967974
Long resourceId = 1L;

0 commit comments

Comments
 (0)