use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.
the class TagDBStore method getServiceTagsIfUpdated.
@Override
public ServiceTags getServiceTagsIfUpdated(String serviceName, Long lastKnownVersion) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TagDBStore.getServiceTagsIfUpdated(" + serviceName + ", " + lastKnownVersion + ")");
}
ServiceTags ret = null;
XXService xxService = daoManager.getXXService().findByName(serviceName);
if (xxService == null) {
LOG.error("Requested Service not found. serviceName=" + serviceName);
throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, RangerServiceNotFoundException.buildExceptionMsg(serviceName), false);
}
XXServiceVersionInfo serviceVersionInfoDbObj = daoManager.getXXServiceVersionInfo().findByServiceName(serviceName);
if (serviceVersionInfoDbObj == null) {
LOG.warn("serviceVersionInfo does not exist. name=" + serviceName);
}
if (lastKnownVersion == null || serviceVersionInfoDbObj == null || serviceVersionInfoDbObj.getTagVersion() == null || !lastKnownVersion.equals(serviceVersionInfoDbObj.getTagVersion())) {
ret = RangerServiceTagsCache.getInstance().getServiceTags(serviceName, xxService.getId(), this);
}
if (ret != null && lastKnownVersion != null && lastKnownVersion.equals(ret.getTagVersion())) {
// ServiceTags are not changed
ret = null;
}
if (LOG.isDebugEnabled()) {
RangerServiceTagsCache.getInstance().dump();
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== TagDBStore.getServiceTagsIfUpdated(" + serviceName + ", " + lastKnownVersion + "): count=" + ((ret == null || ret.getTags() == null) ? 0 : ret.getTags().size()));
}
return ret;
}
use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.
the class RangerPluginInfoService method searchRangerPluginInfo.
public PList<RangerPluginInfo> searchRangerPluginInfo(SearchFilter searchFilter) {
PList<RangerPluginInfo> retList = new PList<RangerPluginInfo>();
List<RangerPluginInfo> objList = new ArrayList<RangerPluginInfo>();
List<XXService> servicesWithTagService = daoManager.getXXService().getAllServicesWithTagService();
List<XXPluginInfo> xObjList = searchRangerObjects(searchFilter, searchFields, sortFields, retList);
List<Object[]> objectsList = null;
if (CollectionUtils.isNotEmpty(xObjList)) {
objectsList = daoManager.getXXServiceVersionInfo().getAllWithServiceNames();
}
for (XXPluginInfo xObj : xObjList) {
XXServiceVersionInfo xxServiceVersionInfo = null;
boolean hasAssociatedTagService = false;
if (CollectionUtils.isNotEmpty(objectsList)) {
for (Object[] objects : objectsList) {
if (objects.length == 2) {
if (xObj.getServiceName().equals(objects[1])) {
if (objects[0] instanceof XXServiceVersionInfo) {
xxServiceVersionInfo = (XXServiceVersionInfo) objects[0];
for (XXService service : servicesWithTagService) {
if (service.getName().equals(xObj.getServiceName())) {
hasAssociatedTagService = true;
break;
}
}
} else {
LOG.warn("Expected first object to be XXServiceVersionInfo, got " + objects[0]);
}
break;
}
} else {
LOG.warn("Expected 2 objects in the list returned by getAllWithServiceNames(), received " + objects.length);
}
}
}
RangerPluginInfo obj = populateViewObjectWithServiceVersionInfo(xObj, xxServiceVersionInfo, hasAssociatedTagService);
objList.add(obj);
}
retList.setList(objList);
return retList;
}
use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.
the class RangerServiceService method preDelete.
protected XXService preDelete(Long id) {
XXService ret = super.preDelete(id);
if (ret != null) {
XXServiceVersionInfoDao serviceVersionInfoDao = daoMgr.getXXServiceVersionInfo();
XXServiceVersionInfo serviceVersionInfo = serviceVersionInfoDao.findByServiceId(id);
if (serviceVersionInfo != null) {
serviceVersionInfoDao.remove(serviceVersionInfo.getId());
}
}
return ret;
}
use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.
the class RangerServiceServiceBase method mapEntityToViewBean.
@Override
protected V mapEntityToViewBean(V vObj, T xObj) {
XXServiceDef xServiceDef = daoMgr.getXXServiceDef().getById(xObj.getType());
XXService xTagService = xObj.getTagService() != null ? daoMgr.getXXService().getById(xObj.getTagService()) : null;
vObj.setType(xServiceDef.getName());
vObj.setGuid(xObj.getGuid());
vObj.setVersion(xObj.getVersion());
vObj.setName(xObj.getName());
vObj.setDescription(xObj.getDescription());
vObj.setTagService(xTagService != null ? xTagService.getName() : null);
XXServiceVersionInfo versionInfoObj = daoMgr.getXXServiceVersionInfo().findByServiceId(xObj.getId());
if (versionInfoObj != null) {
vObj.setPolicyVersion(versionInfoObj.getPolicyVersion());
vObj.setTagVersion(versionInfoObj.getTagVersion());
vObj.setPolicyUpdateTime(versionInfoObj.getPolicyUpdateTime());
vObj.setTagUpdateTime(versionInfoObj.getTagUpdateTime());
} else {
vObj.setPolicyVersion(xObj.getPolicyVersion());
vObj.setTagVersion(xObj.getTagVersion());
vObj.setPolicyUpdateTime(xObj.getPolicyUpdateTime());
vObj.setTagUpdateTime(xObj.getTagUpdateTime());
}
vObj.setIsEnabled(xObj.getIsenabled());
return vObj;
}
use of org.apache.ranger.entity.XXServiceVersionInfo 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