Search in sources :

Example 26 with Event

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

the class EventRepositoryTestSupport method testSearchFeatureUsageEvents.

@Test
public void testSearchFeatureUsageEvents() throws InterruptedException {
    long start = System.currentTimeMillis();
    repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
    for (int i = 0; i < 8; i++) {
        Thread.sleep(100);
        repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
        repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
    }
    Thread.sleep(100);
    // Then
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
    EventSeries es = repo.searchFeatureUsageEvents(testQuery);
    Assert.assertEquals(16, es.size());
// Then
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) EventSeries(org.ff4j.audit.EventSeries) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 27 with Event

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

the class EventRepositoryTestSupport 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)

Example 28 with Event

use of org.ff4j.audit.Event 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 29 with Event

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

the class CassandraMapper method mapEvent.

/**
 * Marshall from cassandra row to bean {@link Event}.
 *
 * @param row
 *      current cassandra row
 * @return
 *      target property bean
 */
public static Event mapEvent(Row row) {
    if (row == null)
        return null;
    Event evt = new Event(row.getString(COL_EVENT_SOURCE), row.getString(COL_EVENT_TYPE), row.getString(COL_EVENT_NAME), row.getString(COL_EVENT_ACTION));
    evt.setUuid(row.getString(COL_EVENT_UID));
    evt.setCustomKeys(row.getMap(COL_EVENT_KEYS, String.class, String.class));
    evt.setDuration(row.getLong(COL_EVENT_DURATION));
    evt.setHostName(row.getString(COL_EVENT_HOSTNAME));
    evt.setTimestamp(row.getTimestamp(COL_EVENT_TIME).getTime());
    evt.setUser(row.getString(COL_EVENT_USER));
    evt.setValue(row.getString(COL_EVENT_VALUE));
    return evt;
}
Also used : Event(org.ff4j.audit.Event)

Example 30 with Event

use of org.ff4j.audit.Event 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)

Aggregations

Event (org.ff4j.audit.Event)56 Test (org.junit.Test)32 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)22 MutableHitCount (org.ff4j.audit.MutableHitCount)15 EventSeries (org.ff4j.audit.EventSeries)8 TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)8 JestResult (io.searchbox.client.JestResult)6 HashMap (java.util.HashMap)5 EventRepository (org.ff4j.audit.repository.EventRepository)4 InMemoryEventRepository (org.ff4j.audit.repository.InMemoryEventRepository)4 Date (java.util.Date)2 TreeMap (java.util.TreeMap)2 EventPublisher (org.ff4j.audit.EventPublisher)2 EventWorker (org.ff4j.audit.EventWorker)2 BarChart (org.ff4j.audit.chart.BarChart)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 FF4j (org.ff4j.FF4j)1 Serie (org.ff4j.audit.chart.Serie)1 MongoEventMapper (org.ff4j.mongo.mapper.MongoEventMapper)1