Search in sources :

Example 16 with MutableHitCount

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

the class JdbcEventRepository method computeHitCount.

/**
 * {@inheritDoc}
 */
private Map<String, MutableHitCount> computeHitCount(String sqlQuery, String columnName, long from, long to) {
    Connection sqlConn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
    try {
        // Returns features
        sqlConn = dataSource.getConnection();
        ps = sqlConn.prepareStatement(sqlQuery);
        ps.setTimestamp(1, new Timestamp(from));
        ps.setTimestamp(2, new Timestamp(to));
        rs = ps.executeQuery();
        while (rs.next()) {
            hitCount.put(rs.getString(columnName), new MutableHitCount(rs.getInt("NB")));
        }
    } catch (SQLException sqlEX) {
        throw new FeatureAccessException(CANNOT_BUILD_PIE_CHART_FROM_REPOSITORY, sqlEX);
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeConnection(sqlConn);
    }
    return hitCount;
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) HashMap(java.util.HashMap) 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) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 17 with MutableHitCount

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

the class TimeSeriesChart method createNewSerie.

/**
 * Create new Serie with existing slots.
 *
 * @param idSerie
 *      target serie id
 */
public void createNewSerie(String idSerie) {
    // Init new Serie
    Serie<Map<String, MutableHitCount>> newSerie = new Serie<Map<String, MutableHitCount>>(idSerie);
    // Populate slots
    Map<String, MutableHitCount> val = new HashMap<String, MutableHitCount>();
    for (String slot : timeSlots) {
        val.put(slot, new MutableHitCount());
    }
    newSerie.setValue(val);
    series.put(idSerie, newSerie);
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 18 with MutableHitCount

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

the class EventRepositoryElastic method getSourceHitCount.

@Override
public Map<String, MutableHitCount> getSourceHitCount(EventQueryDefinition query) {
    JestResult result = getConnection().execute(getBuilder().queryGetEventQueryDefinition(query, EventConstants.ACTION_CHECK_OK));
    List<Event> events = result.getSourceAsObjectList(Event.class);
    Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
    for (Event event : events) {
        String source = event.getSource();
        if (hitCount.containsKey(source)) {
            hitCount.get(source).inc();
        } else {
            hitCount.put(source, new MutableHitCount(1));
        }
    }
    return hitCount;
}
Also used : HashMap(java.util.HashMap) Event(org.ff4j.audit.Event) JestResult(io.searchbox.client.JestResult) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 19 with MutableHitCount

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

the class EventRepositoryElastic method getHostHitCount.

@Override
public Map<String, MutableHitCount> getHostHitCount(EventQueryDefinition query) {
    JestResult result = getConnection().execute(getBuilder().queryGetEventQueryDefinition(query, EventConstants.ACTION_CHECK_OK));
    List<Event> events = result.getSourceAsObjectList(Event.class);
    Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
    for (Event event : events) {
        String hostName = event.getHostName();
        if (hitCount.containsKey(hostName)) {
            hitCount.get(hostName).inc();
        } else {
            hitCount.put(hostName, new MutableHitCount(1));
        }
    }
    return hitCount;
}
Also used : HashMap(java.util.HashMap) Event(org.ff4j.audit.Event) JestResult(io.searchbox.client.JestResult) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 20 with MutableHitCount

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

the class EventRepositoryCassandra method getFeatureUsageHitCount.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, MutableHitCount> getFeatureUsageHitCount(EventQueryDefinition query) {
    String cqlQuery = getBuilder().cqlFeatureUsageHitCount(query);
    LOGGER.debug("Query " + cqlQuery);
    ResultSet rs = conn.getSession().execute(cqlQuery);
    Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
    for (Row row : rs.all()) {
        String featureName = row.getString(COL_EVENT_NAME);
        if (hitCount.containsKey(featureName)) {
            hitCount.get(featureName).inc();
        } else {
            hitCount.put(featureName, new MutableHitCount(1));
        }
    }
    return hitCount;
}
Also used : HashMap(java.util.HashMap) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) MutableHitCount(org.ff4j.audit.MutableHitCount)

Aggregations

MutableHitCount (org.ff4j.audit.MutableHitCount)27 Event (org.ff4j.audit.Event)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)10 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)8 ResultSet (com.datastax.driver.core.ResultSet)4 Row (com.datastax.driver.core.Row)4 JestResult (io.searchbox.client.JestResult)4 Map (java.util.Map)3 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 TreeMap (java.util.TreeMap)2 Serie (org.ff4j.audit.chart.Serie)2 TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1