ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject incubator-ranger git commit: RANGER-663: fix to handle simultaneous updates to service-def/service/policy
Date Thu, 24 Sep 2015 07:05:18 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master b6aca92b0 -> baf0ddd6f


RANGER-663: fix to handle simultaneous updates to service-def/service/policy


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/baf0ddd6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/baf0ddd6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/baf0ddd6

Branch: refs/heads/master
Commit: baf0ddd6f656ca0abff6ee800228f0e757855904
Parents: b6aca92
Author: Madhan Neethiraj <madhan@apache.org>
Authored: Wed Sep 23 19:08:26 2015 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Wed Sep 23 22:19:21 2015 -0700

----------------------------------------------------------------------
 .../org/apache/ranger/biz/ServiceDBStore.java   | 35 +++++---------------
 .../org/apache/ranger/entity/XXPolicyBase.java  |  2 ++
 .../org/apache/ranger/entity/XXServiceBase.java |  2 ++
 .../apache/ranger/entity/XXServiceDefBase.java  |  2 ++
 .../org/apache/ranger/rest/ServiceREST.java     |  1 -
 .../service/RangerServiceDefServiceBase.java    |  1 -
 .../service/RangerServiceServiceBase.java       |  1 -
 .../apache/ranger/biz/TestServiceDBStore.java   |  4 ---
 .../org/apache/ranger/rest/TestServiceREST.java |  2 --
 .../ranger/service/TestRangerPolicyService.java |  1 -
 .../service/TestRangerServiceDefService.java    |  2 --
 .../TestRangerServiceDefServiceBase.java        |  1 -
 .../service/TestRangerServiceService.java       |  1 -
 .../service/TestRangerServiceServiceBase.java   |  1 -
 14 files changed, 14 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
