use of org.apache.ranger.plugin.util.ServiceTags 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;
}
use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class AbstractTagSource method updateSink.
protected void updateSink(final ServiceTags toUpload) {
if (toUpload == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No ServiceTags to upload");
}
} else {
if (LOG.isDebugEnabled()) {
String toUploadJSON = new Gson().toJson(toUpload);
LOG.debug("Uploading serviceTags=" + toUploadJSON);
}
try {
ServiceTags uploaded = tagSink.upload(toUpload);
if (LOG.isDebugEnabled()) {
String uploadedJSON = new Gson().toJson(uploaded);
LOG.debug("Uploaded serviceTags=" + uploadedJSON);
}
} catch (Exception exception) {
String toUploadJSON = new Gson().toJson(toUpload);
LOG.error("Failed to upload serviceTags: " + toUploadJSON);
LOG.error("Exception : ", exception);
}
}
}
use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class TagAdminRESTSink method run.
@Override
public void run() {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TagAdminRESTSink.run()");
}
while (true) {
UploadWorkItem uploadWorkItem;
try {
uploadWorkItem = uploadWorkItems.take();
ServiceTags toUpload = uploadWorkItem.getServiceTags();
boolean doRetry;
do {
doRetry = false;
try {
ServiceTags uploaded = doUpload(toUpload);
if (uploaded == null) {
// Treat this as if an Exception is thrown by doUpload
doRetry = true;
Thread.sleep(rangerAdminConnectionCheckInterval);
} else {
// ServiceTags uploaded successfully
uploadWorkItem.uploadCompleted(uploaded);
}
} catch (InterruptedException interrupted) {
LOG.error("Caught exception..: ", interrupted);
return;
} catch (Exception exception) {
doRetry = true;
Thread.sleep(rangerAdminConnectionCheckInterval);
}
} while (doRetry);
} catch (InterruptedException exception) {
LOG.error("Interrupted..: ", exception);
return;
}
}
}
use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class TagAdminRESTSink method upload.
@Override
public ServiceTags upload(ServiceTags toUpload) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> upload() ");
}
UploadWorkItem uploadWorkItem = new UploadWorkItem(toUpload);
uploadWorkItems.put(uploadWorkItem);
// Wait until message is successfully delivered
ServiceTags ret = uploadWorkItem.waitForUpload();
if (LOG.isDebugEnabled()) {
LOG.debug("<== upload()");
}
return ret;
}
use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class AtlasNotificationMapper method buildServiceTags.
private static ServiceTags buildServiceTags(RangerAtlasEntityWithTags entityWithTags, Map<String, ServiceTags> serviceTagsMap) {
ServiceTags ret = null;
RangerAtlasEntity entity = entityWithTags.getEntity();
RangerServiceResource serviceResource = AtlasResourceMapperUtil.getRangerServiceResource(entity);
if (serviceResource != null) {
List<RangerTag> tags = getTags(entityWithTags);
List<RangerTagDef> tagDefs = getTagDefs(entityWithTags);
String serviceName = serviceResource.getServiceName();
ret = createOrGetServiceTags(serviceTagsMap, serviceName);
if (serviceTagsMap == null || CollectionUtils.isNotEmpty(tags)) {
serviceResource.setId((long) ret.getServiceResources().size());
ret.getServiceResources().add(serviceResource);
List<Long> tagIds = new ArrayList<>();
if (CollectionUtils.isNotEmpty(tags)) {
for (RangerTag tag : tags) {
tag.setId((long) ret.getTags().size());
ret.getTags().put(tag.getId(), tag);
tagIds.add(tag.getId());
}
}
ret.getResourceToTagIds().put(serviceResource.getId(), tagIds);
if (CollectionUtils.isNotEmpty(tagDefs)) {
for (RangerTagDef tagDef : tagDefs) {
tagDef.setId((long) ret.getTagDefinitions().size());
ret.getTagDefinitions().put(tagDef.getId(), tagDef);
}
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Entity " + entityWithTags + " does not have any tags associated with it when full-sync is being done.");
LOG.debug("Will not add this entity to serviceTags, so that this entity, if exists, will be removed from ranger");
}
}
} else {
LOG.error("Failed to build serviceResource for entity:" + entity.getGuid());
}
return ret;
}
Aggregations