-
Notifications
You must be signed in to change notification settings - Fork 1k
RANGER-5406: Support export policies in a segmented manner #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ranger-2.3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,8 @@ public class SearchFilter { | |
| public static final String CREATE_TIME = "createTime"; // sort | ||
| public static final String UPDATE_TIME = "updateTime"; // sort | ||
| public static final String START_INDEX = "startIndex"; | ||
| public static final String BEGIN_INDEX = "beginIndex"; | ||
| public static final String OFFSET_INDEX = "offsetIndex"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think OFFSET is more meaning full than OFFSET_INDEX, offset is not index. What do you think ? |
||
| public static final String PAGE_SIZE = "pageSize"; | ||
| public static final String SORT_BY = "sortBy"; | ||
| public static final String RESOURCE_SIGNATURE = "resourceSignature:"; // search | ||
|
|
@@ -98,6 +100,8 @@ public class SearchFilter { | |
| private Map<String, String> params; | ||
| private int startIndex; | ||
| private int maxRows = Integer.MAX_VALUE; | ||
| private int beginIndex = -1; | ||
| private int offsetIndex = -1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you've added new fields to the SearchFilter class, don't forget to modify the copy constructor (public SearchFilter(SearchFilter other)) accordingly to ensure the new attributes are properly copied. |
||
| private boolean getCount = true; | ||
| private String sortBy; | ||
| private String sortType; | ||
|
|
@@ -182,6 +186,22 @@ public void setStartIndex(int startIndex) { | |
| this.startIndex = startIndex; | ||
| } | ||
|
|
||
| public int getBeginIndex() { | ||
| return beginIndex; | ||
| } | ||
|
|
||
| public void setBeginIndex(int beginIndex) { | ||
| this.beginIndex = beginIndex; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should validate that beginIndex >= 0. What’s your opinion? |
||
| } | ||
|
|
||
| public int getOffsetIndex() { | ||
| return offsetIndex; | ||
| } | ||
|
|
||
| public void setOffsetIndex(int offsetIndex) { | ||
| this.offsetIndex = offsetIndex; | ||
| } | ||
|
|
||
| public int getMaxRows() { | ||
| return maxRows; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2604,6 +2604,8 @@ private List<RangerPolicy> getAllFilteredPolicyList(SearchFilter filter, | |
| List<String> serviceTypeList = null; | ||
| List<String> serviceNameInServiceTypeList = new ArrayList<String>(); | ||
| boolean isServiceExists = false; | ||
| int begin = -1; | ||
| int offset = -1; | ||
|
|
||
| if (request.getParameter(PARAM_SERVICE_NAME) != null){ | ||
| serviceNames = request.getParameter(PARAM_SERVICE_NAME); | ||
|
|
@@ -2623,6 +2625,9 @@ private List<RangerPolicy> getAllFilteredPolicyList(SearchFilter filter, | |
| List<RangerPolicy> policyListByServiceName = new ArrayList<RangerPolicy>(); | ||
|
|
||
| if (filter != null) { | ||
| begin = filter.getBeginIndex(); | ||
| offset = filter.getOffsetIndex(); | ||
| LOG.info("==> beginIndex: " + begin + " offsetIndex: " + offset); | ||
| filter.setStartIndex(0); | ||
| filter.setMaxRows(Integer.MAX_VALUE); | ||
|
|
||
|
|
@@ -2690,6 +2695,12 @@ private List<RangerPolicy> getAllFilteredPolicyList(SearchFilter filter, | |
| policyLists.addAll(orderedPolicies.values()); | ||
| } | ||
| } | ||
| LOG.info("<==policyLists size:" + policyLists.size()); | ||
|
|
||
| if(begin>=0 && offset >0) { | ||
| policyLists = cutRangerPolicyList(policyLists, filter); | ||
| LOG.info("<==policyLists size after cut:" + policyLists.size()); | ||
| } | ||
| return policyLists; | ||
| } | ||
|
|
||
|
|
@@ -3889,6 +3900,45 @@ private RangerPolicyList toRangerPolicyList(List<RangerPolicy> policyList, Searc | |
| return ret; | ||
| } | ||
|
|
||
| private List<RangerPolicy> cutRangerPolicyList(List<RangerPolicy> policyList, SearchFilter filter) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggested name: |
||
| List<RangerPolicy> retList = null; | ||
| if (CollectionUtils.isNotEmpty(policyList)) { | ||
| int totalCount = policyList.size(); | ||
| int startIndex = filter.getBeginIndex(); | ||
| int pageSize = filter.getOffsetIndex(); | ||
| int toIndex = Math.min(startIndex + pageSize, totalCount); | ||
| LOG.info("==>totalCount: " + totalCount + " startIndex: " + startIndex + " pageSize: " +pageSize + " toIndex: " + toIndex); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid string concatenation, use |
||
| String sortType = filter.getSortType(); | ||
| String sortBy = filter.getSortBy(); | ||
|
|
||
| if (StringUtils.isNotEmpty(sortBy) && StringUtils.isNotEmpty(sortType)) { | ||
| // By default policyList is sorted by policyId in asc order, So handling only desc case. | ||
| if (SearchFilter.POLICY_ID.equalsIgnoreCase(sortBy)) { | ||
| if (SORT_ORDER.DESC.name().equalsIgnoreCase(sortType)) { | ||
| policyList.sort(this.getPolicyComparator(sortBy, sortType)); | ||
| } | ||
| } else if (SearchFilter.POLICY_NAME.equalsIgnoreCase(sortBy)) { | ||
| if (SORT_ORDER.ASC.name().equalsIgnoreCase(sortType)) { | ||
| policyList.sort(this.getPolicyComparator(sortBy, sortType)); | ||
| } else if (SORT_ORDER.DESC.name().equalsIgnoreCase(sortType)) { | ||
| policyList.sort(this.getPolicyComparator(sortBy, sortType)); | ||
| } else { | ||
| LOG.info("Invalid or Unsupported sortType : " + sortType); | ||
| } | ||
| } else { | ||
| LOG.info("Invalid or Unsupported sortBy property : " + sortBy); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid string concat, check all references. See: https://cwiki.apache.org/confluence/display/RANGER/Apache+Ranger+Java+Style+Guide |
||
| } | ||
| } | ||
|
|
||
| retList = new ArrayList<RangerPolicy>(); | ||
| for (int i = startIndex; i < toIndex; i++) { | ||
| retList.add(policyList.get(i)); | ||
| } | ||
|
|
||
| } | ||
| return retList; | ||
| } | ||
|
|
||
| private Comparator<RangerPolicy> getPolicyComparator(String sortBy, String sortType) { | ||
| Comparator<RangerPolicy> rangerPolComparator = (RangerPolicy me, RangerPolicy other) -> { | ||
| int ret = 0; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.