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