Search in sources :

Example 1 with EventSeries

use of org.ff4j.audit.EventSeries in project ff4j by ff4j.

the class EventRepositoryCassandra method searchFeatureUsageEvents.

/**
 * {@inheritDoc}
 */
@Override
public EventSeries searchFeatureUsageEvents(EventQueryDefinition query) {
    String cqlQuery = getBuilder().cqlAuditFeatureUsage(query);
    LOGGER.debug("Query " + cqlQuery);
    ResultSet rs = conn.getSession().execute(cqlQuery);
    EventSeries es = new EventSeries();
    for (Row row : rs.all()) {
        es.add(CassandraMapper.mapEvent(row));
    }
    return es;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) EventSeries(org.ff4j.audit.EventSeries) Row(com.datastax.driver.core.Row)

Example 2 with EventSeries

use of org.ff4j.audit.EventSeries in project ff4j by ff4j.

the class EventRepositoryElastic method getAuditTrail.

@Override
public EventSeries getAuditTrail(EventQueryDefinition query) {
    JestResult result = getConnection().execute(getBuilder().queryGetEventQueryDefinition(query));
    List<Event> events = result.getSourceAsObjectList(Event.class);
    EventSeries es = new EventSeries();
    Set<String> candidates = // 
    Util.set(// 
    ACTION_DISCONNECT, // 
    ACTION_TOGGLE_ON, // 
    ACTION_TOGGLE_OFF, // 
    ACTION_CREATE, ACTION_DELETE, ACTION_UPDATE, ACTION_CLEAR);
    for (Event event : events) {
        if (candidates.contains(event.getAction()))
            es.add(event);
    }
    return es;
}
Also used : EventSeries(org.ff4j.audit.EventSeries) Event(org.ff4j.audit.Event) JestResult(io.searchbox.client.JestResult)

Example 3 with EventSeries

use of org.ff4j.audit.EventSeries in project ff4j by ff4j.

the class EventRepositoryHBase method getAuditTrail.

/**
 * {@inheritDoc}
 */
@Override
public EventSeries getAuditTrail(EventQueryDefinition query) {
    EventSeries es = new EventSeries();
    try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) {
        try (Table table = hbConn.getTable(AUDIT_TABLENAME)) {
            query.getActionFilters().add(ACTION_CHECK_OK);
            Scan scanQuery = buildQuery(query, COLS_EVENT, null);
            Set<String> candidates = Util.set(ACTION_DISCONNECT, ACTION_TOGGLE_ON, ACTION_TOGGLE_OFF, ACTION_CREATE, ACTION_DELETE, ACTION_UPDATE, ACTION_CLEAR);
            try (ResultScanner scanner = table.getScanner(scanQuery)) {
                for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
                    String action = Bytes.toString(rr.getValue(B_AUDIT_CF, B_EVENT_ACTION));
                    if (candidates.contains(action)) {
                        es.add(MAPPER.fromStore(rr));
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new AuditAccessException("Cannot search audit trail ", e);
    }
    return es;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) EventSeries(org.ff4j.audit.EventSeries) HBaseConnection(org.ff4j.hbase.HBaseConnection) Connection(org.apache.hadoop.hbase.client.Connection) Scan(org.apache.hadoop.hbase.client.Scan) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) AuditAccessException(org.ff4j.exception.AuditAccessException)

Example 4 with EventSeries

use of org.ff4j.audit.EventSeries in project ff4j by ff4j.

the class EventRepositoryHBase method searchFeatureUsageEvents.

/**
 * {@inheritDoc}
 */
@Override
public EventSeries searchFeatureUsageEvents(EventQueryDefinition query) {
    EventSeries es = new EventSeries();
    try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) {
        try (Table table = hbConn.getTable(AUDIT_TABLENAME)) {
            query.getActionFilters().add(ACTION_CHECK_OK);
            Scan scanQuery = buildQuery(query, COLS_EVENT, EventConstants.TARGET_FEATURE);
            try (ResultScanner scanner = table.getScanner(scanQuery)) {
                for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
                    es.add(MAPPER.fromStore(rr));
                }
            }
        }
    } catch (IOException e) {
        throw new AuditAccessException("Cannot search feature usage ", e);
    }
    return es;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) EventSeries(org.ff4j.audit.EventSeries) HBaseConnection(org.ff4j.hbase.HBaseConnection) Connection(org.apache.hadoop.hbase.client.Connection) Scan(org.apache.hadoop.hbase.client.Scan) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) AuditAccessException(org.ff4j.exception.AuditAccessException)

Example 5 with EventSeries

use of org.ff4j.audit.EventSeries in project ff4j by ff4j.

the class InMemoryEventRepository method saveEvent.

/**
 * Save event to target (based on ACTION).
 *
 * @param e
 *            current event
 * @param target
 *            target list
 * @return if the evetn is stored
 */
private boolean saveEvent(Event e, Map<String, Map<String, EventSeries>> target) {
    String key = getKeyDate(e.getTimestamp());
    String uid = e.getName();
    if (!target.containsKey(key)) {
        target.put(key, new ConcurrentHashMap<String, EventSeries>());
    }
    if (!target.get(key).containsKey(uid)) {
        target.get(key).put(uid, new EventSeries(this.queueCapacity));
    }
    return target.get(key).get(uid).add(e);
}
Also used : EventSeries(org.ff4j.audit.EventSeries)

Aggregations

EventSeries (org.ff4j.audit.EventSeries)18 Event (org.ff4j.audit.Event)8 Test (org.junit.Test)5 ResultSet (com.datastax.driver.core.ResultSet)2 Row (com.datastax.driver.core.Row)2 JestResult (io.searchbox.client.JestResult)2 IOException (java.io.IOException)2 Timestamp (java.sql.Timestamp)2 Connection (org.apache.hadoop.hbase.client.Connection)2 Result (org.apache.hadoop.hbase.client.Result)2 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 Scan (org.apache.hadoop.hbase.client.Scan)2 Table (org.apache.hadoop.hbase.client.Table)2 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)2 AuditAccessException (org.ff4j.exception.AuditAccessException)2 HBaseConnection (org.ff4j.hbase.HBaseConnection)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1