Search in sources :

Example 1 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class AtlasInstanceConverter method toV2AuditEvent.

public EntityAuditEventV2 toV2AuditEvent(EntityAuditEvent v1Event) throws AtlasBaseException {
    EntityAuditEventV2 ret = new EntityAuditEventV2();
    ret.setEntityId(v1Event.getEntityId());
    ret.setTimestamp(v1Event.getTimestamp());
    ret.setUser(v1Event.getUser());
    ret.setDetails(v1Event.getDetails());
    ret.setEventKey(v1Event.getEventKey());
    ret.setAction(getV2AuditAction(v1Event.getAction()));
    AtlasEntitiesWithExtInfo entitiesWithExtInfo = toAtlasEntity(v1Event.getEntityDefinition());
    if (entitiesWithExtInfo != null && CollectionUtils.isNotEmpty(entitiesWithExtInfo.getEntities())) {
        // there will only one source entity
        AtlasEntity entity = entitiesWithExtInfo.getEntities().get(0);
        ret.setEntity(entity);
    }
    return ret;
}
Also used : EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)

Example 2 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class EntityAuditListenerV2 method onEntitiesAdded.

@Override
public void onEntitiesAdded(List<AtlasEntity> entities, boolean isImport) throws AtlasBaseException {
    List<EntityAuditEventV2> events = new ArrayList<>();
    for (AtlasEntity entity : entities) {
        EntityAuditEventV2 event = createEvent(entity, isImport ? ENTITY_IMPORT_CREATE : ENTITY_CREATE);
        events.add(event);
    }
    auditRepository.putEventsV2(events);
}
Also used : EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) ArrayList(java.util.ArrayList)

Example 3 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class EntityAuditListenerV2 method onClassificationsAdded.

@Override
public void onClassificationsAdded(AtlasEntity entity, List<AtlasClassification> classifications) throws AtlasBaseException {
    if (CollectionUtils.isNotEmpty(classifications)) {
        List<EntityAuditEventV2> events = new ArrayList<>();
        for (AtlasClassification classification : classifications) {
            events.add(createEvent(entity, CLASSIFICATION_ADD, "Added classification: " + AtlasType.toJson(classification)));
        }
        auditRepository.putEventsV2(events);
    }
}
Also used : EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) ArrayList(java.util.ArrayList) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 4 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class HBaseBasedAuditRepository method putEventsV2.

@Override
public void putEventsV2(List<EntityAuditEventV2> events) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Putting {} events", events.size());
    }
    Table table = null;
    try {
        table = connection.getTable(tableName);
        List<Put> puts = new ArrayList<>(events.size());
        for (EntityAuditEventV2 event : events) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Adding entity audit event {}", event);
            }
            Put put = new Put(getKey(event.getEntityId(), event.getTimestamp()));
            addColumn(put, COLUMN_ACTION, event.getAction());
            addColumn(put, COLUMN_USER, event.getUser());
            addColumn(put, COLUMN_DETAIL, event.getDetails());
            if (persistEntityDefinition) {
                addColumn(put, COLUMN_DEFINITION, event.getEntity());
            }
            puts.add(put);
        }
        table.put(puts);
    } catch (IOException e) {
        throw new AtlasBaseException(e);
    } finally {
        try {
            close(table);
        } catch (AtlasException e) {
            throw new AtlasBaseException(e);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) Put(org.apache.hadoop.hbase.client.Put)

Example 5 with EntityAuditEventV2

use of org.apache.atlas.model.audit.EntityAuditEventV2 in project atlas by apache.

the class HBaseBasedAuditRepository method fromKeyV2.

private EntityAuditEventV2 fromKeyV2(byte[] keyBytes) {
    String key = Bytes.toString(keyBytes);
    EntityAuditEventV2 event = new EntityAuditEventV2();
    if (StringUtils.isNotEmpty(key)) {
        String[] parts = key.split(FIELD_SEPARATOR);
        event.setEntityId(parts[0]);
        event.setTimestamp(Long.valueOf(parts[1]));
        event.setEventKey(key);
    }
    return event;
}
Also used : EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2)

Aggregations

EntityAuditEventV2 (org.apache.atlas.model.audit.EntityAuditEventV2)13 ArrayList (java.util.ArrayList)10 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 IOException (java.io.IOException)2 List (java.util.List)2 AtlasException (org.apache.atlas.AtlasException)2 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)2 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 Table (org.apache.hadoop.hbase.client.Table)2 HashMap (java.util.HashMap)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)1 Put (org.apache.hadoop.hbase.client.Put)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1