Search in sources :

Example 1 with RangerServiceList

use of org.apache.ranger.view.RangerServiceList in project ranger by apache.

the class TestServiceREST method test63getServices.

@Test
public void test63getServices() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    PList<RangerService> paginatedSvcs = new PList<RangerService>();
    RangerService svc1 = rangerService();
    String userLoginID = "testuser";
    Long userId = 8L;
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    currentUserSession.setUserAdmin(false);
    XXPortalUser xXPortalUser = new XXPortalUser();
    xXPortalUser.setLoginId(userLoginID);
    xXPortalUser.setId(userId);
    currentUserSession.setXXPortalUser(xXPortalUser);
    VXUser loggedInUser = new VXUser();
    List<String> loggedInUserRole = new ArrayList<String>();
    loggedInUserRole.add(RangerConstants.ROLE_USER);
    loggedInUser.setId(8L);
    loggedInUser.setName("testuser");
    loggedInUser.setUserRoleList(loggedInUserRole);
    Map<String, String> configs = new HashMap<String, String>();
    configs.put("username", "servicemgr");
    configs.put("password", "servicemgr");
    configs.put("namenode", "servicemgr");
    configs.put("hadoop.security.authorization", "No");
    configs.put("hadoop.security.authentication", "Simple");
    configs.put("hadoop.security.auth_to_local", "");
    configs.put("dfs.datanode.kerberos.principal", "");
    configs.put("dfs.namenode.kerberos.principal", "");
    configs.put("dfs.secondary.namenode.kerberos.principal", "");
    configs.put("hadoop.rpc.protection", "Privacy");
    configs.put("commonNameForCertificate", "");
    RangerService svc2 = new RangerService();
    svc2.setId(9L);
    svc2.setConfigs(configs);
    svc2.setCreateTime(new Date());
    svc2.setDescription("service policy");
    svc2.setGuid("1427365526516_835_1");
    svc2.setIsEnabled(true);
    svc2.setName("YARN_1");
    svc2.setPolicyUpdateTime(new Date());
    svc2.setType("yarn");
    svc2.setUpdatedBy("Admin");
    svc2.setUpdateTime(new Date());
    List<RangerService> rangerServiceList = new ArrayList<RangerService>();
    rangerServiceList.add(svc1);
    rangerServiceList.add(svc2);
    paginatedSvcs.setList(rangerServiceList);
    SearchFilter filter = new SearchFilter();
    Mockito.when(searchUtil.getSearchFilter(request, svcService.sortFields)).thenReturn(filter);
    Mockito.when(svcStore.getPaginatedServices(filter)).thenReturn(paginatedSvcs);
    Mockito.when(xUserService.getXUserByUserName("testuser")).thenReturn(loggedInUser);
    RangerServiceList retServiceList = serviceREST.getServices(request);
    Assert.assertNotNull(retServiceList);
    Assert.assertNull(retServiceList.getServices().get(0).getDescription());
    Assert.assertTrue(retServiceList.getServices().get(0).getConfigs().isEmpty());
    Assert.assertNull(retServiceList.getServices().get(1).getDescription());
    Assert.assertTrue(retServiceList.getServices().get(1).getConfigs().isEmpty());
    Assert.assertEquals(retServiceList.getServices().get(0).getId(), Id);
    Assert.assertEquals(retServiceList.getServices().get(0).getName(), "HDFS_1");
    Assert.assertEquals(retServiceList.getServices().get(0).getType(), "1");
    Assert.assertEquals(retServiceList.getServices().get(1).getId(), svc2.getId());
    Assert.assertEquals(retServiceList.getServices().get(1).getName(), "YARN_1");
    Assert.assertEquals(retServiceList.getServices().get(1).getType(), "yarn");
}
Also used : PList(org.apache.ranger.plugin.store.PList) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceList(org.apache.ranger.view.RangerServiceList) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) Date(java.util.Date) UserSessionBase(org.apache.ranger.common.UserSessionBase) HttpServletRequest(javax.servlet.http.HttpServletRequest) XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 2 with RangerServiceList

