Search in sources :

Example 1 with XXTagDao

use of org.apache.ranger.db.XXTagDao in project ranger by apache.

the class PatchForUpdatingTagsJson_J10020 method updateRangerTagsTablesWithTagsJson.

private void updateRangerTagsTablesWithTagsJson() throws Exception {
    logger.info("==> updateRangerTagsTablesWithTagsJson() ");
    List<RangerService> allServices = svcStore.getServices(new SearchFilter());
    if (CollectionUtils.isNotEmpty(allServices)) {
        TransactionTemplate txTemplate = new TransactionTemplate(txManager);
        for (RangerService service : allServices) {
            XXService dbService = daoMgr.getXXService().getById(service.getId());
            RangerTagDBRetriever tagsRetriever = new RangerTagDBRetriever(daoMgr, txManager, dbService);
            Map<Long, RangerTagDef> tagDefs = tagsRetriever.getTagDefs();
            Map<Long, RangerTag> tags = tagsRetriever.getTags();
            List<RangerServiceResource> serviceResources = tagsRetriever.getServiceResources();
            XXTagDefDao tagDefDao = daoMgr.getXXTagDef();
            XXTagDao tagDao = daoMgr.getXXTag();
            XXServiceResourceDao serviceResourceDao = daoMgr.getXXServiceResource();
            if (MapUtils.isNotEmpty(tagDefs)) {
                logger.info("==> Port " + tagDefs.size() + " Tag Definitions for service(name=" + dbService.getName() + ")");
                for (Map.Entry<Long, RangerTagDef> entry : tagDefs.entrySet()) {
                    RangerTagDef tagDef = entry.getValue();
                    XXTagDef xTagDef = tagDefDao.getById(tagDef.getId());
                    if (xTagDef != null && StringUtils.isEmpty(xTagDef.getTagAttrDefs())) {
                        TagsUpdaterThread updaterThread = new TagsUpdaterThread(txTemplate, null, null, tagDef);
                        String errorMsg = runThread(updaterThread);
                        if (StringUtils.isNotEmpty(errorMsg)) {
                            throw new Exception(errorMsg);
                        }
                    }
                }
            }
            if (MapUtils.isNotEmpty(tags)) {
                logger.info("==> Port " + tags.size() + " Tags for service(name=" + dbService.getName() + ")");
                for (Map.Entry<Long, RangerTag> entry : tags.entrySet()) {
                    RangerTag tag = entry.getValue();
                    XXTag xTag = tagDao.getById(tag.getId());
                    if (xTag != null && StringUtils.isEmpty(xTag.getTagAttrs())) {
                        TagsUpdaterThread updaterThread = new TagsUpdaterThread(txTemplate, null, tag, null);
                        String errorMsg = runThread(updaterThread);
                        if (StringUtils.isNotEmpty(errorMsg)) {
                            throw new Exception(errorMsg);
                        }
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(serviceResources)) {
                logger.info("==> Port " + serviceResources.size() + " Service Resources for service(name=" + dbService.getName() + ")");
                for (RangerServiceResource serviceResource : serviceResources) {
                    XXServiceResource xServiceResource = serviceResourceDao.getById(serviceResource.getId());
                    if (xServiceResource != null && StringUtils.isEmpty(xServiceResource.getServiceResourceElements())) {
                        TagsUpdaterThread updaterThread = new TagsUpdaterThread(txTemplate, serviceResource, null, null);
                        String errorMsg = runThread(updaterThread);
                        if (StringUtils.isNotEmpty(errorMsg)) {
                            throw new Exception(errorMsg);
                        }
                    }
                }
            }
        }
    }
    logger.info("<== updateRangerTagsTablesWithTagsJson() ");
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) XXTagDef(org.apache.ranger.entity.XXTagDef) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) XXTagDao(org.apache.ranger.db.XXTagDao) RangerTag(org.apache.ranger.plugin.model.RangerTag) RangerService(org.apache.ranger.plugin.model.RangerService) XXServiceResourceDao(org.apache.ranger.db.XXServiceResourceDao) XXServiceResource(org.apache.ranger.entity.XXServiceResource) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) XXTagDefDao(org.apache.ranger.db.XXTagDefDao) XXTag(org.apache.ranger.entity.XXTag) XXService(org.apache.ranger.entity.XXService) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 XXServiceResourceDao (org.apache.ranger.db.XXServiceResourceDao)1 XXTagDao (org.apache.ranger.db.XXTagDao)1 XXTagDefDao (org.apache.ranger.db.XXTagDefDao)1 XXService (org.apache.ranger.entity.XXService)1 XXServiceResource (org.apache.ranger.entity.XXServiceResource)1 XXTag (org.apache.ranger.entity.XXTag)1 XXTagDef (org.apache.ranger.entity.XXTagDef)1 RangerService (org.apache.ranger.plugin.model.RangerService)1 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)1 RangerTag (org.apache.ranger.plugin.model.RangerTag)1 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)1 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1