Search in sources :

Example 11 with EventSeries

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

the class InMemoryEventRepository method saveEvent.

/**
 * {@inheritDoc}
 */
@Override
public boolean saveEvent(Event e) {
    Util.assertEvent(e);
    if (EventConstants.ACTION_CHECK_OK.equalsIgnoreCase(e.getAction())) {
        return saveEvent(e, featureUsageEvents);
    } else if (EventConstants.ACTION_CHECK_OFF.equalsIgnoreCase(e.getAction())) {
        return saveEvent(e, checkOffEvents);
    }
    String key = getKeyDate(e.getTimestamp());
    if (!auditTrailEvents.containsKey(key)) {
        auditTrailEvents.put(key, new EventSeries(this.queueCapacity));
    }
    return auditTrailEvents.get(key).add(e);
}
Also used : EventSeries(org.ff4j.audit.EventSeries)

Example 12 with EventSeries

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

the class InMemoryEventRepository method searchEventById.

/**
 * Given a date fetch in all the list to find the Event.
 *
 * @param uuid
 *      current event unique identifier
 * @param targetDate
 *      target date
 * @return
 *      event if found
 */
private Event searchEventById(String uuid, String targetDate) {
    Util.assertNotNull(targetDate, uuid);
    // Audit
    Event evt = getFromEventSeries(auditTrailEvents.get(targetDate), uuid);
    if (evt != null) {
        return evt;
    }
    // FeatureUsage
    Map<String, EventSeries> maOfFeaturesIsages = featureUsageEvents.get(targetDate);
    if (maOfFeaturesIsages != null) {
        for (EventSeries es : maOfFeaturesIsages.values()) {
            evt = getFromEventSeries(es, uuid);
            if (evt != null) {
                return evt;
            }
        }
    }
    // CheckOff
    Map<String, EventSeries> maOfChecKoff = checkOffEvents.get(targetDate);
    if (maOfChecKoff != null) {
        for (EventSeries es : maOfChecKoff.values()) {
            evt = getFromEventSeries(es, uuid);
            if (evt != null) {
                return evt;
            }
        }
    }
    return evt;
}
Also used : EventSeries(org.ff4j.audit.EventSeries) Event(org.ff4j.audit.Event)

Example 13 with EventSeries

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

the class EventRepositoryElastic method searchFeatureUsageEvents.

@Override
public EventSeries searchFeatureUsageEvents(EventQueryDefinition query) {
    JestResult result = getConnection().execute(getBuilder().queryGetEventQueryDefinition(query, EventConstants.ACTION_CHECK_OK));
    List<Event> events = result.getSourceAsObjectList(Event.class);
    EventSeries es = new EventSeries();
    for (Event event : events) {
        es.add(event);
    }
    return es;
}
Also used : EventSeries(org.ff4j.audit.EventSeries) Event(org.ff4j.audit.Event) JestResult(io.searchbox.client.JestResult)

Example 14 with EventSeries

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

the class EventRepositoryCassandra method getAuditTrail.

/**
 * {@inheritDoc}
 */
@Override
public EventSeries getAuditTrail(EventQueryDefinition query) {
    String cqlQuery = getBuilder().cqlAuditTrail(query);
    LOGGER.debug("Query " + cqlQuery);
    ResultSet rs = conn.getSession().execute(cqlQuery);
    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 (Row row : rs.all()) {
        if (candidates.contains(row.getString(COL_EVENT_ACTION)))
            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 15 with EventSeries

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

the class AbstractEventRepositoryTest method testLimitEventSeries.

/**
 * TDD.
 */
@Test
public void testLimitEventSeries() throws InterruptedException {
    EventSeries es = new EventSeries(5);
    for (int i = 0; i < 10; i++) {
        Thread.sleep(10);
        es.add(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
    }
    Assert.assertEquals(5, es.size());
}
Also used : EventSeries(org.ff4j.audit.EventSeries) Event(org.ff4j.audit.Event) Test(org.junit.Test)

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