use of org.apache.ranger.view.RangerServiceList in project ranger by apache.

the class ServiceDBStore method getServices.

@Override
public List<RangerService> getServices(SearchFilter filter) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.getServices()");
    }
    RangerServiceList serviceList = svcService.searchRangerServices(filter);
    predicateUtil.applyFilter(serviceList.getServices(), filter);
    List<RangerService> ret = serviceList.getServices();
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceDBStore.getServices()");
    }
    return ret;
}
Also used : RangerServiceList(org.apache.ranger.view.RangerServiceList) RangerService(org.apache.ranger.plugin.model.RangerService)

Example 3 with RangerServiceList

use of org.apache.ranger.view.RangerServiceList in project ranger by apache.

the class TestServiceDBStore method test44getMetricByTypePolicies.

@Test
public void test44getMetricByTypePolicies() throws Exception {
    String type = "policies";
    RangerServiceList svcList = new RangerServiceList();
    svcList.setTotalCount(10l);
    Mockito.when(svcService.searchRangerServices(Mockito.any(SearchFilter.class))).thenReturn(svcList);
    serviceDBStore.getMetricByType(ServiceDBStore.METRIC_TYPE.getMetricTypeByName(type));
}
Also used : RangerServiceList(org.apache.ranger.view.RangerServiceList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 4 with RangerServiceList

use of org.apache.ranger.view.RangerServiceList in project ranger by apache.

the class TestServiceDBStore method test25getPaginatedServiceDefs.

@Test
public void test25getPaginatedServiceDefs() throws Exception {
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    List<RangerService> serviceList = new ArrayList<RangerService>();
    RangerService rangerService = rangerService();
    serviceList.add(rangerService);
    RangerServiceList serviceListObj = new RangerServiceList();
    serviceListObj.setPageSize(0);
    serviceListObj.setResultSize(1);
    serviceListObj.setSortBy("asc");
    serviceListObj.setSortType("1");
    serviceListObj.setStartIndex(0);
    serviceListObj.setTotalCount(10);
    serviceListObj.setServices(serviceList);
    Mockito.when(svcService.searchRangerServices(filter)).thenReturn(serviceListObj);
    PList<RangerService> dbServiceList = serviceDBStore.getPaginatedServices(filter);
    Assert.assertNotNull(dbServiceList);
    Assert.assertEquals(dbServiceList.getList(), serviceListObj.getServices());
    Mockito.verify(svcService).searchRangerServices(filter);
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerServiceList(org.apache.ranger.view.RangerServiceList) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 5 with RangerServiceList

use of org.apache.ranger.view.RangerServiceList in project ranger by apache.

the class RangerServiceServiceBase method searchRangerServices.

public RangerServiceList searchRangerServices(SearchFilter searchFilter) {
    RangerServiceList retList = new RangerServiceList();
    int startIndex = searchFilter.getStartIndex();
    int pageSize = searchFilter.getMaxRows();
    searchFilter.setStartIndex(0);
    searchFilter.setMaxRows(Integer.MAX_VALUE);
    List<T> xSvcList = searchResources(searchFilter, searchFields, sortFields, retList);
    List<T> permittedServices = new ArrayList<T>();
    for (T xSvc : xSvcList) {
        if (bizUtil.hasAccess(xSvc, null)) {
            permittedServices.add(xSvc);
        }
    }
    if (!permittedServices.isEmpty()) {
        populatePageList(permittedServices, startIndex, pageSize, retList);
    }
    return retList;
}
Also used : ArrayList(java.util.ArrayList) RangerServiceList(org.apache.ranger.view.RangerServiceList)

Aggregations

RangerServiceList (org.apache.ranger.view.RangerServiceList)11 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 RangerService (org.apache.ranger.plugin.model.RangerService)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 VXString (org.apache.ranger.view.VXString)3 UserSessionBase (org.apache.ranger.common.UserSessionBase)2 VXUser (org.apache.ranger.view.VXUser)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)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 XXPortalUser (org.apache.ranger.entity.XXPortalUser)1 PList (org.apache.ranger.plugin.store.PList)1 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)1 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)1