You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ranger.apache.org by Madhan Neethiraj <ma...@apache.org> on 2022/10/11 22:40:04 UTC
Re: Review Request 73694: RANGER-3500: Ranger policy list doesn't support sorting by field
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/73694/#review224784
-----------------------------------------------------------
agents-common/src/main/java/org/apache/ranger/plugin/store/AbstractPredicateUtil.java
Lines 69 (patched)
<https://reviews.apache.org/r/73694/#comment313581>
Instead of sorting followed by reversal, consider the following:
if (sorter != null) {
boolean isDesc = filter != null && "desc".equalsIgnoreCase(filter.getSortType());
Collections.sort(objList, isDesc ? new ReverseComparator(sorter) : sorter);
}
private static class ReverseComparator implements Comparator<RangerBaseModelObject> {
private final Comparator<RangerBaseModelObject> comparator;
ReverseComparator(Comparator<RangerBaseModelObject> comparator) {
this.comparator = comparator;
}
@Override
public int compare(RangerBaseModelObject o1, RangerBaseModelObject o2) {
return comparator.compare(o2, o1);
}
}
security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
Lines 2597 (patched)
<https://reviews.apache.org/r/73694/#comment313580>
Consider adding a copy-constructor in SearchFilter and use it here, so that other fields (startIndex/maxRows/getCount) will be copied as well.
SearchFilter searchFilter = new SearchFilter(filter);
// SearchFilter.java
public SearchFilter() {
this((Map<String, String>) null);
}
public SearchFilter(SearchFilter other) {
if (other != null) {
setParams(other.params != null ? new HashMap<>(other.params) : null);
setStartIndex(other.startIndex);
setMaxRows(other.maxRows);
setGetCount(other.getCount);
setSortBy(other.sortBy);
setSortType(other.sortType);
} else {
setParams(null);
}
}
- Madhan Neethiraj
On Sept. 29, 2022, 2:37 a.m., Xuze Yang wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/73694/
> -----------------------------------------------------------
>
> (Updated Sept. 29, 2022, 2:37 a.m.)
>
>
> Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Mahesh Bandal, Pradeep Agrawal, Ramesh Mani, Sailaja Polavarapu, Vishal Suvagia, and Velmurugan Periasamy.
>
>
> Bugs: RANGER-3500
> https://issues.apache.org/jira/browse/RANGER-3500
>
>
> Repository: ranger
>
>
> Description
> -------
>
> modify the getServicePolicies() method to support sorting by field and sortType(i.e. asc or desc). The changes are as following:
> 1. Add sortBy and sortType to searchFilter
> 2. Support sorting by sortType("desc" means in decreasing order, otherwise in increasing order)
> 3. Delete a redundant line of code
>
>
> Diffs
> -----
>
> agents-common/src/main/java/org/apache/ranger/plugin/store/AbstractPredicateUtil.java 38d6b03
> security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java f58dcd2
>
>
> Diff: https://reviews.apache.org/r/73694/diff/2/
>
>
> Testing
> -------
>
> 1. compile and package the code
> 2. deploy ranger
> 3. generate hdfs policies and get the hdfs policyList via postman using url like "http://192.168.0.12:6080/service/plugins/policies/service/2?sortBy=policyName&sortType=desc&serviceName=default-Hdfs"
> 4. the return policyList is sorted according our specified sortBy and sortType
>
>
> File Attachments
> ----------------
>
> 0002-RANGER-3500-Ranger-policy-list-doesn-t-support-sorti.patch
> https://reviews.apache.org/media/uploaded/files/2022/09/29/61ba9494-1dc8-4b67-80ed-44c7e9f313a1__0002-RANGER-3500-Ranger-policy-list-doesn-t-support-sorti.patch
>
>
> Thanks,
>
> Xuze Yang
>
>
Re: Review Request 73694: RANGER-3500: Ranger policy list doesn't support sorting by field
Posted by Xuze Yang <xu...@163.com>.
> On 十月 11, 2022, 10:40 p.m., Madhan Neethiraj wrote:
> > security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
> > Lines 2597 (patched)
> > <https://reviews.apache.org/r/73694/diff/2/?file=2270291#file2270291line2597>
> >
> > Consider adding a copy-constructor in SearchFilter and use it here, so that other fields (startIndex/maxRows/getCount) will be copied as well.
> >
> > SearchFilter searchFilter = new SearchFilter(filter);
> >
> >
> >
> > // SearchFilter.java
> > public SearchFilter() {
> > this((Map<String, String>) null);
> > }
> >
> > public SearchFilter(SearchFilter other) {
> > if (other != null) {
> > setParams(other.params != null ? new HashMap<>(other.params) : null);
> > setStartIndex(other.startIndex);
> > setMaxRows(other.maxRows);
> > setGetCount(other.getCount);
> > setSortBy(other.sortBy);
> > setSortType(other.sortType);
> > } else {
> > setParams(null);
> > }
> > }
Thank you for your modification comments. I have made changes according to your modification comments. The same verification has been done in the environment, and everything works well
- Xuze
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/73694/#review224784
-----------------------------------------------------------
On 九月 29, 2022, 2:37 a.m., Xuze Yang wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/73694/
> -----------------------------------------------------------
>
> (Updated 九月 29, 2022, 2:37 a.m.)
>
>
> Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Mahesh Bandal, Pradeep Agrawal, Ramesh Mani, Sailaja Polavarapu, Vishal Suvagia, and Velmurugan Periasamy.
>
>
> Bugs: RANGER-3500
> https://issues.apache.org/jira/browse/RANGER-3500
>
>
> Repository: ranger
>
>
> Description
> -------
>
> modify the getServicePolicies() method to support sorting by field and sortType(i.e. asc or desc). The changes are as following:
> 1. Add sortBy and sortType to searchFilter
> 2. Support sorting by sortType("desc" means in decreasing order, otherwise in increasing order)
> 3. Delete a redundant line of code
>
>
> Diffs
> -----
>
> agents-common/src/main/java/org/apache/ranger/plugin/store/AbstractPredicateUtil.java 38d6b03
> agents-common/src/main/java/org/apache/ranger/plugin/util/SearchFilter.java c5f13b5
> security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java fdead07
>
>
> Diff: https://reviews.apache.org/r/73694/diff/3/
>
>
> Testing
> -------
>
> 1. compile and package the code
> 2. deploy ranger
> 3. generate hdfs policies and get the hdfs policyList via postman using url like "http://192.168.0.12:6080/service/plugins/policies/service/2?sortBy=policyName&sortType=desc&serviceName=default-Hdfs"
> 4. the return policyList is sorted according our specified sortBy and sortType
>
>
> File Attachments
> ----------------
>
> 0002-RANGER-3500-Ranger-policy-list-doesn-t-support-sorti.patch
> https://reviews.apache.org/media/uploaded/files/2022/09/29/61ba9494-1dc8-4b67-80ed-44c7e9f313a1__0002-RANGER-3500-Ranger-policy-list-doesn-t-support-sorti.patch
>
>
> Thanks,
>
> Xuze Yang
>
>