Search in sources :

Example 11 with XXServiceVersionInfo

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;
}
Also used : ServiceTags(org.apache.ranger.plugin.util.ServiceTags) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo)

Example 12 with XXServiceVersionInfo

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;
}
Also used : PList(org.apache.ranger.plugin.store.PList) ArrayList(java.util.ArrayList) XXPluginInfo(org.apache.ranger.entity.XXPluginInfo) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) RangerPluginInfo(org.apache.ranger.plugin.model.RangerPluginInfo)

Example 13 with XXServiceVersionInfo

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;
}
Also used : XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) XXServiceVersionInfoDao(org.apache.ranger.db.XXServiceVersionInfoDao)

Example 14 with XXServiceVersionInfo

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;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo)

Example 15 with XXServiceVersionInfo

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();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) XXServiceConfigMapDao(org.apache.ranger.db.XXServiceConfigMapDao) Date(java.util.Date) XXServiceConfigMap(org.apache.ranger.entity.XXServiceConfigMap) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) XXServiceVersionInfoDao(org.apache.ranger.db.XXServiceVersionInfoDao) Test(org.junit.Test)

Aggregations

XXServiceVersionInfo (org.apache.ranger.entity.XXServiceVersionInfo)16 XXService (org.apache.ranger.entity.XXService)14 Date (java.util.Date)8 XXServiceVersionInfoDao (org.apache.ranger.db.XXServiceVersionInfoDao)8 ArrayList (java.util.ArrayList)5 XXServiceDef (org.apache.ranger.entity.XXServiceDef)5 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)4 RangerService (org.apache.ranger.plugin.model.RangerService)4 Test (org.junit.Test)4 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)3 XXServiceConfigMapDao (org.apache.ranger.db.XXServiceConfigMapDao)3 XXServiceDao (org.apache.ranger.db.XXServiceDao)3 XXPortalUser (org.apache.ranger.entity.XXPortalUser)3 XXServiceConfigMap (org.apache.ranger.entity.XXServiceConfigMap)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 PList (org.apache.ranger.plugin.store.PList)2 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)2 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)2 JSONException (org.codehaus.jettison.json.JSONException)2