Search in sources :

Example 1 with RangerValiditySchedule

use of org.apache.ranger.plugin.model.RangerValiditySchedule in project ranger by apache.

the class AtlasNotificationMapper method getTags.

private static List<RangerTag> getTags(RangerAtlasEntityWithTags entityWithTags) {
    List<RangerTag> ret = new ArrayList<>();
    if (entityWithTags != null && CollectionUtils.isNotEmpty(entityWithTags.getTags())) {
        List<EntityNotificationWrapper.RangerAtlasClassification> tags = entityWithTags.getTags();
        for (EntityNotificationWrapper.RangerAtlasClassification tag : tags) {
            RangerTag rangerTag = new RangerTag(null, tag.getName(), tag.getAttributes(), RangerTag.OWNER_SERVICERESOURCE);
            List<RangerValiditySchedule> validityPeriods = tag.getValidityPeriods();
            if (CollectionUtils.isNotEmpty(validityPeriods)) {
                rangerTag.setValidityPeriods(validityPeriods);
            }
            ret.add(rangerTag);
        }
    }
    return ret;
}
Also used : RangerValiditySchedule(org.apache.ranger.plugin.model.RangerValiditySchedule) RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList)

Example 2 with RangerValiditySchedule

use of org.apache.ranger.plugin.model.RangerValiditySchedule in project ranger by apache.

the class EntityNotificationWrapper method convertTimeSpecFromAtlasToRanger.

public static List<RangerValiditySchedule> convertTimeSpecFromAtlasToRanger(List<TimeBoundary> atlasTimeSpec) {
    List<RangerValiditySchedule> rangerTimeSpec = null;
    if (CollectionUtils.isNotEmpty(atlasTimeSpec)) {
        rangerTimeSpec = new ArrayList<>();
        for (TimeBoundary validityPeriod : atlasTimeSpec) {
            RangerValiditySchedule validitySchedule = new RangerValiditySchedule();
            validitySchedule.setStartTime(validityPeriod.getStartTime());
            validitySchedule.setEndTime(validityPeriod.getEndTime());
            validitySchedule.setTimeZone(validityPeriod.getTimeZone());
            rangerTimeSpec.add(validitySchedule);
        }
    }
    return rangerTimeSpec;
}
Also used : RangerValiditySchedule(org.apache.ranger.plugin.model.RangerValiditySchedule) TimeBoundary(org.apache.atlas.model.TimeBoundary)

Example 3 with RangerValiditySchedule

use of org.apache.ranger.plugin.model.RangerValiditySchedule in project ranger by apache.

the class AtlasRESTTagSource method resolveTag.

/*
     * Returns a list of <EntityNotificationWrapper.RangerAtlasClassification>
     */
private List<EntityNotificationWrapper.RangerAtlasClassification> resolveTag(AtlasTypeRegistry typeRegistry, AtlasClassification classification) {
    List<EntityNotificationWrapper.RangerAtlasClassification> ret = new ArrayList<>();
    String typeName = classification.getTypeName();
    Map<String, Object> attributes = classification.getAttributes();
    try {
        AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(typeName);
        if (classificationType != null) {
            Map<String, String> allAttributes = new HashMap<>();
            if (MapUtils.isNotEmpty(attributes) && MapUtils.isNotEmpty(classificationType.getAllAttributes())) {
                for (Map.Entry<String, Object> attribute : attributes.entrySet()) {
                    String name = attribute.getKey();
                    Object value = attribute.getValue();
                    if (value != null) {
                        String stringValue = value.toString();
                        AtlasStructType.AtlasAttribute atlasAttribute = classificationType.getAttribute(name);
                        if (atlasAttribute != null) {
                            if (value instanceof Number) {
                                if (atlasAttribute.getAttributeType() instanceof AtlasBuiltInTypes.AtlasDateType) {
                                    stringValue = DATE_FORMATTER.get().format(value);
                                }
                            }
                            allAttributes.put(name, stringValue);
                        }
                    }
                }
            }
            List<TimeBoundary> validityPeriods = classification.getValidityPeriods();
            List<RangerValiditySchedule> validitySchedules = null;
            if (CollectionUtils.isNotEmpty(validityPeriods)) {
                validitySchedules = EntityNotificationWrapper.convertTimeSpecFromAtlasToRanger(validityPeriods);
            }
            // Add most derived classificationType with all attributes
            ret.add(new EntityNotificationWrapper.RangerAtlasClassification(typeName, allAttributes, validitySchedules));
            // Find base classification types
            Set<String> superTypeNames = classificationType.getAllSuperTypes();
            for (String superTypeName : superTypeNames) {
                AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName);
                if (superType != null) {
                    Map<String, String> attributeMap = new HashMap<>();
                    if (MapUtils.isNotEmpty(attributes) && MapUtils.isNotEmpty(superType.getAllAttributes())) {
                        for (String name : superType.getAllAttributes().keySet()) {
                            String stringValue = allAttributes.get(name);
                            if (stringValue != null) {
                                attributeMap.put(name, stringValue);
                            }
                        }
                    }
                    validityPeriods = classification.getValidityPeriods();
                    validitySchedules = null;
                    if (CollectionUtils.isNotEmpty(validityPeriods)) {
                        validitySchedules = EntityNotificationWrapper.convertTimeSpecFromAtlasToRanger(validityPeriods);
                    }
                    ret.add(new EntityNotificationWrapper.RangerAtlasClassification(superTypeName, attributeMap, validitySchedules));
                }
            }
        }
    } catch (Exception exception) {
        LOG.error("Error in resolving tags for type:[" + typeName + "]", exception);
    }
    return ret;
}
Also used : EntityNotificationWrapper(org.apache.ranger.tagsync.source.atlas.EntityNotificationWrapper) RangerValiditySchedule(org.apache.ranger.plugin.model.RangerValiditySchedule) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasServiceException(org.apache.atlas.AtlasServiceException) IOException(java.io.IOException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) TimeBoundary(org.apache.atlas.model.TimeBoundary) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with RangerValiditySchedule

