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() ");
}
Aggregations