use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestServiceREST method test34countServices.
@Test
public void test34countServices() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
PList<RangerService> ret = Mockito.mock(PList.class);
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(svcStore.getPaginatedServices(filter)).thenReturn(ret);
Long data = serviceREST.countServices(request);
Assert.assertNotNull(data);
Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields);
Mockito.verify(svcStore).getPaginatedServices(filter);
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestServiceREST method test22getServicePoliciesById.
@Test
public void test22getServicePoliciesById() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
RangerPolicy rangerPolicy = rangerPolicy();
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
RangerPolicyList dbRangerPolicy = serviceREST.getServicePolicies(rangerPolicy.getId(), request);
Assert.assertNotNull(dbRangerPolicy);
Mockito.verify(searchUtil).getSearchFilter(request, policyService.sortFields);
Mockito.verify(svcStore).getServicePolicies(Id, filter);
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class TestServiceREST method test26getServices.
@Test
public void test26getServices() throws Exception {
List<RangerService> ret = new ArrayList<RangerService>();
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
Mockito.when(svcStore.getServices(filter)).thenReturn(ret);
List<RangerService> dbRangerService = serviceREST.getServices(filter);
Assert.assertNotNull(dbRangerService);
Mockito.verify(svcStore).getServices(filter);
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class MetricUtil method getAuditsCount.
private VXMetricServiceCount getAuditsCount(int accessResult, Date startDate, Date endDate) throws Exception {
long totalCountOfAudits = 0;
SearchFilter filter = new SearchFilter();
filter.setStartIndex(0);
Map<String, Long> servicesRepoType = new HashMap<String, Long>();
VXMetricServiceCount vXMetricServiceCount = new VXMetricServiceCount();
PList<RangerServiceDef> paginatedSvcDefs = svcStore.getPaginatedServiceDefs(filter);
Iterable<RangerServiceDef> repoTypeGet = paginatedSvcDefs.getList();
for (Object repo : repoTypeGet) {
RangerServiceDef rangerServiceDefObj = (RangerServiceDef) repo;
long id = rangerServiceDefObj.getId();
String serviceRepoName = rangerServiceDefObj.getName();
SearchCriteria searchCriteriaWithType = new SearchCriteria();
searchCriteriaWithType.getParamList().put("repoType", id);
searchCriteriaWithType.getParamList().put("accessResult", accessResult);
searchCriteriaWithType.addParam("startDate", startDate);
searchCriteriaWithType.addParam("endDate", endDate);
VXAccessAuditList vXAccessAuditListwithType = assetMgr.getAccessLogs(searchCriteriaWithType);
long toltalCountOfRepo = vXAccessAuditListwithType.getTotalCount();
if (toltalCountOfRepo != 0) {
servicesRepoType.put(serviceRepoName, toltalCountOfRepo);
totalCountOfAudits += toltalCountOfRepo;
}
}
vXMetricServiceCount.setServiceBasedCountList(servicesRepoType);
vXMetricServiceCount.setTotalCount(totalCountOfAudits);
return vXMetricServiceCount;
}
use of org.apache.ranger.plugin.util.SearchFilter in project ranger by apache.
the class AssetREST method searchXResources.
@GET
@Path("/resources")
@Produces({ "application/xml", "application/json" })
public VXResourceList searchXResources(@Context HttpServletRequest request) {
if (logger.isDebugEnabled()) {
logger.debug("==> AssetREST.searchXResources()");
}
VXResourceList ret = new VXResourceList();
SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, xResourceService.sortFields);
List<RangerPolicy> policies = serviceREST.getPolicies(filter);
if (policies != null) {
List<VXResource> resources = new ArrayList<VXResource>();
for (RangerPolicy policy : policies) {
RangerService service = serviceREST.getServiceByName(policy.getService());
VXResource resource = serviceUtil.toVXResource(policy, service);
if (resource != null) {
resources.add(resource);
}
}
ret.setVXResources(resources);
}
if (logger.isDebugEnabled()) {
logger.debug("<== AssetREST.searchXResources(): count=" + ret.getResultSize());
}
return ret;
}
Aggregations