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");
}
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;
}
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));
}
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);
}
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;
}
Aggregations