Java Code Examples for org.apache.atlas.v1.model.instance.Referenceable#getSystemAttributes()

The following examples show how to use org.apache.atlas.v1.model.instance.Referenceable#getSystemAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasJson.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(Referenceable entity, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    if (entity != null) {
        Map<String, Object> valueMap = entity.getValues() != null ? new HashMap<>(entity.getValues()) : new HashMap<>();

        if (entity.getTypeName() != null) {
            valueMap.put(V1_KEY_$TYPENAME, entity.getTypeName());
        }

        if (entity.getId() != null) {
            valueMap.put(V1_KEY_$ID, entity.getId());
        }

        if (entity.getSystemAttributes() != null) {
            valueMap.put(V1_KEY_$SYSTEM_ATTRIBUTES, entity.getSystemAttributes());
        }

        if (MapUtils.isNotEmpty(entity.getTraits())) {
            valueMap.put(V1_KEY_$TRAITS, entity.getTraits());
        }

        jgen.writeObject(valueMap);
    }
}
 
Example 2
Source File: EntityAuditListener.java    From atlas with Apache License 2.0 5 votes vote down vote up
private String getAuditEventDetail(Referenceable entity, EntityAuditAction action) throws AtlasException {
    Map<String, Object> prunedAttributes = pruneEntityAttributesForAudit(entity);

    String auditPrefix  = getV1AuditPrefix(action);
    String auditString  = auditPrefix + AtlasType.toV1Json(entity);
    byte[] auditBytes   = auditString.getBytes(StandardCharsets.UTF_8);
    long   auditSize    = auditBytes != null ? auditBytes.length : 0;
    long   auditMaxSize = auditRepository.repositoryMaxSize();

    if (auditMaxSize >= 0 && auditSize > auditMaxSize) { // don't store attributes in audit
        LOG.warn("audit record too long: entityType={}, guid={}, size={}; maxSize={}. entity attribute values not stored in audit",
                entity.getTypeName(), entity.getId()._getId(), auditSize, auditMaxSize);

        Map<String, Object> attrValues = entity.getValuesMap();

        entity.setValues(null);

        auditString = auditPrefix + AtlasType.toV1Json(entity);
        auditBytes  = auditString.getBytes(StandardCharsets.UTF_8); // recheck auditString size
        auditSize   = auditBytes != null ? auditBytes.length : 0;

        if (auditMaxSize >= 0 && auditSize > auditMaxSize) { // don't store classifications as well
            LOG.warn("audit record still too long: entityType={}, guid={}, size={}; maxSize={}. audit will have only summary details",
                    entity.getTypeName(), entity.getId()._getId(), auditSize, auditMaxSize);

            Referenceable shallowEntity = new Referenceable(entity.getId(), entity.getTypeName(), null, entity.getSystemAttributes(), null, null);

            auditString = auditPrefix + AtlasType.toJson(shallowEntity);
        }

        entity.setValues(attrValues);
    }

    restoreEntityAttributes(entity, prunedAttributes);

    return auditString;
}