Package org.nuxeo.elasticsearch.audit
Class ESAuditBackend
- java.lang.Object
-
- org.nuxeo.ecm.platform.audit.service.AbstractAuditBackend
-
- org.nuxeo.elasticsearch.audit.ESAuditBackend
-
- All Implemented Interfaces:
AuditAdmin
,AuditLogger
,AuditReader
,AuditStorage
,Logs
,AuditBackend
public class ESAuditBackend extends AbstractAuditBackend implements AuditBackend
Implementation of theAuditBackend
interface using Elasticsearch persistence- Author:
- tiry
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ESAuditBackend.ESCursorResult
-
Field Summary
Fields Modifier and Type Field Description protected static String
AUDIT_LATEST_LOG_ID_AFTER_DATE_PROP
protected CursorService<Iterator<org.elasticsearch.search.SearchHit>,org.elasticsearch.search.SearchHit,String>
cursorService
protected ESClient
esClient
protected String
latestLogIdAfterDate
protected static Log
log
static String
MIGRATION_BATCH_SIZE_PROP
static int
MIGRATION_DEFAULT_BACTH_SIZE
static String
MIGRATION_DONE_EVENT
static String
MIGRATION_FLAG_PROP
protected BaseLogEntryProvider
provider
static String
SEQ_NAME
-
Fields inherited from class org.nuxeo.ecm.platform.audit.service.AbstractAuditBackend
component, config, expressionEvaluator, FORCE_AUDIT_FACET
-
-
Constructor Summary
Constructors Constructor Description ESAuditBackend()
ESAuditBackend(NXAuditEventsService component, AuditBackendDescriptor config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLogEntries(List<LogEntry> entries)
Adds given log entries.void
append(List<String> jsonEntries)
protected org.elasticsearch.index.query.QueryBuilder
buildFilter(PredicateDefinition[] predicates, DocumentModel searchDocumentModel)
protected List<LogEntry>
buildLogEntries(org.elasticsearch.action.search.SearchResponse searchResponse)
org.elasticsearch.action.search.SearchRequest
buildQuery(String query, Map<String,Object> params)
org.elasticsearch.action.search.SearchRequest
buildSearchQuery(String fixedPart, PredicateDefinition[] predicates, DocumentModel searchDocumentModel)
protected Object
convertDate(Object o)
protected org.elasticsearch.index.query.QueryBuilder
createQueryBuilder(MultiExpression andPredicate)
protected org.elasticsearch.action.search.SearchRequest
createSearchRequest()
protected org.elasticsearch.search.builder.SearchSourceBuilder
createSearchRequestSource(MultiExpression predicate, OrderByList orders)
protected org.elasticsearch.search.builder.SearchSourceBuilder
createSearchSourceBuilder(String query)
protected void
ensureUIDSequencer(ESClient esClient)
Ensures the audit sequence returns an UID greater or equal than the maximum log entry id.String
expandQueryVariables(String query, Object[] params)
String
expandQueryVariables(String query, Map<String,Object> params)
int
getApplicationStartedOrder()
protected ESClient
getClient()
protected String
getESIndexName()
Long
getEventsCount(String eventId)
long
getLatestLogId(String repositoryId, String... eventIds)
Returns the latest log id matching events and repository or 0 when no match found.protected String
getLatestLogIdAfterDate()
LogEntry
getLogEntryByID(long id)
Returns a given log entry given its id.protected boolean
isMigrationDone()
protected boolean
isNonNullParam(Object[] val)
protected void
logSearchRequest(org.elasticsearch.action.search.SearchRequest request)
protected void
logSearchResponse(org.elasticsearch.action.search.SearchResponse response)
String
migrate(int batchSize)
List<?>
nativeQuery(String query, Map<String,Object> params, int pageNb, int pageSize)
Returns a batched list of entries.ExtendedInfo
newExtendedInfo(Serializable value)
Create a new ExtendedInfo instancevoid
onApplicationStarted()
void
onApplicationStopped()
List<LogEntry>
queryLogs(QueryBuilder builder)
Returns the logs given a collection of predicates and a default sort.List<LogEntry>
queryLogsByPage(String[] eventIds, Date limit, String[] categories, String path, int pageNb, int pageSize)
ScrollResult<String>
scroll(String scrollId)
ScrollResult<String>
scroll(QueryBuilder builder, int batchSize, int keepAliveSeconds)
org.elasticsearch.action.search.SearchResponse
search(org.elasticsearch.action.search.SearchRequest request)
long
syncLogCreationEntries(String repoId, String path, Boolean recurs)
Forces log Synchronisation for a branch of the repository.-
Methods inherited from class org.nuxeo.ecm.platform.audit.service.AbstractAuditBackend
await, buildEntryFromEvent, convert, doCreateAndFillEntryFromDocument, doPutExtendedInfos, doSyncNode, getAuditableEventNames, getLogEntriesAfter, getLogEntriesFor, guardedDocument, guardedDocumentChildren, isAuditable, logEvent, logEvents, newLogEntry, populateExtendedInfo, restore, syncLogCreationEntries
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.platform.audit.service.AuditBackend
onShutdown, restore
-
Methods inherited from interface org.nuxeo.ecm.platform.audit.api.AuditLogger
await, buildEntryFromEvent, getAuditableEventNames, logEvent, logEvents, newLogEntry
-
Methods inherited from interface org.nuxeo.ecm.platform.audit.api.AuditReader
getLogEntriesAfter, getLogEntriesFor, getLogEntriesFor, getLogEntriesFor, nativeQuery, nativeQueryLogs, queryLogs, queryLogsByPage, queryLogsByPage, queryLogsByPage
-
-
-
-
Field Detail
-
SEQ_NAME
public static final String SEQ_NAME
- See Also:
- Constant Field Values
-
MIGRATION_FLAG_PROP
public static final String MIGRATION_FLAG_PROP
- See Also:
- Constant Field Values
-
MIGRATION_BATCH_SIZE_PROP
public static final String MIGRATION_BATCH_SIZE_PROP
- See Also:
- Constant Field Values
-
MIGRATION_DONE_EVENT
public static final String MIGRATION_DONE_EVENT
- See Also:
- Constant Field Values
-
MIGRATION_DEFAULT_BACTH_SIZE
public static final int MIGRATION_DEFAULT_BACTH_SIZE
- See Also:
- Constant Field Values
-
AUDIT_LATEST_LOG_ID_AFTER_DATE_PROP
protected static final String AUDIT_LATEST_LOG_ID_AFTER_DATE_PROP
- See Also:
- Constant Field Values
-
latestLogIdAfterDate
protected String latestLogIdAfterDate
-
cursorService
protected CursorService<Iterator<org.elasticsearch.search.SearchHit>,org.elasticsearch.search.SearchHit,String> cursorService
-
esClient
protected ESClient esClient
-
log
protected static final Log log
-
provider
protected BaseLogEntryProvider provider
-
-
Constructor Detail
-
ESAuditBackend
public ESAuditBackend(NXAuditEventsService component, AuditBackendDescriptor config)
-
ESAuditBackend
public ESAuditBackend()
- Since:
- 9.3
-
-
Method Detail
-
getClient
protected ESClient getClient()
-
isMigrationDone
protected boolean isMigrationDone()
-
getApplicationStartedOrder
public int getApplicationStartedOrder()
- Specified by:
getApplicationStartedOrder
in interfaceAuditBackend
-
onApplicationStarted
public void onApplicationStarted()
- Specified by:
onApplicationStarted
in interfaceAuditBackend
-
onApplicationStopped
public void onApplicationStopped()
- Specified by:
onApplicationStopped
in interfaceAuditBackend
-
queryLogs
public List<LogEntry> queryLogs(QueryBuilder builder)
Description copied from interface:AuditReader
Returns the logs given a collection of predicates and a default sort.- Specified by:
queryLogs
in interfaceAuditReader
- Parameters:
builder
- the query builder to fetch log entries- Returns:
- a list of log entries
-
createSearchRequestSource
protected org.elasticsearch.search.builder.SearchSourceBuilder createSearchRequestSource(MultiExpression predicate, OrderByList orders)
-
createQueryBuilder
protected org.elasticsearch.index.query.QueryBuilder createQueryBuilder(MultiExpression andPredicate)
-
buildLogEntries
protected List<LogEntry> buildLogEntries(org.elasticsearch.action.search.SearchResponse searchResponse)
-
createSearchRequest
protected org.elasticsearch.action.search.SearchRequest createSearchRequest()
-
getLogEntryByID
public LogEntry getLogEntryByID(long id)
Description copied from interface:AuditReader
Returns a given log entry given its id.- Specified by:
getLogEntryByID
in interfaceAuditReader
- Parameters:
id
- the log entry identifier- Returns:
- a LogEntry instance
-
buildQuery
public org.elasticsearch.action.search.SearchRequest buildQuery(String query, Map<String,Object> params)
-
createSearchSourceBuilder
protected org.elasticsearch.search.builder.SearchSourceBuilder createSearchSourceBuilder(String query)
-
nativeQuery
public List<?> nativeQuery(String query, Map<String,Object> params, int pageNb, int pageSize)
Description copied from interface:AuditReader
Returns a batched list of entries.- Specified by:
nativeQuery
in interfaceAuditReader
- Parameters:
query
- a JPA query language query if implementation of audit backend is JPA (< 7.3 or audit.elasticsearch.enabled=false) and JSON if implementation is Elasticsearchparams
- parameters for the querypageNb
- the page number (starts at 1)pageSize
- the number of results per page
-
queryLogsByPage
public List<LogEntry> queryLogsByPage(String[] eventIds, Date limit, String[] categories, String path, int pageNb, int pageSize)
- Specified by:
queryLogsByPage
in interfaceAuditReader
- Overrides:
queryLogsByPage
in classAbstractAuditBackend
-
addLogEntries
public void addLogEntries(List<LogEntry> entries)
Description copied from interface:AuditLogger
Adds given log entries.- Specified by:
addLogEntries
in interfaceAuditLogger
- Parameters:
entries
- the list of log entries.
-
getEventsCount
public Long getEventsCount(String eventId)
- Specified by:
getEventsCount
in interfaceAuditAdmin
-
syncLogCreationEntries
public long syncLogCreationEntries(String repoId, String path, Boolean recurs)
Description copied from interface:AuditAdmin
Forces log Synchronisation for a branch of the repository. This can be useful to add the create entries if DB was initialized from a bulk import.- Specified by:
syncLogCreationEntries
in interfaceAuditAdmin
-
search
public org.elasticsearch.action.search.SearchResponse search(org.elasticsearch.action.search.SearchRequest request)
-
buildFilter
protected org.elasticsearch.index.query.QueryBuilder buildFilter(PredicateDefinition[] predicates, DocumentModel searchDocumentModel)
-
buildSearchQuery
public org.elasticsearch.action.search.SearchRequest buildSearchQuery(String fixedPart, PredicateDefinition[] predicates, DocumentModel searchDocumentModel)
-
isNonNullParam
protected boolean isNonNullParam(Object[] val)
-
migrate
public String migrate(int batchSize)
-
logSearchResponse
protected void logSearchResponse(org.elasticsearch.action.search.SearchResponse response)
-
logSearchRequest
protected void logSearchRequest(org.elasticsearch.action.search.SearchRequest request)
-
ensureUIDSequencer
protected void ensureUIDSequencer(ESClient esClient)
Ensures the audit sequence returns an UID greater or equal than the maximum log entry id.
-
newExtendedInfo
public ExtendedInfo newExtendedInfo(Serializable value)
Description copied from interface:AuditLogger
Create a new ExtendedInfo instance- Specified by:
newExtendedInfo
in interfaceAuditLogger
- Specified by:
newExtendedInfo
in classAbstractAuditBackend
-
getESIndexName
protected String getESIndexName()
-
append
public void append(List<String> jsonEntries)
- Specified by:
append
in interfaceAuditStorage
-
scroll
public ScrollResult<String> scroll(QueryBuilder builder, int batchSize, int keepAliveSeconds)
- Specified by:
scroll
in interfaceAuditStorage
-
scroll
public ScrollResult<String> scroll(String scrollId)
- Specified by:
scroll
in interfaceAuditStorage
-
getLatestLogId
public long getLatestLogId(String repositoryId, String... eventIds)
Description copied from interface:AuditReader
Returns the latest log id matching events and repository or 0 when no match found.- Specified by:
getLatestLogId
in interfaceAuditReader
- Overrides:
getLatestLogId
in classAbstractAuditBackend
-
getLatestLogIdAfterDate
protected String getLatestLogIdAfterDate()
-
-