use of org.apache.ranger.plugin.model.RangerValiditySchedule in project ranger by apache.

the class RangerValidityScheduleValidator method validate.

public RangerValiditySchedule validate(List<ValidationFailureDetails> validationFailures) {
    RangerValiditySchedule ret = null;
    if (StringUtils.isEmpty(validitySchedule.getStartTime()) && StringUtils.isEmpty(validitySchedule.getEndTime()) && CollectionUtils.isEmpty(validitySchedule.getRecurrences())) {
        validationFailures.add(new ValidationFailureDetails(0, "startTime,endTime,recurrences", "", true, true, false, "empty values"));
    } else {
        if (validitySchedule.getStartTime() != null) {
            try {
                startTime = DATE_FORMATTER.get().parse(validitySchedule.getStartTime());
            } catch (ParseException exception) {
                LOG.error("Error parsing startTime:[" + validitySchedule.getStartTime() + "]", exception);
                validationFailures.add(new ValidationFailureDetails(0, "startTime", "", true, true, false, "invalid value"));
            }
        } else {
            startTime = new Date();
        }
        if (validitySchedule.getEndTime() != null) {
            try {
                endTime = DATE_FORMATTER.get().parse(validitySchedule.getEndTime());
            } catch (ParseException exception) {
                LOG.error("Error parsing endTime:[" + validitySchedule.getEndTime() + "]", exception);
                validationFailures.add(new ValidationFailureDetails(0, "endTime", "", true, true, false, "invalid value"));
            }
        } else {
            endTime = new Date(Long.MAX_VALUE);
        }
        if (startTime != null && endTime != null) {
            validityPeriodEstimator = new RangerValidityRecurrence.RecurrenceSchedule();
            normalizedValiditySchedule = new RangerValiditySchedule();
            boolean isValid = validateTimeRangeSpec(validationFailures);
            if (isValid) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("validityPeriodEstimator:[" + validityPeriodEstimator + "]");
                }
                normalizedValiditySchedule.setStartTime(validitySchedule.getStartTime());
                normalizedValiditySchedule.setEndTime(validitySchedule.getEndTime());
                normalizedValiditySchedule.setTimeZone(validitySchedule.getTimeZone());
                ret = normalizedValiditySchedule;
            } else {
                normalizedValiditySchedule = null;
            }
        }
    }
    return ret;
}
Also used : RangerValidityRecurrence(org.apache.ranger.plugin.model.RangerValidityRecurrence) RangerValiditySchedule(org.apache.ranger.plugin.model.RangerValiditySchedule) ParseException(java.text.ParseException) Date(java.util.Date) RecurrenceSchedule(org.apache.ranger.plugin.model.RangerValidityRecurrence.RecurrenceSchedule)

Example 5 with RangerValiditySchedule

use of org.apache.ranger.plugin.model.RangerValiditySchedule in project ranger by apache.

the class RangerTagServiceBase method mapEntityToViewBean.

@Override
protected V mapEntityToViewBean(V vObj, T xObj) {
    XXTagDef xTagDef = daoMgr.getXXTagDef().getById(xObj.getType());
    if (xTagDef == null) {
        throw restErrorUtil.createRESTException("No TagDefinition found with name :" + xObj.getType(), MessageEnums.INVALID_INPUT_DATA);
    }
    vObj.setGuid(xObj.getGuid());
    vObj.setType(xTagDef.getName());
    vObj.setOwner(xObj.getOwner());
    Map<String, Object> options = JsonUtils.jsonToObject(xObj.getOptions(), Map.class);
    if (MapUtils.isNotEmpty(options)) {
        String optionTagValidityPeriod = (String) options.remove(RangerTag.OPTION_TAG_VALIDITY_PERIODS);
        if (StringUtils.isNotBlank(optionTagValidityPeriod)) {
            List<RangerValiditySchedule> validityPeriods = JsonUtils.jsonToRangerValiditySchedule(optionTagValidityPeriod);
            vObj.setValidityPeriods(validityPeriods);
        }
    }
    vObj.setOptions(options);
    Map<String, String> attributes = getAttributesForTag(xObj);
    vObj.setAttributes(attributes);
    return vObj;
}
Also used : XXTagDef(org.apache.ranger.entity.XXTagDef) RangerValiditySchedule(org.apache.ranger.plugin.model.RangerValiditySchedule)

Aggregations

RangerValiditySchedule (org.apache.ranger.plugin.model.RangerValiditySchedule)9 ArrayList (java.util.ArrayList)3 Map (java.util.Map)2 TimeBoundary (org.apache.atlas.model.TimeBoundary)2 EntityNotificationWrapper (org.apache.ranger.tagsync.source.atlas.EntityNotificationWrapper)2 JsonParseException (com.google.gson.JsonParseException)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Type (java.lang.reflect.Type)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TimeZone (java.util.TimeZone)1 AtlasServiceException (org.apache.atlas.AtlasServiceException)1 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)1 AtlasStructType (org.apache.atlas.type.AtlasStructType)1