ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [2/7] incubator-ranger git commit: RANGER-554: Pagination support in KMS Keys listing page
Date Thu, 18 Jun 2015 02:31:18 GMT
RANGER-554: Pagination support in KMS Keys listing page

Signed-off-by: sneethiraj <sneethir@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/9a0330cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/9a0330cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/9a0330cc

Branch: refs/heads/tag-policy
Commit: 9a0330ccef16a7cf10435f4592fc5bda0798afe2
Parents: aa695b1
Author: Velmurugan Periasamy <vel@apache.org>
Authored: Mon Jun 15 19:41:56 2015 -0400
Committer: sneethiraj <sneethir@apache.org>
Committed: Mon Jun 15 22:56:29 2015 -0400

----------------------------------------------------------------------
 .../java/org/apache/ranger/biz/KmsKeyMgr.java   | 52 +++++++++++++++-----
 .../java/org/apache/ranger/rest/XKeyREST.java   |  3 +-
 2 files changed, 42 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/9a0330cc/security-admin/src/main/java/org/apache/ranger/biz/KmsKeyMgr.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/KmsKeyMgr.java b/security-admin/src/main/java/org/apache/ranger/biz/KmsKeyMgr.java
index 7854f4b..551ec2e 100755
--- a/security-admin/src/main/java/org/apache/ranger/biz/KmsKeyMgr.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/KmsKeyMgr.java
@@ -26,6 +26,7 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -100,7 +101,7 @@ public class KmsKeyMgr {
 	RangerDaoManagerBase rangerDaoManagerBase;
 	
 	@SuppressWarnings("unchecked")
-	public VXKmsKeyList searchKeys(String repoName) throws Exception{
+	public VXKmsKeyList searchKeys(HttpServletRequest request, String repoName) throws Exception{
 		String providers[] = null;
 		try {
 			providers = getKMSURL(repoName);
@@ -147,6 +148,16 @@ public class KmsKeyMgr {
 				Gson gson = new GsonBuilder().create();
 				logger.debug(" Search Key RESPONSE: [" + response + "]");
 				keys = gson.fromJson(response, List.class);
+				Collections.sort(keys);
+				VXKmsKeyList vxKmsKeyList2 = new VXKmsKeyList();
+				List<VXKmsKey> vXKeys2 = new ArrayList<VXKmsKey>();
+				for (String name : keys) {
+					VXKmsKey key = new VXKmsKey();
+					key.setName(name);
+					vXKeys2.add(key);
+				}
+				vxKmsKeyList2.setVXKeys(vXKeys2);
+				vxKmsKeyList = getFilteredKeyList(request, vxKmsKeyList2);
 				break;
 			} catch (Exception e) {
 				if (e instanceof UniformInterfaceException || i == providers.length - 1)
@@ -155,15 +166,35 @@ public class KmsKeyMgr {
 					continue;
 			}
 		}
-		if (keys != null && keys.size() > 0) {
-			for (String name : keys) {
-				VXKmsKey key = getKeyFromUri(connProvider, name, isKerberos, repoName);
-				vXKeys.add(key);
+		//details
+		if (vxKmsKeyList != null && vxKmsKeyList.getVXKeys() != null && vxKmsKeyList.getVXKeys().size()
> 0) {
+			List<VXKmsKey> lstKMSKey = vxKmsKeyList.getVXKeys();
+			int startIndex=restErrorUtil.parseInt(
+					request.getParameter("startIndex"), 0,
+					"Invalid value for parameter startIndex",
+					MessageEnums.INVALID_INPUT_DATA, null, "startIndex");
+			startIndex = startIndex < 0 ? 0 : startIndex;
+			
+			int pageSize=restErrorUtil.parseInt(
+					request.getParameter("pageSize"), 0,
+					"Invalid value for parameter pageSize",
+					MessageEnums.INVALID_INPUT_DATA, null, "pageSize");
+			pageSize = pageSize < 0 ? 0 : pageSize;			
+			
+			vxKmsKeyList.setResultSize(lstKMSKey.size());
+			vxKmsKeyList.setTotalCount(lstKMSKey.size());
+			if((startIndex+pageSize) <= lstKMSKey.size()){
+				lstKMSKey = lstKMSKey.subList(startIndex, (startIndex+pageSize));}
+			else{
+				startIndex = startIndex >= lstKMSKey.size() ? 0 : startIndex;
+				lstKMSKey = lstKMSKey.subList(startIndex, lstKMSKey.size());
 			}
-			vxKmsKeyList.setResultSize(vXKeys.size());
-			vxKmsKeyList.setTotalCount(vXKeys.size());
-			vxKmsKeyList.setStartIndex(0);
-			vxKmsKeyList.setPageSize(vXKeys.size());
+			for (VXKmsKey kmsKey : lstKMSKey) {
+				VXKmsKey key = getKeyFromUri(connProvider, kmsKey.getName(), isKerberos, repoName);
+				vXKeys.add(key);
+			}			
+			vxKmsKeyList.setStartIndex(startIndex);
+			vxKmsKeyList.setPageSize(pageSize);
 		}
 		vxKmsKeyList.setVXKeys(vXKeys);
 		return vxKmsKeyList;
@@ -540,7 +571,7 @@ public class KmsKeyMgr {
 	public VXKmsKeyList getFilteredKeyList(HttpServletRequest request, VXKmsKeyList vXKmsKeyList){
 		List<SortField> sortFields = new ArrayList<SortField>();
 		sortFields.add(new SortField(KeySearchFilter.KEY_NAME, KeySearchFilter.KEY_NAME));
-		
+
 		KeySearchFilter filter = getKeySearchFilter(request, sortFields);
 		
 		Predicate pred = getPredicate(filter);
@@ -631,7 +662,6 @@ public class KmsKeyMgr {
 		String sortBy = restErrorUtil.validateString(request.getParameter(KeySearchFilter.SORT_BY),
 				StringUtil.VALIDATION_ALPHA, "Invalid value for parameter sortBy", MessageEnums.INVALID_INPUT_DATA,
 				null, KeySearchFilter.SORT_BY);
-
 		boolean sortSet = false;
 		if (!StringUtils.isEmpty(sortBy)) {
 			for (SortField sortField : sortFields) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/9a0330cc/security-admin/src/main/java/org/apache/ranger/rest/XKeyREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/XKeyREST.java b/security-admin/src/main/java/org/apache/ranger/rest/XKeyREST.java
index 7845b86..1c0f9fc 100755
--- a/security-admin/src/main/java/org/apache/ranger/rest/XKeyREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/XKeyREST.java
@@ -79,8 +79,7 @@ public class XKeyREST {
 	public VXKmsKeyList searchKeys(@Context HttpServletRequest request, @QueryParam("provider")
String provider) {
 		VXKmsKeyList vxKmsKeyList = new VXKmsKeyList();
 		try{
-			vxKmsKeyList = keyMgr.searchKeys(provider);
-			vxKmsKeyList = keyMgr.getFilteredKeyList(request, vxKmsKeyList);
+			vxKmsKeyList = keyMgr.searchKeys(request, provider);
 		}catch(Exception e){
 			handleError(e);						
 		}


Mime
View raw message