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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations