use of org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity in project ranger by apache.
the class TestKafkaResourceMapper method testKafkaResourceFromQualifiedName.
@Test
public void testKafkaResourceFromQualifiedName() throws Exception {
Map<String, Object> entAttribs = new HashMap<String, Object>();
entAttribs.put(AtlasKafkaResourceMapper.ENTITY_ATTRIBUTE_QUALIFIED_NAME, QUALIFIED_NAME);
RangerAtlasEntity entity = getKafkaTopicEntity(entAttribs);
RangerServiceResource resource = resourceMapper.buildResource(entity);
assertServiceResource(resource);
}
use of org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity 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);
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());
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Entity " + entityWithTags + " does not have any tags associated with it");
}
}
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 {
LOG.error("Failed to build serviceResource for entity:" + entity.getGuid());
}
return ret;
}
use of org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity in project ranger by apache.
the class AtlasNotificationMapper method buildServiceTags.
private static Map<String, ServiceTags> buildServiceTags(List<RangerAtlasEntityWithTags> entitiesWithTags) {
Map<String, ServiceTags> ret = new HashMap<>();
for (RangerAtlasEntityWithTags element : entitiesWithTags) {
RangerAtlasEntity entity = element.getEntity();
if (entity != null) {
buildServiceTags(element, ret);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Ignoring entity because its State is not ACTIVE: " + element);
}
}
}
// Remove duplicate tag definitions
if (CollectionUtils.isNotEmpty(ret.values())) {
for (ServiceTags serviceTag : ret.values()) {
if (MapUtils.isNotEmpty(serviceTag.getTagDefinitions())) {
Map<String, RangerTagDef> uniqueTagDefs = new HashMap<>();
for (RangerTagDef tagDef : serviceTag.getTagDefinitions().values()) {
RangerTagDef existingTagDef = uniqueTagDefs.get(tagDef.getName());
if (existingTagDef == null) {
uniqueTagDefs.put(tagDef.getName(), tagDef);
} else {
if (CollectionUtils.isNotEmpty(tagDef.getAttributeDefs())) {
for (RangerTagAttributeDef tagAttrDef : tagDef.getAttributeDefs()) {
boolean attrDefExists = false;
if (CollectionUtils.isNotEmpty(existingTagDef.getAttributeDefs())) {
for (RangerTagAttributeDef existingTagAttrDef : existingTagDef.getAttributeDefs()) {
if (StringUtils.equalsIgnoreCase(existingTagAttrDef.getName(), tagAttrDef.getName())) {
attrDefExists = true;
break;
}
}
}
if (!attrDefExists) {
existingTagDef.getAttributeDefs().add(tagAttrDef);
}
}
}
}
}
serviceTag.getTagDefinitions().clear();
for (RangerTagDef tagDef : uniqueTagDefs.values()) {
serviceTag.getTagDefinitions().put(tagDef.getId(), tagDef);
}
}
}
}
if (MapUtils.isNotEmpty(ret)) {
for (Map.Entry<String, ServiceTags> entry : ret.entrySet()) {
ServiceTags serviceTags = entry.getValue();
serviceTags.setOp(ServiceTags.OP_REPLACE);
}
}
return ret;
}
use of org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity in project ranger by apache.
the class TestHbaseResourceMapper method getHbaseColumnFamilyEntity.
private RangerAtlasEntity getHbaseColumnFamilyEntity(Map<String, Object> entAttribs) throws Exception {
RangerAtlasEntity entity = Mockito.mock(RangerAtlasEntity.class);
Mockito.when(entity.getTypeName()).thenReturn(AtlasHbaseResourceMapper.ENTITY_TYPE_HBASE_COLUMN_FAMILY);
Mockito.when(entity.getAttributes()).thenReturn(entAttribs);
return entity;
}
use of org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity in project ranger by apache.
the class TestHbaseResourceMapper method testHbaseResourceFromMissingColumnFamilyName.
@Test
public void testHbaseResourceFromMissingColumnFamilyName() throws Exception {
Map<String, Object> entAttribs = new HashMap<String, Object>();
entAttribs.put(ENTITY_ATTRIBUTE_QUALIFIED_NAME, TABLE_QUALIFIED_NAME);
RangerAtlasEntity entity = getHbaseColumnFamilyEntity(entAttribs);
try {
RangerServiceResource resource = resourceMapper.buildResource(entity);
Assert.fail("expected exception. Found " + resource);
} catch (Exception excp) {
// ignore
}
}
Aggregations