index 6813915..d62c645 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
@@ -411,14 +411,10 @@ public class ServiceDBStore implements ServiceStore {
 		List<RangerContextEnricherDef> contextEnrichers = serviceDef.getContextEnrichers()
!= null 	? serviceDef.getContextEnrichers() 	  : new ArrayList<RangerContextEnricherDef>();
 		List<RangerEnumDef> enums 						= serviceDef.getEnums() != null 			? serviceDef.getEnums()
			  : new ArrayList<RangerEnumDef>();
 
-		Long version = serviceDef.getVersion();
-		if (version == null) {
-			version = new Long(1);
-			LOG.info("Found Version Value: `null`, so setting value of version to 1. While updating
object version should not be null.");
-		} else {
-			version = new Long(version.longValue() + 1);
-		}
-		serviceDef.setVersion(version);
+		serviceDef.setCreateTime(existing.getCreateTime());
+		serviceDef.setGuid(existing.getGuid());
+		serviceDef.setVersion(existing.getVersion());
+
 		serviceDef = serviceDefService.update(serviceDef);
 		XXServiceDef createdSvcDef = daoMgr.getXXServiceDef().getById(serviceDefId);
 
@@ -1125,16 +1121,6 @@ public class ServiceDBStore implements ServiceStore {
 
 		List<XXTrxLog> trxLogList = svcService.getTransactionLog(service, existing, RangerServiceService.OPERATION_UPDATE_CONTEXT);
 
-		Long version = service.getVersion();
-		if(version == null) {
-			version = new Long(1);
-			LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating
object, version should not be null.");
-		} else {
-			version = new Long(version.longValue() + 1);
-		}
-
-		service.setVersion(version);
-
 		if(populateExistingBaseFields) {
 			svcServiceWithAssignedId.setPopulateExistingBaseFields(true);
 			service = svcServiceWithAssignedId.update(service);
@@ -1438,17 +1424,12 @@ public class ServiceDBStore implements ServiceStore {
 		Map<String, RangerPolicyResource> newResources = policy.getResources();
 		List<RangerPolicyItem> newPolicyItems = policy.getPolicyItems();
 		
+		policy.setCreateTime(xxExisting.getCreateTime());
+		policy.setGuid(xxExisting.getGuid());
+		policy.setVersion(xxExisting.getVersion());
+
 		List<XXTrxLog> trxLogList = policyService.getTransactionLog(policy, xxExisting, RangerPolicyService.OPERATION_UPDATE_CONTEXT);
 		
-		Long version = policy.getVersion();
-		if(version == null) {
-			version = new Long(1);
-			LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating
object, version should not be null.");
-		} else {
-			version = new Long(version.longValue() + 1);
-		}
-		
-		policy.setVersion(version);
 		updatePolicySignature(policy);
 		
 		policy = policyService.update(policy);

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/main/java/org/apache/ranger/entity/XXPolicyBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/entity/XXPolicyBase.java b/security-admin/src/main/java/org/apache/ranger/entity/XXPolicyBase.java
index 7e59530..8564d43 100644
--- a/security-admin/src/main/java/org/apache/ranger/entity/XXPolicyBase.java
+++ b/security-admin/src/main/java/org/apache/ranger/entity/XXPolicyBase.java
@@ -19,6 +19,7 @@ package org.apache.ranger.entity;
 
 import javax.persistence.Column;
 import javax.persistence.MappedSuperclass;
+import javax.persistence.Version;
 import javax.xml.bind.annotation.XmlRootElement;
 
 @MappedSuperclass
@@ -42,6 +43,7 @@ public abstract class XXPolicyBase extends XXDBBase {
 	 * </ul>
 	 *
 	 */
+	@Version
 	@Column(name = "version")
 	protected Long version;
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/main/java/org/apache/ranger/entity/XXServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/entity/XXServiceBase.java b/security-admin/src/main/java/org/apache/ranger/entity/XXServiceBase.java
index 9fc7349..243526f 100644
--- a/security-admin/src/main/java/org/apache/ranger/entity/XXServiceBase.java
+++ b/security-admin/src/main/java/org/apache/ranger/entity/XXServiceBase.java
@@ -23,6 +23,7 @@ import javax.persistence.Column;
 import javax.persistence.MappedSuperclass;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
+import javax.persistence.Version;
 import javax.xml.bind.annotation.XmlRootElement;
 
 @MappedSuperclass
@@ -46,6 +47,7 @@ public abstract class XXServiceBase extends XXDBBase {
 	 * </ul>
 	 *
 	 */
+	@Version
 	@Column(name = "version")
 	protected Long version;
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/main/java/org/apache/ranger/entity/XXServiceDefBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/entity/XXServiceDefBase.java b/security-admin/src/main/java/org/apache/ranger/entity/XXServiceDefBase.java
index 93a0372..c59286e 100644
--- a/security-admin/src/main/java/org/apache/ranger/entity/XXServiceDefBase.java
+++ b/security-admin/src/main/java/org/apache/ranger/entity/XXServiceDefBase.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
 
 import javax.persistence.Column;
 import javax.persistence.MappedSuperclass;
+import javax.persistence.Version;
 import javax.xml.bind.annotation.XmlRootElement;
 
 @MappedSuperclass
@@ -43,6 +44,7 @@ public abstract class XXServiceDefBase extends XXDBBase implements Serializable
 	 * </ul>
 	 *
 	 */
+	@Version
 	@Column(name = "version")
 	protected Long version;
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
index f523d67..5371897 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
@@ -49,7 +49,6 @@ import org.apache.ranger.biz.RangerBizUtil;
 import org.apache.ranger.biz.ServiceDBStore;
 import org.apache.ranger.biz.ServiceMgr;
 import org.apache.ranger.biz.XUserMgr;
-import org.apache.ranger.common.AppConstants;
 import org.apache.ranger.common.GUIDUtil;
 import org.apache.ranger.common.MessageEnums;
 import org.apache.ranger.common.RESTErrorUtil;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
index dac9807..56c8c91 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceDefServiceBase.java
@@ -158,7 +158,6 @@ public abstract class RangerServiceDefServiceBase<T extends XXServiceDefBase,
V
 		String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid();
 		
 		xObj.setGuid(guid);
-		xObj.setVersion(vObj.getVersion());
 		xObj.setName(vObj.getName());
 		xObj.setImplclassname(vObj.getImplClass());
 		xObj.setLabel(vObj.getLabel());

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
index d0ddcff..09dced6 100755
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerServiceServiceBase.java
@@ -65,7 +65,6 @@ public abstract class RangerServiceServiceBase<T extends XXServiceBase,
V extend
 		String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid();
 		
 		xObj.setGuid(guid);
-		xObj.setVersion(vObj.getVersion());
 		
 		XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(vObj.getType());
 		if(xServiceDef == null) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java b/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
index b2fdad6..70e89a3 100644
--- a/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
+++ b/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
@@ -292,7 +292,6 @@ public class TestServiceDBStore {
 		xServiceDef.setDescription("HDFS Repository");
 		xServiceDef.setGuid("1427365526516_835_0");
 		xServiceDef.setId(Id);
-		xServiceDef.setVersion(Id);
 		xServiceDef.setUpdateTime(new Date());
 		xServiceDef.setUpdatedByUserId(Id);
 		xServiceDef.setImplclassname("RangerServiceHdfs");
@@ -318,7 +317,6 @@ public class TestServiceDBStore {
 		xService.setType(1L);
 		xService.setUpdatedByUserId(Id);
 		xService.setUpdateTime(new Date());
-		xService.setVersion(1L);
 
 		return xService;
 	}
@@ -677,7 +675,6 @@ public class TestServiceDBStore {
 		xService.setType(1L);
 		xService.setUpdatedByUserId(Id);
 		xService.setUpdateTime(new Date());
-		xService.setVersion(1L);
 		xServiceList.add(xService);
 
 		List<XXAccessTypeDef> accessTypeDefList = new ArrayList<XXAccessTypeDef>();
@@ -2462,7 +2459,6 @@ public class TestServiceDBStore {
 		xService.setType(1L);
 		xService.setUpdatedByUserId(Id);
 		xService.setUpdateTime(new Date());
-		xService.setVersion(1L);
 
 		String serviceName = "HDFS_1";
 		Long lastKnownVersion = 1l;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java b/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
index f728c58..8b3e348 100644
--- a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
+++ b/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java
@@ -284,7 +284,6 @@ public class TestServiceREST {
 		xServiceDef.setDescription("HDFS Repository");
 		xServiceDef.setGuid("1427365526516_835_0");
 		xServiceDef.setId(Id);
-		xServiceDef.setVersion(Id);
 		xServiceDef.setUpdateTime(new Date());
 		xServiceDef.setUpdatedByUserId(Id);
 		xServiceDef.setImplclassname("RangerServiceHdfs");
@@ -310,7 +309,6 @@ public class TestServiceREST {
 		xService.setType(1L);
 		xService.setUpdatedByUserId(Id);
 		xService.setUpdateTime(new Date());
-		xService.setVersion(1L);
 
 		return xService;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyService.java
index bac5261..513746b 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyService.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerPolicyService.java
@@ -180,7 +180,6 @@ public class TestRangerPolicyService {
 		xService.setType(1L);
 		xService.setUpdatedByUserId(Id);
 		xService.setUpdateTime(new Date());
-		xService.setVersion(1L);
 
 		return xService;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
index 94680c3..5c57a9f 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefService.java
@@ -138,7 +138,6 @@ public class TestRangerServiceDefService {
 		xServiceDef.setDescription("HDFS Repository");
 		xServiceDef.setGuid("1427365526516_835_0");
 		xServiceDef.setId(Id);
-		xServiceDef.setVersion(Id);
 		xServiceDef.setUpdateTime(new Date());
 		xServiceDef.setUpdatedByUserId(Id);
 		xServiceDef.setImplclassname("RangerServiceHdfs");
@@ -408,7 +407,6 @@ public class TestRangerServiceDefService {
 		serviceDef.setDescription("HDFS Repository");
 		serviceDef.setGuid("1427365526516_835_0");
 		serviceDef.setId(Id);
-		serviceDef.setVersion(Id);
 		serviceDef.setUpdateTime(new Date());
 		serviceDef.setUpdatedByUserId(Id);
 		serviceDef.setImplclassname("RangerServiceHdfs");

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
index dd1978b..e01e23c 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceDefServiceBase.java
@@ -152,7 +152,6 @@ public class TestRangerServiceDefServiceBase {
 		xServiceDef.setRbkeylabel(null);
 		xServiceDef.setUpdatedByUserId(Id);
 		xServiceDef.setUpdateTime(new Date());
-		xServiceDef.setVersion(Id);
 
 		return xServiceDef;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceService.java
index 7d0cf61..215506e 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceService.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceService.java
@@ -141,7 +141,6 @@ public class TestRangerServiceService {
 		xService.setType(1L);
 		xService.setUpdatedByUserId(userId);
 		xService.setUpdateTime(new Date());
-		xService.setVersion(1L);
 
 		return xService;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/baf0ddd6/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
index f359118..5dff936 100644
--- a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceServiceBase.java
@@ -127,7 +127,6 @@ public class TestRangerServiceServiceBase {
 		xService.setType(1L);
 		xService.setUpdatedByUserId(Id);
 		xService.setUpdateTime(new Date());
-		xService.setVersion(1L);
 
 		return xService;
 	}


Mime
View raw message