use of org.apache.ranger.view.RangerServiceDefList in project ranger by apache.
the class TestServiceDBStore method test17getServiceDefs.
@Test
public void test17getServiceDefs() throws Exception {
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
List<RangerServiceDef> serviceDefsList = new ArrayList<RangerServiceDef>();
RangerServiceDef serviceDef = rangerServiceDef();
serviceDefsList.add(serviceDef);
RangerServiceDefList serviceDefList = new RangerServiceDefList();
serviceDefList.setPageSize(0);
serviceDefList.setResultSize(1);
serviceDefList.setSortBy("asc");
serviceDefList.setSortType("1");
serviceDefList.setStartIndex(0);
serviceDefList.setTotalCount(10);
serviceDefList.setServiceDefs(serviceDefsList);
Mockito.when(serviceDefService.searchRangerServiceDefs(filter)).thenReturn(serviceDefList);
List<RangerServiceDef> dbServiceDef = serviceDBStore.getServiceDefs(filter);
Assert.assertNotNull(dbServiceDef);
Assert.assertEquals(dbServiceDef, serviceDefsList);
Assert.assertEquals(dbServiceDef.get(0), serviceDefsList.get(0));
Mockito.verify(serviceDefService).searchRangerServiceDefs(filter);
}
use of org.apache.ranger.view.RangerServiceDefList in project ranger by apache.
the class TestServiceDBStore method test18getPaginatedServiceDefs.
@Test
public void test18getPaginatedServiceDefs() throws Exception {
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
List<RangerServiceDef> serviceDefsList = new ArrayList<RangerServiceDef>();
RangerServiceDef serviceDef = rangerServiceDef();
serviceDefsList.add(serviceDef);
RangerServiceDefList serviceDefList = new RangerServiceDefList();
serviceDefList.setPageSize(0);
serviceDefList.setResultSize(1);
serviceDefList.setSortBy("asc");
serviceDefList.setSortType("1");
serviceDefList.setStartIndex(0);
serviceDefList.setTotalCount(10);
serviceDefList.setServiceDefs(serviceDefsList);
Mockito.when(serviceDefService.searchRangerServiceDefs(filter)).thenReturn(serviceDefList);
PList<RangerServiceDef> dbServiceDefList = serviceDBStore.getPaginatedServiceDefs(filter);
Assert.assertNotNull(dbServiceDefList);
Assert.assertEquals(dbServiceDefList.getList(), serviceDefList.getServiceDefs());
Mockito.verify(serviceDefService).searchRangerServiceDefs(filter);
}
use of org.apache.ranger.view.RangerServiceDefList in project ranger by apache.
the class TestServiceDBStore method test46getMetricByTypeContextenrichers.
@Test
public void test46getMetricByTypeContextenrichers() throws Exception {
String type = "contextenrichers";
RangerServiceDefList svcDefList = new RangerServiceDefList();
svcDefList.setTotalCount(10l);
Mockito.when(serviceDefService.searchRangerServiceDefs(Mockito.any(SearchFilter.class))).thenReturn(svcDefList);
serviceDBStore.getMetricByType(ServiceDBStore.METRIC_TYPE.getMetricTypeByName(type));
}
use of org.apache.ranger.view.RangerServiceDefList in project ranger by apache.
the class ServiceREST method getServiceDefs.
@GET
@Path("/definitions")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_SERVICE_DEFS + "\")")
public RangerServiceDefList getServiceDefs(@Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getServiceDefs()");
}
if (!bizUtil.hasModuleAccess(RangerConstants.MODULE_RESOURCE_BASED_POLICIES)) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_FORBIDDEN, "User is not having permissions on the " + RangerConstants.MODULE_RESOURCE_BASED_POLICIES + " module.", true);
}
RangerServiceDefList ret = null;
RangerPerfTracer perf = null;
PList<RangerServiceDef> paginatedSvcDefs = null;
SearchFilter filter = searchUtil.getSearchFilter(request, serviceDefService.sortFields);
String pageSource = null;
pageSource = request.getParameter("pageSource");
if (pageSource != null)
filter.setParam("pageSource", pageSource);
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getServiceDefs()");
}
paginatedSvcDefs = svcStore.getPaginatedServiceDefs(filter);
if (paginatedSvcDefs != null) {
ret = new RangerServiceDefList();
ret.setServiceDefs(paginatedSvcDefs.getList());
ret.setPageSize(paginatedSvcDefs.getPageSize());
ret.setResultSize(paginatedSvcDefs.getResultSize());
ret.setStartIndex(paginatedSvcDefs.getStartIndex());
ret.setTotalCount(paginatedSvcDefs.getTotalCount());
ret.setSortBy(paginatedSvcDefs.getSortBy());
ret.setSortType(paginatedSvcDefs.getSortType());
}
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("getServiceDefs() failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
} finally {
RangerPerfTracer.log(perf);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.getServiceDefs(): count=" + (ret == null ? 0 : ret.getListSize()));
}
return ret;
}
use of org.apache.ranger.view.RangerServiceDefList in project ranger by apache.
the class TestServiceREST method test7getServiceDefs.
@Test
public void test7getServiceDefs() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
Mockito.when(searchUtil.getSearchFilter(request, serviceDefService.sortFields)).thenReturn(filter);
List<RangerServiceDef> serviceDefsList = new ArrayList<RangerServiceDef>();
RangerServiceDef serviceDef = rangerServiceDef();
serviceDefsList.add(serviceDef);
PList<RangerServiceDef> serviceDefList = new PList<RangerServiceDef>();
serviceDefList.setPageSize(0);
serviceDefList.setResultSize(1);
serviceDefList.setSortBy("asc");
serviceDefList.setSortType("1");
serviceDefList.setStartIndex(0);
serviceDefList.setTotalCount(10);
serviceDefList.setList(serviceDefsList);
Mockito.when(bizUtil.hasModuleAccess(RangerConstants.MODULE_RESOURCE_BASED_POLICIES)).thenReturn(true);
Mockito.when(svcStore.getPaginatedServiceDefs(filter)).thenReturn(serviceDefList);
RangerServiceDefList dbRangerServiceDef = serviceREST.getServiceDefs(request);
Assert.assertNotNull(dbRangerServiceDef);
Mockito.verify(searchUtil).getSearchFilter(request, serviceDefService.sortFields);
Mockito.verify(svcStore).getPaginatedServiceDefs(filter);
}
Aggregations