Search in sources :

Example 6 with RangerServiceDefList

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);
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) Test(org.junit.Test)

Example 7 with RangerServiceDefList

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);
}
Also used : RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) Test(org.junit.Test)

Example 8 with RangerServiceDefList

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));
}
Also used : SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXString(org.apache.ranger.view.VXString) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) Test(org.junit.Test)

Example 9 with RangerServiceDefList

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;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXString(org.apache.ranger.view.VXString) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 10 with RangerServiceDefList

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PList(org.apache.ranger.plugin.store.PList) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceDefList(org.apache.ranger.view.RangerServiceDefList) Test(org.junit.Test)

Aggregations

RangerServiceDefList (org.apache.ranger.view.RangerServiceDefList)12 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)8 Test (org.junit.Test)8 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)6 ArrayList (java.util.ArrayList)5 VXString (org.apache.ranger.view.VXString)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 PList (org.apache.ranger.plugin.store.PList)2 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1