Search in sources :

Example 1 with RangerAtlasEntityWithTags

use of org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags 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 2 with RangerAtlasEntityWithTags

use of org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags in project ranger by apache.

the class AtlasTagSource method getPrintableEntityNotification.

private static String getPrintableEntityNotification(EntityNotificationWrapper notification) {
    StringBuilder sb = new StringBuilder();
    sb.append("{ Notification-Type: ").append(notification.getOpType()).append(", ");
    RangerAtlasEntityWithTags entityWithTags = new RangerAtlasEntityWithTags(notification);
    sb.append(entityWithTags.toString());
    sb.append("}");
    return sb.toString();
}
Also used : RangerAtlasEntityWithTags(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags)

Aggregations

RangerAtlasEntityWithTags (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntityWithTags)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)1 RangerTagAttributeDef (org.apache.ranger.plugin.model.RangerTagDef.RangerTagAttributeDef)1 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)1 RangerAtlasEntity (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity)1