Search in sources :

Example 6 with EventSeries

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

the class InMemoryEventRepository method getFeatureUsageHistory.

/**
 * {@inheritDoc}
 */
@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit units) {
    // Create the interval depending on units
    TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), units);
    for (String currentDay : getCandidateDays(query.getFrom(), query.getTo())) {
        // There are some event this day
        if (featureUsageEvents.containsKey(currentDay)) {
            for (Map.Entry<String, EventSeries> entry : featureUsageEvents.get(currentDay).entrySet()) {
                String currentFeatureName = entry.getKey();
                // Filter feature names if required
                Set<String> filteredFeatures = query.getNamesFilter();
                if (filteredFeatures == null || filteredFeatures.isEmpty() || filteredFeatures.contains(currentFeatureName)) {
                    // Loop over events
                    for (Event evt : entry.getValue()) {
                        // Between bounds (keydate not enough)
                        if (isEventInInterval(evt, query.getFrom(), query.getTo())) {
                            // Create new serie if new feature Name
                            if (!tsc.getSeries().containsKey((currentFeatureName))) {
                                tsc.createNewSerie(currentFeatureName);
                            }
                            // Match FeatureName
                            Serie<Map<String, MutableHitCount>> serie = tsc.getSeries().get(currentFeatureName);
                            // Match SlotName
                            String slotName = tsc.getSdf().format(new Date(evt.getTimestamp()));
                            // Should be always 'true' as the tsc.getsdf().format() will get a slotName.
                            if (serie.getValue().containsKey(slotName)) {
                                // Fast Increment
                                serie.getValue().get(slotName).inc();
                            }
                        }
                    }
                }
            }
        }
    }
    // Recolor series
    List<String> colors = Util.generateHSVGradient("ee1100", "442299", tsc.getSeries().size());
    int idxColor = 0;
    for (Map.Entry<String, Serie<Map<String, MutableHitCount>>> serie : tsc.getSeries().entrySet()) {
        serie.getValue().setColor(colors.get(idxColor));
        idxColor++;
    }
    return tsc;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) EventSeries(org.ff4j.audit.EventSeries) Date(java.util.Date) MutableHitCount(org.ff4j.audit.MutableHitCount) Event(org.ff4j.audit.Event) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Serie(org.ff4j.audit.chart.Serie)

Example 7 with EventSeries

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

the class JdbcEventRepository method searchEvents.

/**
 * {@inheritDoc}
 */
private EventSeries searchEvents(String sqlQuery, long from, long to) {
    Connection sqlConn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    EventSeries es = new EventSeries();
    try {
        sqlConn = getDataSource().getConnection();
        ps = sqlConn.prepareStatement(sqlQuery);
        ps.setTimestamp(1, new Timestamp(from));
        ps.setTimestamp(2, new Timestamp(to));
        rs = ps.executeQuery();
        while (rs.next()) {
            es.add(EVENT_MAPPER.mapEvent(rs));
        }
    } catch (SQLException sqlEX) {
        throw new IllegalStateException("CANNOT_READ_AUDITTABLE", sqlEX);
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeConnection(sqlConn);
    }
    return es;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) ResultSet(java.sql.ResultSet) JdbcUtils.closeResultSet(org.ff4j.utils.JdbcUtils.closeResultSet) EventSeries(org.ff4j.audit.EventSeries) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 8 with EventSeries

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

the class AbstractEventRepositoryTest 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 9 with EventSeries

use of org.ff4j.audit.EventSeries 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 10 with EventSeries

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

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