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 theAuditBackendinterface using Elasticsearch persistence- Author:
- tiry
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classESAuditBackend.ESCursorResult
-
Field Summary
Fields Modifier and Type Field Description protected static StringAUDIT_LATEST_LOG_ID_AFTER_DATE_PROPprotected CursorService<Iterator<org.elasticsearch.search.SearchHit>,org.elasticsearch.search.SearchHit,String>cursorServiceprotected ESClientesClientprotected StringlatestLogIdAfterDateprotected static Loglogstatic StringMIGRATION_BATCH_SIZE_PROPstatic intMIGRATION_DEFAULT_BACTH_SIZEstatic StringMIGRATION_DONE_EVENTstatic StringMIGRATION_FLAG_PROPprotected BaseLogEntryProviderproviderstatic StringSEQ_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 voidaddLogEntries(List<LogEntry> entries)Adds given log entries.voidappend(List<String> jsonEntries)protected org.elasticsearch.index.query.QueryBuilderbuildFilter(PredicateDefinition[] predicates, DocumentModel searchDocumentModel)protected List<LogEntry>buildLogEntries(org.elasticsearch.action.search.SearchResponse searchResponse)org.elasticsearch.action.search.SearchRequestbuildQuery(String query, Map<String,Object> params)org.elasticsearch.action.search.SearchRequestbuildSearchQuery(String fixedPart, PredicateDefinition[] predicates, DocumentModel searchDocumentModel)protected ObjectconvertDate(Object o)protected org.elasticsearch.index.query.QueryBuildercreateQueryBuilder(MultiExpression andPredicate)protected org.elasticsearch.action.search.SearchRequestcreateSearchRequest()protected org.elasticsearch.search.builder.SearchSourceBuildercreateSearchRequestSource(MultiExpression predicate, OrderByList orders)protected org.elasticsearch.search.builder.SearchSourceBuildercreateSearchSourceBuilder(String query)protected voidensureUIDSequencer(ESClient esClient)Ensures the audit sequence returns an UID greater or equal than the maximum log entry id.StringexpandQueryVariables(String query, Object[] params)StringexpandQueryVariables(String query, Map<String,Object> params)intgetApplicationStartedOrder()protected ESClientgetClient()protected StringgetESIndexName()LonggetEventsCount(String eventId)longgetLatestLogId(String repositoryId, String... eventIds)Returns the latest log id matching events and repository or 0 when no match found.protected StringgetLatestLogIdAfterDate()LogEntrygetLogEntryByID(long id)Returns a given log entry given its id.protected booleanisMigrationDone()protected booleanisNonNullParam(Object[] val)protected voidlogSearchRequest(org.elasticsearch.action.search.SearchRequest request)protected voidlogSearchResponse(org.elasticsearch.action.search.SearchResponse response)Stringmigrate(int batchSize)List<?>nativeQuery(String query, Map<String,Object> params, int pageNb, int pageSize)Returns a batched list of entries.ExtendedInfonewExtendedInfo(Serializable value)Create a new ExtendedInfo instancevoidonApplicationStarted()voidonApplicationStopped()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.SearchResponsesearch(org.elasticsearch.action.search.SearchRequest request)longsyncLogCreationEntries(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:
getApplicationStartedOrderin interfaceAuditBackend
-
onApplicationStarted
public void onApplicationStarted()
- Specified by:
onApplicationStartedin interfaceAuditBackend
-
onApplicationStopped
public void onApplicationStopped()
- Specified by:
onApplicationStoppedin interfaceAuditBackend
-
queryLogs
public List<LogEntry> queryLogs(QueryBuilder builder)
Description copied from interface:AuditReaderReturns the logs given a collection of predicates and a default sort.- Specified by:
queryLogsin 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:AuditReaderReturns a given log entry given its id.- Specified by:
getLogEntryByIDin 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:AuditReaderReturns a batched list of entries.- Specified by:
nativeQueryin 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:
queryLogsByPagein interfaceAuditReader- Overrides:
queryLogsByPagein classAbstractAuditBackend
-
addLogEntries
public void addLogEntries(List<LogEntry> entries)
Description copied from interface:AuditLoggerAdds given log entries.- Specified by:
addLogEntriesin interfaceAuditLogger- Parameters:
entries- the list of log entries.
-
getEventsCount
public Long getEventsCount(String eventId)
- Specified by:
getEventsCountin interfaceAuditAdmin
-
syncLogCreationEntries
public long syncLogCreationEntries(String repoId, String path, Boolean recurs)
Description copied from interface:AuditAdminForces 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:
syncLogCreationEntriesin 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:AuditLoggerCreate a new ExtendedInfo instance- Specified by:
newExtendedInfoin interfaceAuditLogger- Specified by:
newExtendedInfoin classAbstractAuditBackend
-
getESIndexName
protected String getESIndexName()
-
append
public void append(List<String> jsonEntries)
- Specified by:
appendin interfaceAuditStorage
-
scroll
public ScrollResult<String> scroll(QueryBuilder builder, int batchSize, int keepAliveSeconds)
- Specified by:
scrollin interfaceAuditStorage
-
scroll
public ScrollResult<String> scroll(String scrollId)
- Specified by:
scrollin interfaceAuditStorage
-
getLatestLogId
public long getLatestLogId(String repositoryId, String... eventIds)
Description copied from interface:AuditReaderReturns the latest log id matching events and repository or 0 when no match found.- Specified by:
getLatestLogIdin interfaceAuditReader- Overrides:
getLatestLogIdin classAbstractAuditBackend
-
getLatestLogIdAfterDate
protected String getLatestLogIdAfterDate()
-
-