You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2023/05/19 13:22:48 UTC

[ranger] branch master updated: RANGER-4244: security-zone REST APIs to return status code 409 in case of simultaneous update calls

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git


The following commit(s) were added to refs/heads/master by this push:
     new 6efa1f306 RANGER-4244: security-zone REST APIs to return status code 409 in case of simultaneous update calls
6efa1f306 is described below

commit 6efa1f306c496a59f141fc15c8954a528825f8db
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Thu May 18 18:04:02 2023 -0700

    RANGER-4244: security-zone REST APIs to return status code 409 in case of simultaneous update calls
---
 .../java/org/apache/ranger/rest/SecurityZoneREST.java  | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java b/security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java
index b82e478c6..53aafae94 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/SecurityZoneREST.java
@@ -30,6 +30,7 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 
+import javax.persistence.OptimisticLockException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
@@ -81,6 +82,7 @@ import com.google.common.collect.Sets;
 public class SecurityZoneREST {
     private static final Logger LOG                                    = LoggerFactory.getLogger(SecurityZoneREST.class);
     private static final String STR_USER_NOT_AUTHORIZED_TO_ACCESS_ZONE = "User is not authorized to access zone(s).";
+    private static final String ERR_ANOTHER_SEC_ZONE_OPER_IN_PROGRESS  = "Another security zone operation is already in progress";
 
     @Autowired
     RESTErrorUtil restErrorUtil;
@@ -129,6 +131,10 @@ public class SecurityZoneREST {
             RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore);
             validator.validate(securityZone, RangerValidator.Action.CREATE);
             ret = securityZoneStore.createSecurityZone(securityZone);
+        } catch (OptimisticLockException | org.eclipse.persistence.exceptions.OptimisticLockException excp) {
+            LOG.error("createSecurityZone(" + securityZone + ") failed", excp);
+
+            throw restErrorUtil.createRESTException(HttpServletResponse.SC_CONFLICT, ERR_ANOTHER_SEC_ZONE_OPER_IN_PROGRESS, true);
         } catch(WebApplicationException excp) {
             throw excp;
         } catch(Throwable excp) {
@@ -168,6 +174,10 @@ public class SecurityZoneREST {
             RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore);
             validator.validate(securityZone, RangerValidator.Action.UPDATE);
             ret = securityZoneStore.updateSecurityZoneById(securityZone);
+        } catch (OptimisticLockException | org.eclipse.persistence.exceptions.OptimisticLockException excp) {
+            LOG.error("updateSecurityZone(" + securityZone + ") failed", excp);
+
+            throw restErrorUtil.createRESTException(HttpServletResponse.SC_CONFLICT, ERR_ANOTHER_SEC_ZONE_OPER_IN_PROGRESS, true);
         } catch(WebApplicationException excp) {
             throw excp;
         } catch(Throwable excp) {
@@ -192,6 +202,10 @@ public class SecurityZoneREST {
             RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore);
             validator.validate(zoneName, RangerValidator.Action.DELETE);
             securityZoneStore.deleteSecurityZoneByName(zoneName);
+        } catch (OptimisticLockException | org.eclipse.persistence.exceptions.OptimisticLockException excp) {
+            LOG.error("deleteSecurityZone(" + zoneName + ") failed", excp);
+
+            throw restErrorUtil.createRESTException(HttpServletResponse.SC_CONFLICT, ERR_ANOTHER_SEC_ZONE_OPER_IN_PROGRESS, true);
         } catch(WebApplicationException excp) {
             throw excp;
         } catch(Throwable excp) {
@@ -218,6 +232,10 @@ public class SecurityZoneREST {
             RangerSecurityZoneValidator validator = validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore);
             validator.validate(zoneId, RangerValidator.Action.DELETE);
             securityZoneStore.deleteSecurityZoneById(zoneId);
+        } catch (OptimisticLockException | org.eclipse.persistence.exceptions.OptimisticLockException excp) {
+            LOG.error("deleteSecurityZone(" + zoneId + ") failed", excp);
+
+            throw restErrorUtil.createRESTException(HttpServletResponse.SC_CONFLICT, ERR_ANOTHER_SEC_ZONE_OPER_IN_PROGRESS, true);
         } catch(WebApplicationException excp) {
             throw excp;
         } catch(Throwable excp) {