/** {@inheritDoc} */ @Override public Event getEventByUUID(String uuid, Long timestamp) { Util.assertHasLength(new String[]{uuid}); try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(AUDIT_TABLENAME)) { Get queryGetById = new Get(Bytes.toBytes(uuid)); return MAPPER.fromStore(table.get(queryGetById)); } } catch (IOException e) { throw new AuditAccessException("Cannot check feature existence", e); } }
/** {@inheritDoc} */ private Map<String, MutableHitCount> computeHitCount(EventQueryDefinition query, String pColName) { Map < String, MutableHitCount > hitCount = new HashMap<String, MutableHitCount>(); try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(AUDIT_TABLENAME)) { query.getActionFilters().add(ACTION_CHECK_OK); Scan scanQuery = buildQuery(query, Util.set(pColName), EventConstants.TARGET_FEATURE); try(ResultScanner scanner = table.getScanner(scanQuery)) { for (Result rr = scanner.next(); rr != null; rr = scanner.next()) { String colValue = Bytes.toString(rr.getValue(B_AUDIT_CF, Bytes.toBytes(pColName))); if (hitCount.containsKey(colValue)) { hitCount.get(colValue).inc(); } else { hitCount.put(colValue, new MutableHitCount(1)); } } } } } catch (IOException e) { throw new AuditAccessException("Compute hitcount based on " + pColName, e); } return hitCount; }
/** * Utility to insert data into events. * * @param putQuery * query to update DB. */ private void executePutCommand(Put putQuery) { try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(AUDIT_TABLENAME)) { table.put(putQuery); } } catch (IOException e) { throw new AuditAccessException("Cannot execute command", e); } }
/** {@inheritDoc} */ @Override public void purgeAuditTrail(EventQueryDefinition query) { try (Connection hbConn = ConnectionFactory.createConnection(conn.getConfig())) { try(Table table = hbConn.getTable(AUDIT_TABLENAME)) { query.getActionFilters().add(ACTION_CHECK_OK); // Scan for ids Scan scanQuery = buildQuery(query, Util.set(COL_EVENT_UID), null); List < Delete > list = new ArrayList<Delete>(); try(ResultScanner scanner = table.getScanner(scanQuery)) { for (Result rr = scanner.next(); rr != null; rr = scanner.next()) { list.add(new Delete(rr.getValue(B_AUDIT_CF, B_EVENT_UID))); } } table.delete(list); } } catch (IOException e) { throw new AuditAccessException("Cannot search audit trail ", e); } }
throw new AuditAccessException("Cannot insert event into DB (" + exc.getClass() + ") "+ exc.getCause(), exc); } finally { closeStatement(stmt);
/** {@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; }
/** {@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; }
throw new AuditAccessException("Cannot execute command", e);