use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class PatchForAtlasServiceDefUpdate_J10013 method updateAtlasServiceDef.
private void updateAtlasServiceDef() throws Exception {
String serviceDefName = EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME;
XXServiceDefDao serviceDefDao = daoMgr.getXXServiceDef();
XXServiceDef serviceDef = serviceDefDao.findByName(serviceDefName);
// if service-def named 'atlas' does not exist then no need to process this patch further.
if (serviceDef == null) {
LOG.info(serviceDefName + ": service-def not found. No patching is needed");
return;
}
// if older atlas service-def doesn't exist then no need to process this patch further.
if (!checkIfHasOlderServiceDef(serviceDef)) {
LOG.info("Older version of " + serviceDefName + " service-def not found. No patching is needed");
return;
}
String suffix = null;
for (int i = 1; true; i++) {
suffix = ".v" + i;
if (serviceDefDao.findByName(serviceDefName + suffix) == null) {
break;
}
}
String serviceDefNewName = serviceDefName + suffix;
LOG.info("Renaming service-def " + serviceDefName + " as " + serviceDefNewName);
RangerServiceDef dbAtlasServiceDef = svcDBStore.getServiceDefByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
if (EmbeddedServiceDefsUtil.instance().getTagServiceDefId() != -1) {
RangerServiceDef dbTagServiceDef;
try {
dbTagServiceDef = svcDBStore.getServiceDef(EmbeddedServiceDefsUtil.instance().getTagServiceDefId());
if (dbTagServiceDef != null) {
String prefix = serviceDefName + AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR;
String newPrefix = serviceDefNewName + AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR;
List<RangerServiceDef.RangerAccessTypeDef> svcDefAccessTypes = dbAtlasServiceDef.getAccessTypes();
List<RangerServiceDef.RangerAccessTypeDef> tagDefAccessTypes = dbTagServiceDef.getAccessTypes();
long itemIdOffset = serviceDef.getId() * (MAX_ACCESS_TYPES_IN_SERVICE_DEF + 1);
boolean updateNeeded = updateTagAccessTypeDefs(svcDefAccessTypes, tagDefAccessTypes, itemIdOffset, prefix, newPrefix);
if (updateNeeded) {
svcDBStore.updateServiceDef(dbTagServiceDef);
}
}
} catch (Exception e) {
LOG.error("updateAtlasServiceDef:" + serviceDef.getName() + "): could not find TAG ServiceDef.. ", e);
}
}
serviceDef.setName(serviceDefNewName);
serviceDef.setDisplayName(serviceDefNewName);
serviceDefDao.update(serviceDef);
LOG.info("Renamed service-def " + serviceDefName + " as " + serviceDefNewName);
XXServiceDao serviceDao = daoMgr.getXXService();
List<XXService> services = serviceDao.findByServiceDefId(serviceDef.getId());
if (CollectionUtils.isNotEmpty(services)) {
for (XXService service : services) {
String serviceName = service.getName();
String serviceNewName = serviceName + suffix;
LOG.info("Renaming service " + serviceName + " as " + serviceNewName);
if (serviceDao.findByName(serviceNewName) != null) {
LOG.warn("Another service named " + serviceNewName + " already exists. Not renaming " + serviceName);
continue;
}
service.setName(serviceNewName);
service.setDisplayName(serviceNewName);
serviceDao.update(service);
LOG.info("Renamed service " + serviceName + " as " + serviceNewName);
}
}
}
use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestServiceREST method test46exportPoliciesInCSV.
@Test
public void test46exportPoliciesInCSV() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
RangerPolicy rangerPolicy = rangerPolicy();
rangerPolicyList.add(rangerPolicy);
XXService xService = xService();
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
request.setAttribute("serviceType", "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop");
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
SearchFilter filter = new SearchFilter();
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(svcStore.getPolicies(filter)).thenReturn(rangerPolicyList);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(bizUtil.isKeyAdmin()).thenReturn(false);
Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn("admin");
Mockito.when(bizUtil.isAuditAdmin()).thenReturn(false);
Mockito.when(bizUtil.isAuditKeyAdmin()).thenReturn(false);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(daoManager.getXXService().findByName("HDFS_1-1-20150316062453")).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef().getById(xService.getType())).thenReturn(xServiceDef);
serviceREST.getPoliciesInCsv(request, response);
Mockito.verify(svcStore).getPoliciesInCSV(rangerPolicyList, response);
}
use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestServiceREST method test45exportPoliciesInJSON.
@Test
public void test45exportPoliciesInJSON() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
RangerPolicy rangerPolicy = rangerPolicy();
rangerPolicyList.add(rangerPolicy);
XXService xService = xService();
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
request.setAttribute("serviceType", "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop");
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
SearchFilter filter = new SearchFilter();
filter.setParam("zoneName", "zone1");
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(svcStore.getPolicies(filter)).thenReturn(rangerPolicyList);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(bizUtil.isKeyAdmin()).thenReturn(false);
Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn("admin");
Mockito.when(bizUtil.isAuditAdmin()).thenReturn(false);
Mockito.when(bizUtil.isAuditKeyAdmin()).thenReturn(false);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(daoManager.getXXService().findByName("HDFS_1-1-20150316062453")).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef().getById(xService.getType())).thenReturn(xServiceDef);
serviceREST.getPoliciesInJson(request, response, false);
Mockito.verify(svcStore).getPoliciesInJson(rangerPolicyList, response);
}
use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestServiceREST method test17updatePolicyFalse.
@Test
public void test17updatePolicyFalse() throws Exception {
RangerPolicy rangerPolicy = rangerPolicy();
String userName = "admin";
Set<String> userGroupsList = new HashSet<String>();
userGroupsList.add("group1");
userGroupsList.add("group2");
List<RangerAccessTypeDef> rangerAccessTypeDefList = new ArrayList<RangerServiceDef.RangerAccessTypeDef>();
RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
rangerAccessTypeDefObj.setLabel("Read");
rangerAccessTypeDefObj.setName("read");
rangerAccessTypeDefObj.setRbKeyLabel(null);
rangerAccessTypeDefList.add(rangerAccessTypeDefObj);
XXServiceDef xServiceDef = serviceDef();
XXService xService = xService();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
Mockito.when(validatorFactory.getPolicyValidator(svcStore)).thenReturn(policyValidator);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn(userName);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.findByName(Mockito.anyString())).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
RangerPolicy dbRangerPolicy = serviceREST.updatePolicy(rangerPolicy);
Assert.assertNull(dbRangerPolicy);
Mockito.verify(validatorFactory).getPolicyValidator(svcStore);
}
use of org.apache.ranger.db.XXServiceDao in project ranger by apache.
the class TestServiceREST method test48exportPoliciesInExcel.
/* @Test
public void test47WhenPolicyListIsEmpty() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
request.setAttribute("serviceType", "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop");
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
SearchFilter filter = new SearchFilter();
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(svcStore.getPolicies(filter)).thenReturn(rangerPolicyList);
Mockito.when(((Object) response).getStatus()).thenReturn(204);
serviceREST.getPoliciesInCsv(request, response);
Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
}
*/
@Test
public void test48exportPoliciesInExcel() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
RangerPolicy rangerPolicy = rangerPolicy();
rangerPolicyList.add(rangerPolicy);
XXService xService = xService();
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDef xServiceDef = serviceDef();
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
request.setAttribute("serviceType", "hdfs,hbase,hive,yarn,knox,storm,solr,kafka,nifi,atlas,sqoop");
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
SearchFilter filter = new SearchFilter();
Mockito.when(searchUtil.getSearchFilter(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(svcStore.getPolicies(filter)).thenReturn(rangerPolicyList);
Mockito.when(bizUtil.isAdmin()).thenReturn(true);
Mockito.when(bizUtil.isKeyAdmin()).thenReturn(false);
Mockito.when(bizUtil.getCurrentUserLoginId()).thenReturn("admin");
Mockito.when(bizUtil.isAuditAdmin()).thenReturn(false);
Mockito.when(bizUtil.isAuditKeyAdmin()).thenReturn(false);
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(daoManager.getXXService().findByName("HDFS_1-1-20150316062453")).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef().getById(xService.getType())).thenReturn(xServiceDef);
serviceREST.getPoliciesInExcel(request, response);
Mockito.verify(svcStore).getPoliciesInExcel(rangerPolicyList, response);
}
Aggregations