Search in sources :

Example 1 with XXServiceVersionInfo

use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.

the class TagDBStore method getServiceTags.

@Override
public ServiceTags getServiceTags(String serviceName) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TagDBStore.getServiceTags(" + serviceName + ")");
    }
    ServiceTags ret = null;
    XXService xxService = daoManager.getXXService().findByName(serviceName);
    if (xxService == null) {
        throw new Exception("service does not exist. name=" + serviceName);
    }
    XXServiceVersionInfo serviceVersionInfoDbObj = daoManager.getXXServiceVersionInfo().findByServiceName(serviceName);
    if (serviceVersionInfoDbObj == null) {
        LOG.warn("serviceVersionInfo does not exist for service [" + serviceName + "]");
    }
    RangerServiceDef serviceDef = svcStore.getServiceDef(xxService.getType());
    if (serviceDef == null) {
        throw new Exception("service-def does not exist. id=" + xxService.getType());
    }
    RangerTagDBRetriever tagDBRetriever = new RangerTagDBRetriever(daoManager, xxService);
    Map<Long, RangerTagDef> tagDefMap = tagDBRetriever.getTagDefs();
    Map<Long, RangerTag> tagMap = tagDBRetriever.getTags();
    List<RangerServiceResource> resources = tagDBRetriever.getServiceResources();
    List<RangerTagResourceMap> tagResourceMaps = tagDBRetriever.getTagResourceMaps();
    Map<Long, List<Long>> resourceToTagIds = new HashMap<Long, List<Long>>();
    if (CollectionUtils.isNotEmpty(tagResourceMaps)) {
        Long resourceId = null;
        List<Long> tagIds = null;
        for (RangerTagResourceMap tagResourceMap : tagResourceMaps) {
            if (!tagResourceMap.getResourceId().equals(resourceId)) {
                if (resourceId != null) {
                    resourceToTagIds.put(resourceId, tagIds);
                }
                resourceId = tagResourceMap.getResourceId();
                tagIds = new ArrayList<Long>();
            }
            tagIds.add(tagResourceMap.getTagId());
        }
        if (resourceId != null) {
            resourceToTagIds.put(resourceId, tagIds);
        }
    }
    ret = new ServiceTags();
    ret.setServiceName(xxService.getName());
    ret.setTagVersion(serviceVersionInfoDbObj == null ? null : serviceVersionInfoDbObj.getTagVersion());
    ret.setTagUpdateTime(serviceVersionInfoDbObj == null ? null : serviceVersionInfoDbObj.getTagUpdateTime());
    ret.setTagDefinitions(tagDefMap);
    ret.setTags(tagMap);
    ret.setServiceResources(resources);
    ret.setResourceToTagIds(resourceToTagIds);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== TagDBStore.getServiceTags(" + serviceName + ")");
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) RangerServiceNotFoundException(org.apache.ranger.plugin.util.RangerServiceNotFoundException) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) ArrayList(java.util.ArrayList) List(java.util.List) PList(org.apache.ranger.plugin.store.PList) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo)

Example 2 with XXServiceVersionInfo

use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.

the class TestRangerServiceService method test5GetAllServices.

@Test
public void test5GetAllServices() {
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXServiceConfigMapDao xServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    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);
    List<XXService> xServiceList = new ArrayList<XXService>();
    XXService xService = xService();
    xServiceList.add(xService);
    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.getXXService()).thenReturn(xServiceDao);
    Mockito.when(xServiceDao.getAll()).thenReturn(xServiceList);
    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);
    List<RangerService> dbServiceList = serviceService.getAllServices();
    Assert.assertNotNull(dbServiceList);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(daoManager).getXXServiceConfigMap();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) XXServiceDao(org.apache.ranger.db.XXServiceDao) 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)

Example 3 with XXServiceVersionInfo

use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.

the class TestRangerServiceService method test3PopulateViewBean.

@Test
public void test3PopulateViewBean() {
    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.populateViewBean(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)

Example 4 with XXServiceVersionInfo

use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.

the class TestRangerServiceServiceBase method test2mapEntityToViewBean.

@Test
public void test2mapEntityToViewBean() {
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
    RangerService rangerService = rangerService();
    XXService service = service();
    XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
    XXServiceVersionInfo serviceVersionInfo = new XXServiceVersionInfo();
    serviceVersionInfo.setServiceId(service.getId());
    serviceVersionInfo.setPolicyVersion(service.getPolicyVersion());
    serviceVersionInfo.setPolicyUpdateTime(service.getPolicyUpdateTime());
    serviceVersionInfo.setTagVersion(service.getTagVersion());
    serviceVersionInfo.setPolicyUpdateTime(service.getTagUpdateTime());
    Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
    Mockito.when(xServiceVersionInfoDao.findByServiceId(service.getId())).thenReturn(serviceVersionInfo);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getById(service.getType())).thenReturn(xServiceDef);
    RangerService dbRangerService = rangerServiceService.mapEntityToViewBean(rangerService, service);
    Assert.assertNotNull(dbRangerService);
    Assert.assertEquals(dbRangerService, rangerService);
    Assert.assertEquals(dbRangerService.getDescription(), rangerService.getDescription());
    Assert.assertEquals(dbRangerService.getGuid(), rangerService.getGuid());
    Assert.assertEquals(dbRangerService.getName(), rangerService.getName());
    Assert.assertEquals(dbRangerService.getId(), rangerService.getId());
    Assert.assertEquals(dbRangerService.getVersion(), rangerService.getVersion());
    Assert.assertEquals(dbRangerService.getType(), rangerService.getType());
    Mockito.verify(daoManager).getXXServiceDef();
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) 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)

Example 5 with XXServiceVersionInfo

use of org.apache.ranger.entity.XXServiceVersionInfo in project ranger by apache.

the class ServiceDBStore method getServicePoliciesIfUpdated.

@Override
public ServicePolicies getServicePoliciesIfUpdated(String serviceName, Long lastKnownVersion) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + ")");
    }
    ServicePolicies ret = null;
    XXService serviceDbObj = daoMgr.getXXService().findByName(serviceName);
    if (serviceDbObj == null) {
        throw new Exception("service does not exist. name=" + serviceName);
    }
    XXServiceVersionInfo serviceVersionInfoDbObj = daoMgr.getXXServiceVersionInfo().findByServiceName(serviceName);
    if (serviceVersionInfoDbObj == null) {
        LOG.warn("serviceVersionInfo does not exist. name=" + serviceName);
    }
    if (lastKnownVersion == null || serviceVersionInfoDbObj == null || serviceVersionInfoDbObj.getPolicyVersion() == null || !lastKnownVersion.equals(serviceVersionInfoDbObj.getPolicyVersion())) {
        ret = RangerServicePoliciesCache.getInstance().getServicePolicies(serviceName, serviceDbObj.getId(), this);
    }
    if (ret != null && lastKnownVersion != null && lastKnownVersion.equals(ret.getPolicyVersion())) {
        // ServicePolicies are not changed
        ret = null;
    }
    if (LOG.isDebugEnabled()) {
        RangerServicePoliciesCache.getInstance().dump();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceDBStore.getServicePoliciesIfUpdated(" + serviceName + ", " + lastKnownVersion + "): count=" + ((ret == null || ret.getPolicies() == null) ? 0 : ret.getPolicies().size()));
    }
    return ret;
}
Also used : ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JSONException(org.codehaus.jettison.json.JSONException)

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