Search in sources :

Example 6 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class EntityAuditListener method onTraitsAdded.

@Override
public void onTraitsAdded(ITypedReferenceableInstance entity, Collection<? extends IStruct> traits) throws AtlasException {
    if (traits != null) {
        for (IStruct trait : traits) {
            EntityAuditEvent event = createEvent(entity, EntityAuditAction.TAG_ADD, "Added trait: " + InstanceSerialization.toJson(trait, true));
            auditRepository.putEvents(event);
        }
    }
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) IStruct(org.apache.atlas.typesystem.IStruct)

Example 7 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class HBaseBasedAuditRepository method putEvents.

@Override
public /**
     * Add events to the event repository
     * @param events events to be added
     * @throws AtlasException
     */
void putEvents(List<EntityAuditEvent> events) throws AtlasException {
    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 (EntityAuditEvent event : events) {
            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.getEntityDefinitionString());
            }
            puts.add(put);
        }
        table.put(puts);
    } catch (IOException e) {
        throw new AtlasException(e);
    } finally {
        close(table);
    }
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Table(org.apache.hadoop.hbase.client.Table) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) Put(org.apache.hadoop.hbase.client.Put)

Example 8 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class HBaseBasedAuditRepository method fromKey.

private EntityAuditEvent fromKey(byte[] keyBytes) {
    String key = Bytes.toString(keyBytes);
    EntityAuditEvent event = new EntityAuditEvent();
    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 : EntityAuditEvent(org.apache.atlas.EntityAuditEvent)

Example 9 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class InMemoryEntityAuditRepository method listEvents.

//synchronized to avoid concurrent modification exception that occurs if events are added
//while we are iterating through the map
@Override
public synchronized List<EntityAuditEvent> listEvents(String entityId, String startKey, short maxResults) throws AtlasException {
    List<EntityAuditEvent> events = new ArrayList<>();
    String myStartKey = startKey;
    if (myStartKey == null) {
        myStartKey = entityId;
    }
    SortedMap<String, EntityAuditEvent> subMap = auditEvents.tailMap(myStartKey);
    for (EntityAuditEvent event : subMap.values()) {
        if (events.size() < maxResults && event.getEntityId().equals(entityId)) {
            events.add(event);
        }
    }
    return events;
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) ArrayList(java.util.ArrayList)

Example 10 with EntityAuditEvent

use of org.apache.atlas.EntityAuditEvent in project incubator-atlas by apache.

the class InMemoryEntityAuditRepository method putEvents.

@Override
public synchronized void putEvents(List<EntityAuditEvent> events) throws AtlasException {
    for (EntityAuditEvent event : events) {
        String rowKey = event.getEntityId() + (Long.MAX_VALUE - event.getTimestamp());
        event.setEventKey(rowKey);
        auditEvents.put(rowKey, event);
    }
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent)

Aggregations

EntityAuditEvent (org.apache.atlas.EntityAuditEvent)20 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)5 Referenceable (org.apache.atlas.typesystem.Referenceable)4 AtlasException (org.apache.atlas.AtlasException)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 IOException (java.io.IOException)2 IStruct (org.apache.atlas.typesystem.IStruct)2 Table (org.apache.hadoop.hbase.client.Table)2 BeforeTest (org.testng.annotations.BeforeTest)2 AtlasClient (org.apache.atlas.AtlasClient)1 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)1 HookNotification (org.apache.atlas.notification.hook.HookNotification)1 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)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 Scan (org.apache.hadoop.hbase.client.Scan)1 PageFilter (org.apache.hadoop.hbase.filter.PageFilter)1 JSONArray (org.codehaus.jettison.json.JSONArray)1