use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestTagREST method test54getSecureServiceTagsIfUpdatedIsKeyAdminFalse.
@Test
public void test54getSecureServiceTagsIfUpdatedIsKeyAdminFalse() {
boolean isAdmin = false;
boolean isKeyAdmin = false;
boolean isAllowed = true;
ServiceTags oldServiceTag = new ServiceTags();
oldServiceTag.setServiceName(serviceName);
oldServiceTag.setTagVersion(5L);
XXService xService = new XXService();
xService.setId(id);
xService.setName(serviceName);
xService.setType(5L);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setId(id);
xServiceDef.setVersion(5L);
xServiceDef.setImplclassname("org.apache.ranger.services.kms.RangerServiceKMS");
RangerService rangerService = new RangerService();
rangerService.setId(id);
rangerService.setName(serviceName);
XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDefDao xXServiceDefDao = Mockito.mock(XXServiceDefDao.class);
Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
try {
Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
} catch (Exception e) {
}
Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
try {
Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
} catch (Exception e) {
}
ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, null);
Assert.assertNotNull(result.getServiceName());
Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
Mockito.verify(bizUtil).isAdmin();
Mockito.verify(bizUtil).isKeyAdmin();
Mockito.verify(daoManager).getXXService();
Mockito.verify(xXServiceDao).findByName(serviceName);
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(xXServiceDefDao).getById(xService.getType());
try {
Mockito.verify(svcStore).getServiceByName(serviceName);
} catch (Exception e) {
}
Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
try {
Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
} catch (Exception e) {
}
}
use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestTagREST method test52getSecureServiceTagsIfUpdatedIsKeyAdminTrue.
@Test
public void test52getSecureServiceTagsIfUpdatedIsKeyAdminTrue() {
boolean isAdmin = false;
boolean isKeyAdmin = true;
ServiceTags oldServiceTag = new ServiceTags();
oldServiceTag.setServiceName(serviceName);
oldServiceTag.setTagVersion(5L);
XXService xService = new XXService();
xService.setId(id);
xService.setName(serviceName);
xService.setType(5L);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setId(id);
xServiceDef.setVersion(5L);
xServiceDef.setImplclassname("org.apache.ranger.services.kms.RangerServiceKMS");
RangerService rangerService = new RangerService();
rangerService.setId(id);
rangerService.setName(serviceName);
XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
XXServiceDefDao xXServiceDefDao = Mockito.mock(XXServiceDefDao.class);
Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
try {
Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
} catch (Exception e) {
}
try {
Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
} catch (Exception e) {
}
ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, null);
Assert.assertNotNull(result.getServiceName());
Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
Mockito.verify(bizUtil).isAdmin();
Mockito.verify(bizUtil).isKeyAdmin();
Mockito.verify(daoManager).getXXService();
Mockito.verify(xXServiceDao).findByName(serviceName);
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(xXServiceDefDao).getById(xService.getType());
try {
Mockito.verify(svcStore).getServiceByName(serviceName);
} catch (Exception e) {
}
try {
Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
} catch (Exception e) {
}
}
use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class PatchForAtlasServiceDefUpdate_J10013 method updateAtlasServiceDef.
private void updateAtlasServiceDef() {
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);
serviceDef.setName(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);
serviceDao.update(service);
LOG.info("Renamed service " + serviceName + " as " + serviceNewName);
}
}
}
use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestRangerServiceService method test8GetTransactionLogDelete.
@Test
public void test8GetTransactionLogDelete() {
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
RangerService rangerService = rangerService();
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.findByName(rangerService.getType())).thenReturn(xServiceDef);
List<XXTrxLog> dbXXTrxLogList = serviceService.getTransactionLog(rangerService, 3);
Assert.assertNotNull(dbXXTrxLogList);
}
use of org.apache.ranger.db.XXServiceDefDao in project ranger by apache.
the class TestRangerServiceService method test4GetPopulatedViewObject.
@Test
public void test4GetPopulatedViewObject() {
XXServiceConfigMapDao xServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXService xService = xService();
String name = "fdfdfds";
List<XXServiceConfigMap> svcConfigMapList = new ArrayList<XXServiceConfigMap>();
XXServiceConfigMap xConfMap = new XXServiceConfigMap();
xConfMap.setAddedByUserId(null);
xConfMap.setConfigkey(name);
xConfMap.setConfigvalue(name);
xConfMap.setCreateTime(new Date());
xConfMap.setServiceId(null);
xConfMap.setUpdatedByUserId(null);
xConfMap.setUpdateTime(new Date());
svcConfigMapList.add(xConfMap);
XXPortalUser tUser = new XXPortalUser();
tUser.setAddedByUserId(userId);
tUser.setCreateTime(new Date());
tUser.setEmailAddress("test@gmail.com");
tUser.setFirstName(name);
tUser.setId(userId);
tUser.setLastName(name);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setAddedByUserId(userId);
xServiceDef.setCreateTime(new Date());
xServiceDef.setDescription("test");
xServiceDef.setGuid("1427365526516_835_0");
xServiceDef.setId(userId);
XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
XXServiceVersionInfo serviceVersionInfo = new XXServiceVersionInfo();
serviceVersionInfo.setServiceId(xService.getId());
serviceVersionInfo.setPolicyVersion(xService.getPolicyVersion());
serviceVersionInfo.setPolicyUpdateTime(xService.getPolicyUpdateTime());
serviceVersionInfo.setTagVersion(xService.getTagVersion());
serviceVersionInfo.setTagUpdateTime(xService.getTagUpdateTime());
Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
Mockito.when(xServiceVersionInfoDao.findByServiceId(xService.getId())).thenReturn(serviceVersionInfo);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(tUser);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xServiceConfigMapDao);
Mockito.when(xServiceConfigMapDao.findByServiceId(xService.getId())).thenReturn(svcConfigMapList);
RangerService dbService = serviceService.getPopulatedViewObject(xService);
Assert.assertNotNull(dbService);
Assert.assertEquals(userId, dbService.getId());
Assert.assertEquals(xService.getAddedByUserId(), dbService.getId());
Assert.assertEquals(xService.getId(), dbService.getId());
Assert.assertEquals(xService.getDescription(), dbService.getDescription());
Assert.assertEquals(xService.getGuid(), dbService.getGuid());
Assert.assertEquals(xService.getName(), dbService.getName());
Assert.assertEquals(xService.getPolicyUpdateTime(), dbService.getPolicyUpdateTime());
Assert.assertEquals(xService.getPolicyVersion(), dbService.getPolicyVersion());
Assert.assertEquals(xService.getVersion(), dbService.getVersion());
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(daoManager).getXXServiceConfigMap();
}
Aggregations