ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject incubator-ranger git commit: Add latest policy and tag info to RangerPluginInfo
Date Tue, 06 Dec 2016 01:15:30 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master 883666c67 -> 10f2befe9


Add latest policy and tag info to RangerPluginInfo

Signed-off-by: Velmurugan Periasamy <vel@apache.org>


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

Branch: refs/heads/master
Commit: 10f2befe97f597ebef7cc7ad032e833633905117
Parents: 883666c
Author: Abhay Kulkarni <akulkarni@hortonworks.com>
Authored: Wed Nov 30 16:16:20 2016 -0800
Committer: Velmurugan Periasamy <vel@apache.org>
Committed: Mon Dec 5 20:15:08 2016 -0500

----------------------------------------------------------------------
 .../ranger/plugin/model/RangerPluginInfo.java   | 30 ++++++++
 .../ranger/db/XXServiceVersionInfoDao.java      |  7 ++
 .../ranger/service/RangerPluginInfoService.java | 80 ++++++++++++++++++--
 .../resources/META-INF/jpa_named_queries.xml    |  4 +
 4 files changed, 113 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/10f2befe/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPluginInfo.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPluginInfo.java
b/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPluginInfo.java
index ee11c42..d859368 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPluginInfo.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPluginInfo.java
@@ -53,6 +53,12 @@ public class RangerPluginInfo implements Serializable {
 	public static final String PLUGIN_INFO_TAG_ACTIVATION_TIME       = "tagActivationTime";
 	public static final String PLUGIN_INFO_TAG_ACTIVE_VERSION        = "tagActiveVersion";
 
+
+	public static final String RANGER_ADMIN_LAST_POLICY_UPDATE_TIME  = "lastPolicyUpdateTime";
+	public static final String RANGER_ADMIN_LATEST_POLICY_VERSION    = "latestPolicyVersion";
+	public static final String RANGER_ADMIN_LAST_TAG_UPDATE_TIME     = "lastTagUpdateTime";
+	public static final String RANGER_ADMIN_LATEST_TAG_VERSION       = "latestTagVersion";
+
 	private Long    id         = null;
 	private Date    createTime = null;
 	private Date    updateTime = null;
@@ -232,6 +238,30 @@ public class RangerPluginInfo implements Serializable {
 		return StringUtils.isNotBlank(activeVersionString) ? Long.valueOf(activeVersionString)
: null;
 	}
 
+	@JsonIgnore
+	public Long getLatestPolicyVersion() {
+		String latestPolicyVersionString = getInfo().get(RANGER_ADMIN_LATEST_POLICY_VERSION);
+		return StringUtils.isNotBlank(latestPolicyVersionString) ? Long.valueOf(latestPolicyVersionString)
: null;
+	}
+
+	@JsonIgnore
+	public Long getLastPolicyUpdateTime() {
+		String updateTimeString = getInfo().get(RANGER_ADMIN_LAST_POLICY_UPDATE_TIME);
+		return StringUtils.isNotBlank(updateTimeString) ? Long.valueOf(updateTimeString) : null;
+	}
+
+	@JsonIgnore
+	public Long getLatestTagVersion() {
+		String latestTagVersionString = getInfo().get(RANGER_ADMIN_LATEST_TAG_VERSION);
+		return StringUtils.isNotBlank(latestTagVersionString) ? Long.valueOf(latestTagVersionString)
: null;
+	}
+
+	@JsonIgnore
+	public Long getLastTagUpdateTime() {
+		String updateTimeString = getInfo().get(RANGER_ADMIN_LAST_TAG_UPDATE_TIME);
+		return StringUtils.isNotBlank(updateTimeString) ? Long.valueOf(updateTimeString) : null;
+	}
+
 	@Override
 	public String toString() {
 		StringBuilder sb = new StringBuilder();

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/10f2befe/security-admin/src/main/java/org/apache/ranger/db/XXServiceVersionInfoDao.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/db/XXServiceVersionInfoDao.java
b/security-admin/src/main/java/org/apache/ranger/db/XXServiceVersionInfoDao.java
index f1535fe..0098bff 100644
--- a/security-admin/src/main/java/org/apache/ranger/db/XXServiceVersionInfoDao.java
+++ b/security-admin/src/main/java/org/apache/ranger/db/XXServiceVersionInfoDao.java
@@ -62,6 +62,13 @@ public class XXServiceVersionInfoDao extends BaseDao<XXServiceVersionInfo>
{
 		}
 	}
 
+	@SuppressWarnings("unchecked")
+	public List<Object[]> getAllWithServiceNames(){
+		return getEntityManager()
+				.createNamedQuery("XXServiceVersionInfo.getAllWithServiceNames")
+				.getResultList();
+	}
+
 	public void updateServiceVersionInfoForServiceResourceUpdate(Long resourceId, Date updateTime)
{
 		if (resourceId == null) {
 			return;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/10f2befe/security-admin/src/main/java/org/apache/ranger/service/RangerPluginInfoService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerPluginInfoService.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerPluginInfoService.java
index fe86e72..b496b86 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerPluginInfoService.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerPluginInfoService.java
@@ -19,9 +19,13 @@ package org.apache.ranger.service;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ranger.biz.RangerBizUtil;
 import org.apache.ranger.common.JSONUtil;
 import org.apache.ranger.common.RangerSearchUtil;
@@ -29,6 +33,7 @@ import org.apache.ranger.common.SearchField;
 import org.apache.ranger.common.SortField;
 import org.apache.ranger.db.RangerDaoManager;
 import org.apache.ranger.entity.XXPluginInfo;
+import org.apache.ranger.entity.XXServiceVersionInfo;
 import org.apache.ranger.plugin.model.RangerPluginInfo;
 import org.apache.ranger.plugin.store.PList;
 import org.apache.ranger.plugin.util.SearchFilter;
@@ -41,6 +46,8 @@ import javax.persistence.Query;
 @Service
 public class RangerPluginInfoService {
 
+	private static final Log LOG = LogFactory.getLog(RangerPluginInfoService.class);
+
 	@Autowired
 	RangerSearchUtil searchUtil;
 
@@ -83,8 +90,32 @@ public class RangerPluginInfoService {
 
 		List<XXPluginInfo> xObjList = searchRangerObjects(searchFilter, searchFields, sortFields,
retList);
 
+		List<Object[]> objectsList = null;
+		if (CollectionUtils.isNotEmpty(xObjList)) {
+			objectsList = daoManager.getXXServiceVersionInfo().getAllWithServiceNames();
+		}
+
 		for (XXPluginInfo xObj : xObjList) {
-			RangerPluginInfo obj = populateViewObject(xObj);
+			XXServiceVersionInfo xxServiceVersionInfo = null;
+
+			if (CollectionUtils.isNotEmpty(objectsList)) {
+				for (Object[] objects : objectsList) {
+					if (objects.length == 2) {
+						if (xObj.getServiceName().equals(objects[1])) {
+							if (objects[0] instanceof XXServiceVersionInfo) {
+								xxServiceVersionInfo = (XXServiceVersionInfo) objects[0];
+							} else {
+								LOG.warn("Expected first object to be XXServiceVersionInfo, got " + objects[0]);
+							}
+							break;
+						}
+					} else {
+						LOG.warn("Expected 2 objects in the list returned by getAllWithServiceNames(), received
" + objects.length);
+					}
+				}
+			}
+
+			RangerPluginInfo obj = populateViewObjectWithServiceVersionInfo(xObj, xxServiceVersionInfo);
 			objList.add(obj);
 		}
 
@@ -102,7 +133,7 @@ public class RangerPluginInfoService {
 		ret.setHostName(xObj.getHostName());
 		ret.setAppType(xObj.getAppType());
 		ret.setIpAddress(xObj.getIpAddress());
-		ret.setInfo(jsonStringToMap(xObj.getInfo()));
+		ret.setInfo(jsonStringToMap(xObj.getInfo(), null));
 		return ret;
 	}
 
@@ -118,6 +149,20 @@ public class RangerPluginInfoService {
 		ret.setInfo(mapToJsonString(modelObj.getInfo()));
 		return ret;
 	}
+
+	private RangerPluginInfo populateViewObjectWithServiceVersionInfo(XXPluginInfo xObj, XXServiceVersionInfo
xxServiceVersionInfo) {
+		RangerPluginInfo ret = new RangerPluginInfo();
+		ret.setId(xObj.getId());
+		ret.setCreateTime(xObj.getCreateTime());
+		ret.setUpdateTime(xObj.getUpdateTime());
+		ret.setServiceName(xObj.getServiceName());
+		ret.setHostName(xObj.getHostName());
+		ret.setAppType(xObj.getAppType());
+		ret.setIpAddress(xObj.getIpAddress());
+		ret.setInfo(jsonStringToMap(xObj.getInfo(), xxServiceVersionInfo));
+		return ret;
+	}
+
 	private List<XXPluginInfo> searchRangerObjects(SearchFilter searchCriteria, List<SearchField>
searchFieldList, List<SortField> sortFieldList, PList<RangerPluginInfo> pList)
{
 
 		// Get total count of the rows which meet the search criteria
@@ -175,21 +220,40 @@ public class RangerPluginInfoService {
 			try {
 				ret = jsonUtil.readMapToString(map);
 			} catch(Exception excp) {
+				LOG.error("Failed to convert map to JSON string: '" + map + "'", excp);
 			}
 		}
 
 		return ret;
 	}
 
-	private Map<String, String> jsonStringToMap(String jsonStr) {
-		Map<String, String> ret = null;
+	private Map<String, String> jsonStringToMap(String jsonStr, XXServiceVersionInfo xxServiceVersionInfo)
{
 
-			try {
-				ret = jsonUtil.jsonToMap(jsonStr);
-			} catch(Exception excp) {
+		Map<String, String> ret = null;
 
+		try {
+			ret = jsonUtil.jsonToMap(jsonStr);
+
+			if (xxServiceVersionInfo != null) {
+				Long latestPolicyVersion = xxServiceVersionInfo.getPolicyVersion();
+				Date lastPolicyUpdateTime = xxServiceVersionInfo.getPolicyUpdateTime();
+				Long latestTagVersion = xxServiceVersionInfo.getTagVersion();
+				Date lastTagUpdateTime = xxServiceVersionInfo.getTagUpdateTime();
+				ret.put(RangerPluginInfo.RANGER_ADMIN_LATEST_POLICY_VERSION, Long.toString(latestPolicyVersion));
+				ret.put(RangerPluginInfo.RANGER_ADMIN_LAST_POLICY_UPDATE_TIME, Long.toString(lastPolicyUpdateTime.getTime()));
+				// Meaningful tag-versions start from 2
+				if (latestTagVersion.longValue() > 1L) {
+					ret.put(RangerPluginInfo.RANGER_ADMIN_LATEST_TAG_VERSION, Long.toString(latestTagVersion));
+					ret.put(RangerPluginInfo.RANGER_ADMIN_LAST_TAG_UPDATE_TIME, Long.toString(lastTagUpdateTime.getTime()));
+				} else {
+					ret.remove(RangerPluginInfo.RANGER_ADMIN_LATEST_TAG_VERSION);
+					ret.remove(RangerPluginInfo.RANGER_ADMIN_LAST_TAG_UPDATE_TIME);
+				}
 			}
-
+		}
+		catch(Exception excp) {
+			LOG.error("Failed to convert JSON string to Map: '" + jsonStr + "'", excp);
+		}
 
 		return ret;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/10f2befe/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
----------------------------------------------------------------------
diff --git a/security-admin/src/main/resources/META-INF/jpa_named_queries.xml b/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
index e54bfe2..ac34b07 100644
--- a/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
+++ b/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
@@ -413,6 +413,10 @@
 		<query>select obj from XXServiceVersionInfo obj where obj.serviceId = :serviceId</query>
 	</named-query>
 
+	<named-query name="XXServiceVersionInfo.getAllWithServiceNames">
+		<query>select obj, service.name from XXServiceVersionInfo obj, XXService service
where obj.serviceId = service.id</query>
+	</named-query>
+
 	<named-query name="XXServiceVersionInfo.findByServiceResourceId">
 		<query>
 			select obj from XXServiceVersionInfo obj where obj.serviceId in


Mime
View raw message