Search in sources :

Example 1 with RangerAtlasEntity

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);
}
Also used : RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) HashMap(java.util.HashMap) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) Test(org.junit.Test)

Example 2 with RangerAtlasEntity

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;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList)

Example 3 with RangerAtlasEntity

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;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) RangerAtlasEntityWithTags(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags) HashMap(java.util.HashMap) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerTagAttributeDef(org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with RangerAtlasEntity

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;
}
Also used : RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity)

Example 5 with RangerAtlasEntity

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
    }
}
Also used : RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) HashMap(java.util.HashMap) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) Test(org.junit.Test)

Aggregations

RangerAtlasEntity (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity)49 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)39 Test (org.junit.Test)37 HashMap (java.util.HashMap)29 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)3 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 RangerTag (org.apache.ranger.plugin.model.RangerTag)1 RangerTagAttributeDef (org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef)1 RangerAtlasEntityWithTags (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags)1