Search in sources :

Example 11 with EntityAuditEventV2

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

the class EntityAuditListenerV2 method onClassificationsUpdated.

@Override
public void onClassificationsUpdated(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_UPDATE, "Updated 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 12 with EntityAuditEventV2

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

the class HBaseBasedAuditRepository method listEventsV2.

@Override
public List<EntityAuditEventV2> listEventsV2(String entityId, String startKey, short n) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Listing events for entity id {}, starting timestamp {}, #records {}", entityId, startKey, n);
    }
    Table table = null;
    ResultScanner scanner = null;
    try {
        table = connection.getTable(tableName);
        /**
         * Scan Details:
         * In hbase, the events are stored in increasing order of timestamp. So, doing reverse scan to get the latest event first
         * Page filter is set to limit the number of results returned.
         * Stop row is set to the entity id to avoid going past the current entity while scanning
         * small is set to true to optimise RPC calls as the scanner is created per request
         */
        Scan scan = new Scan().setReversed(true).setFilter(new PageFilter(n)).setStopRow(Bytes.toBytes(entityId)).setCaching(n).setSmall(true);
        if (StringUtils.isEmpty(startKey)) {
            // Set start row to entity id + max long value
            byte[] entityBytes = getKey(entityId, Long.MAX_VALUE);
            scan = scan.setStartRow(entityBytes);
        } else {
            scan = scan.setStartRow(Bytes.toBytes(startKey));
        }
        scanner = table.getScanner(scan);
        List<EntityAuditEventV2> events = new ArrayList<>();
        Result result;
        // So, adding extra check on n here
        while ((result = scanner.next()) != null && events.size() < n) {
            EntityAuditEventV2 event = fromKeyV2(result.getRow());
            // In case the user sets random start key, guarding against random events
            if (!event.getEntityId().equals(entityId)) {
                continue;
            }
            event.setUser(getResultString(result, COLUMN_USER));
            event.setAction(EntityAuditAction.fromString(getResultString(result, COLUMN_ACTION)));
            event.setDetails(getResultString(result, COLUMN_DETAIL));
            if (persistEntityDefinition) {
                String colDef = getResultString(result, COLUMN_DEFINITION);
                if (colDef != null) {
                    event.setEntityDefinition(colDef);
                }
            }
            events.add(event);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Got events for entity id {}, starting timestamp {}, #records {}", entityId, startKey, events.size());
        }
        return events;
    } catch (IOException e) {
        throw new AtlasBaseException(e);
    } finally {
        try {
            close(scanner);
            close(table);
        } catch (AtlasException e) {
            throw new AtlasBaseException(e);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) Result(org.apache.hadoop.hbase.client.Result) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) Scan(org.apache.hadoop.hbase.client.Scan) PageFilter(org.apache.hadoop.hbase.filter.PageFilter)

Example 13 with EntityAuditEventV2

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

the class InMemoryEntityAuditRepository method listEventsV2.

@Override
public List<EntityAuditEventV2> listEventsV2(String entityId, String startKey, short maxResults) {
    List<EntityAuditEventV2> events = new ArrayList<>();
    String myStartKey = startKey;
    if (myStartKey == null) {
        myStartKey = entityId;
    }
    SortedMap<String, EntityAuditEventV2> subMap = auditEventsV2.tailMap(myStartKey);
    for (EntityAuditEventV2 event : subMap.values()) {
        if (events.size() < maxResults && event.getEntityId().equals(entityId)) {
            events.add(event);
        }
    }
    return events;
}
Also used : EntityAuditEventV2(org.apache.atlas.model.audit.EntityAuditEventV2) ArrayList(java.util.ArrayList)

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