Package com.flowable.indexing
Class IndexManagerImpl
java.lang.Object
com.flowable.indexing.IndexManagerImpl
- All Implemented Interfaces:
IndexManager
,java.util.EventListener
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
,org.springframework.core.Ordered
public class IndexManagerImpl extends java.lang.Object implements IndexManager, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>, org.springframework.context.ApplicationContextAware, org.springframework.core.Ordered, org.springframework.beans.factory.InitializingBean
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.context.ApplicationContext
applicationContext
protected java.util.List<CustomIndexConfiguration>
customConfigurations
protected java.util.Map<java.lang.String,IndexMapping>
customMappings
static int
DEFAULT_ORDER
protected ElasticsearchClient
elasticsearchClient
protected static java.lang.String
FULL_TEXT_VARIABLES_FIELD
protected static java.time.format.DateTimeFormatter
INDEX_SUFFIX_FORMAT
protected java.util.Map<java.lang.String,CustomIndexConfiguration>
indexedDocumentTypes
protected java.util.Map<java.lang.String,IndexMapping>
indexMappings
protected java.lang.String
indexNamePrefix
protected IndexTemplateComposer
indexTemplateComposer
protected java.util.List<java.lang.String>
indices
protected java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager>
lockManagerProvider
protected org.springframework.core.io.Resource[]
mappingExtensionResources
protected org.springframework.core.io.Resource[]
mappingResources
protected java.time.Duration
mappingSchemaLockWaitTime
protected static int
MINIMAL_COMPATIBLE_ES_VERSION
protected com.fasterxml.jackson.databind.ObjectMapper
objectMapper
protected int
order
protected static java.lang.String
PROPERTIES_FIELD
protected static java.lang.String
SETTINGS_FIELD
protected boolean
useLockForIndexMappingCreation
protected static java.lang.String
VARIABLE_EXTRACTORS_FIELD
protected static java.lang.String
VARIABLE_PROPERTIES_FIELD
-
Constructor Summary
Constructors Constructor Description IndexManagerImpl(ElasticsearchClient elasticsearchClient, java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager> lockManagerProvider, java.lang.String indexNamePrefix, java.lang.String projectName, org.springframework.core.io.Resource[] mappingResources, org.springframework.core.io.Resource[] mappingExtensionResources, IndexTemplateComposer indexTemplateComposer, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
IndexManagerImpl(ElasticsearchClient elasticsearchClient, java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager> lockManagerProvider, java.lang.String indexNamePrefix, java.lang.String projectName, org.springframework.core.io.Resource[] mappingResources, org.springframework.core.io.Resource[] mappingExtensionResources, IndexTemplateComposer indexTemplateComposer, com.fasterxml.jackson.databind.ObjectMapper objectMapper, boolean useLockForIndexMappingCreation, java.time.Duration mappingSchemaLockWaitTime)
-
Method Summary
Modifier and Type Method Description void
afterPropertiesSet()
protected boolean
compareExtensionMetadata(com.fasterxml.jackson.databind.JsonNode currentMapping, com.fasterxml.jackson.databind.JsonNode updateMapping)
protected void
createCustomAlias(java.lang.String alias, java.lang.String indexMapping)
protected java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>>
createCustomAliasesFromMappings(java.util.Map<java.lang.String,com.fasterxml.jackson.databind.JsonNode> indexMetaData)
protected void
createCustomMappings()
com.fasterxml.jackson.databind.JsonNode
createIndexAndAlias(java.lang.String alias, java.lang.String indexMapping)
void
createIndexesAndCustomAliasesFromMappings()
java.util.Map<java.lang.String,com.fasterxml.jackson.databind.JsonNode>
createIndexesFromMappings()
Creates the indices for all known mappingscom.fasterxml.jackson.databind.JsonNode
createIndexWithAlias(java.lang.String indexName)
Creates an index.java.lang.String
createIndexWithoutAlias(java.lang.String indexName)
Similar toIndexManager.createIndexWithAlias(String)
, but doesn't create an alias, only the index with the mapping.void
deleteAliasAndRelatedIndices(java.lang.String indexName)
Deletes the given index and all its aliases.void
deleteAllKnownIndices()
Deletes all indices registered in the systemvoid
deleteIndex(java.lang.String indexName)
Deletes the index with the given name.protected java.lang.String
enhanceIndexName(java.lang.String indexName)
protected void
enhanceMappingWithExtension(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations, CustomIndexConfiguration customIndexConfiguration, java.lang.String indexName)
protected void
enhanceProperties(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations, CustomIndexConfiguration customIndexConfiguration, java.lang.String indexName)
protected void
enhanceSettings(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations, CustomIndexConfiguration customIndexConfiguration, java.lang.String indexName)
protected void
enhanceVariableProperties(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations, CustomIndexConfiguration customIndexConfiguration, java.lang.String indexName)
IndexMapping
findIndexMapping(java.lang.String indexName)
java.util.List<IndexMapping>
findMatchingCustomMappings(java.lang.String indexName)
Returns a list ofIndexMapping
(s) that are applicable for the provided index name.java.util.List<IndexMapping>
findMatchingIndexMappings(com.fasterxml.jackson.databind.node.ObjectNode objectNode)
Returns a list ofIndexMapping
instances that are applicable for the provided data.java.util.List<IndexMapping>
findMatchingIndexMappings(java.lang.String mappingType)
Returns a list ofIndexMapping
(s) that are applicable for the provided mapping type.IndexMapping
getCustomQueryMapping(java.lang.String indexName, java.lang.String mappingName)
Get custom query mapping for given index if exists.java.lang.String
getESIndexName(java.lang.String indexName)
Returns the internal index name for the provided raw index name.CustomIndexConfiguration
getIndexConfiguration(java.lang.String indexName)
Returns the mapping information for the given index.java.lang.String
getIndexNamePrefix()
Returns the prefix that is added to all indices.java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager>
getLockManagerProvider()
protected com.fasterxml.jackson.databind.node.ObjectNode
getMappingDelta(com.fasterxml.jackson.databind.JsonNode currentMapping, com.fasterxml.jackson.databind.JsonNode updateMapping, java.lang.String currentType)
org.springframework.core.io.Resource[]
getMappingExtensionResources()
org.springframework.core.io.Resource[]
getMappingResources()
int
getOrder()
boolean
isKnownIndex(java.lang.String index)
Returns whether the index is a known mapped index.protected void
logElasticsearchVersionInformation()
void
onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
protected java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>>
processMappingExtensionResources()
protected void
processMappingResources(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations)
protected void
processResources()
protected void
processVariableMappings(CustomIndexMapping indexMapping, com.fasterxml.jackson.databind.JsonNode jsonNode)
IndexMapping
recreateMapping(IndexMapping indexMapping)
Used to recreate mapping ifCustomIndexConfiguration
changed.boolean
reloadIndex(java.lang.String indexName)
Reloads selected indexboolean
reloadIndices()
Reloads all indexesvoid
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
void
setLockManagerProvider(java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager> lockManagerProvider)
void
setMappingExtensionResources(org.springframework.core.io.Resource[] mappingExtensionResources)
void
setMappingResources(org.springframework.core.io.Resource[] mappingResources)
void
setOrder(int order)
protected void
updateExistingAliasMapping(IndexMapping customMapping)
protected com.fasterxml.jackson.databind.JsonNode
updateExistingMappingIfNeeded(java.lang.String indexName, IndexMapping indexMapping)
protected void
updateIndexAndMappingMetaData(java.lang.String index, com.fasterxml.jackson.databind.JsonNode metaData)
protected void
updateIndexMetaData(java.util.Map<java.lang.String,com.fasterxml.jackson.databind.JsonNode> indicesMetaData, java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> aliasesMetaData)
protected boolean
validateMappingExtensionJson(org.springframework.core.io.Resource mappingExtensionResource, com.fasterxml.jackson.databind.JsonNode mappingExtensionJson)
-
Field Details
-
DEFAULT_ORDER
public static final int DEFAULT_ORDER- See Also:
- Constant Field Values
-
INDEX_SUFFIX_FORMAT
protected static final java.time.format.DateTimeFormatter INDEX_SUFFIX_FORMAT -
MINIMAL_COMPATIBLE_ES_VERSION
protected static int MINIMAL_COMPATIBLE_ES_VERSION -
PROPERTIES_FIELD
protected static final java.lang.String PROPERTIES_FIELD- See Also:
- Constant Field Values
-
SETTINGS_FIELD
protected static final java.lang.String SETTINGS_FIELD- See Also:
- Constant Field Values
-
VARIABLE_PROPERTIES_FIELD
protected static final java.lang.String VARIABLE_PROPERTIES_FIELD- See Also:
- Constant Field Values
-
VARIABLE_EXTRACTORS_FIELD
protected static final java.lang.String VARIABLE_EXTRACTORS_FIELD- See Also:
- Constant Field Values
-
FULL_TEXT_VARIABLES_FIELD
protected static final java.lang.String FULL_TEXT_VARIABLES_FIELD- See Also:
- Constant Field Values
-
elasticsearchClient
-
lockManagerProvider
protected java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager> lockManagerProvider -
mappingResources
protected org.springframework.core.io.Resource[] mappingResources -
mappingExtensionResources
protected org.springframework.core.io.Resource[] mappingExtensionResources -
indexTemplateComposer
-
objectMapper
protected com.fasterxml.jackson.databind.ObjectMapper objectMapper -
indexNamePrefix
protected java.lang.String indexNamePrefix -
useLockForIndexMappingCreation
protected boolean useLockForIndexMappingCreation -
mappingSchemaLockWaitTime
protected java.time.Duration mappingSchemaLockWaitTime -
indexMappings
-
customMappings
-
customConfigurations
-
indices
protected java.util.List<java.lang.String> indices -
indexedDocumentTypes
-
applicationContext
protected org.springframework.context.ApplicationContext applicationContext -
order
protected int order
-
-
Constructor Details
-
IndexManagerImpl
public IndexManagerImpl(ElasticsearchClient elasticsearchClient, java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager> lockManagerProvider, java.lang.String indexNamePrefix, java.lang.String projectName, org.springframework.core.io.Resource[] mappingResources, org.springframework.core.io.Resource[] mappingExtensionResources, IndexTemplateComposer indexTemplateComposer, com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
IndexManagerImpl
public IndexManagerImpl(ElasticsearchClient elasticsearchClient, java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager> lockManagerProvider, java.lang.String indexNamePrefix, java.lang.String projectName, org.springframework.core.io.Resource[] mappingResources, org.springframework.core.io.Resource[] mappingExtensionResources, IndexTemplateComposer indexTemplateComposer, com.fasterxml.jackson.databind.ObjectMapper objectMapper, boolean useLockForIndexMappingCreation, java.time.Duration mappingSchemaLockWaitTime)
-
-
Method Details
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-
setOrder
public void setOrder(int order) -
processResources
protected void processResources() -
processMappingExtensionResources
protected java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> processMappingExtensionResources() -
validateMappingExtensionJson
protected boolean validateMappingExtensionJson(org.springframework.core.io.Resource mappingExtensionResource, com.fasterxml.jackson.databind.JsonNode mappingExtensionJson) -
processMappingResources
protected void processMappingResources(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations) -
processVariableMappings
protected void processVariableMappings(CustomIndexMapping indexMapping, com.fasterxml.jackson.databind.JsonNode jsonNode) -
enhanceMappingWithExtension
protected void enhanceMappingWithExtension(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations, CustomIndexConfiguration customIndexConfiguration, java.lang.String indexName) -
enhanceProperties
protected void enhanceProperties(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations, CustomIndexConfiguration customIndexConfiguration, java.lang.String indexName) -
enhanceVariableProperties
protected void enhanceVariableProperties(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations, CustomIndexConfiguration customIndexConfiguration, java.lang.String indexName) -
enhanceSettings
protected void enhanceSettings(java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> mappingExtensionConfigurations, CustomIndexConfiguration customIndexConfiguration, java.lang.String indexName) -
getIndexNamePrefix
public java.lang.String getIndexNamePrefix()Description copied from interface:IndexManager
Returns the prefix that is added to all indices. Empty by default.- Specified by:
getIndexNamePrefix
in interfaceIndexManager
-
getESIndexName
public java.lang.String getESIndexName(java.lang.String indexName)Description copied from interface:IndexManager
Returns the internal index name for the provided raw index name. As there might be an index-prefix in place, the index name towards the Elasticsearch client needs to use the internal name though which is returned using this method.- Specified by:
getESIndexName
in interfaceIndexManager
- Parameters:
indexName
- the index name as being used in configuration, query DSL and API- Returns:
- the index name as being used towards Elasticsearch (might have a prefix)
-
createIndexWithAlias
public com.fasterxml.jackson.databind.JsonNode createIndexWithAlias(java.lang.String indexName)Description copied from interface:IndexManager
Creates an index. The index mapping that is used will need to have as 'name' the passed index name. In fact, creates both an alias with the given name and the actual index, prefixed with the project name and with a timestamp. This allows later to change indices, but keep the alias and reindex.- Specified by:
createIndexWithAlias
in interfaceIndexManager
-
createIndexWithoutAlias
public java.lang.String createIndexWithoutAlias(java.lang.String indexName)Description copied from interface:IndexManager
Similar toIndexManager.createIndexWithAlias(String)
, but doesn't create an alias, only the index with the mapping. Note that the index will still follow the aliasName-timeStamp pattern. Note that the mapping will be looked up based on the name passed.- Specified by:
createIndexWithoutAlias
in interfaceIndexManager
-
createIndexAndAlias
public com.fasterxml.jackson.databind.JsonNode createIndexAndAlias(java.lang.String alias, java.lang.String indexMapping) -
getCustomQueryMapping
public IndexMapping getCustomQueryMapping(java.lang.String indexName, java.lang.String mappingName)Description copied from interface:IndexManager
Get custom query mapping for given index if exists.- Specified by:
getCustomQueryMapping
in interfaceIndexManager
-
deleteAliasAndRelatedIndices
public void deleteAliasAndRelatedIndices(java.lang.String indexName)Description copied from interface:IndexManager
Deletes the given index and all its aliases. Or, when the name is an alias, deletes the alias and all indices.- Specified by:
deleteAliasAndRelatedIndices
in interfaceIndexManager
-
deleteIndex
public void deleteIndex(java.lang.String indexName)Description copied from interface:IndexManager
Deletes the index with the given name. Does not delete the alias, if one exists.- Specified by:
deleteIndex
in interfaceIndexManager
-
deleteAllKnownIndices
public void deleteAllKnownIndices()Description copied from interface:IndexManager
Deletes all indices registered in the system- Specified by:
deleteAllKnownIndices
in interfaceIndexManager
-
enhanceIndexName
protected java.lang.String enhanceIndexName(java.lang.String indexName) -
isKnownIndex
public boolean isKnownIndex(java.lang.String index)Description copied from interface:IndexManager
Returns whether the index is a known mapped index. This is useful when parsing queries.- Specified by:
isKnownIndex
in interfaceIndexManager
-
findMatchingIndexMappings
public java.util.List<IndexMapping> findMatchingIndexMappings(com.fasterxml.jackson.databind.node.ObjectNode objectNode)Description copied from interface:IndexManager
Returns a list ofIndexMapping
instances that are applicable for the provided data.- Specified by:
findMatchingIndexMappings
in interfaceIndexManager
-
findMatchingIndexMappings
Description copied from interface:IndexManager
Returns a list ofIndexMapping
(s) that are applicable for the provided mapping type.- Specified by:
findMatchingIndexMappings
in interfaceIndexManager
-
findMatchingCustomMappings
Description copied from interface:IndexManager
Returns a list ofIndexMapping
(s) that are applicable for the provided index name.- Specified by:
findMatchingCustomMappings
in interfaceIndexManager
-
findIndexMapping
- Specified by:
findIndexMapping
in interfaceIndexManager
-
getIndexConfiguration
Description copied from interface:IndexManager
Returns the mapping information for the given index.- Specified by:
getIndexConfiguration
in interfaceIndexManager
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)- Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
-
createIndexesAndCustomAliasesFromMappings
public void createIndexesAndCustomAliasesFromMappings()- Specified by:
createIndexesAndCustomAliasesFromMappings
in interfaceIndexManager
-
updateIndexMetaData
protected void updateIndexMetaData(java.util.Map<java.lang.String,com.fasterxml.jackson.databind.JsonNode> indicesMetaData, java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> aliasesMetaData) -
updateIndexAndMappingMetaData
protected void updateIndexAndMappingMetaData(java.lang.String index, com.fasterxml.jackson.databind.JsonNode metaData) -
createCustomMappings
protected void createCustomMappings() -
recreateMapping
Description copied from interface:IndexManager
Used to recreate mapping ifCustomIndexConfiguration
changed.- Specified by:
recreateMapping
in interfaceIndexManager
- Returns:
- Updated indexMapping
-
createCustomAliasesFromMappings
protected java.util.Map<java.lang.String,java.util.List<com.fasterxml.jackson.databind.JsonNode>> createCustomAliasesFromMappings(java.util.Map<java.lang.String,com.fasterxml.jackson.databind.JsonNode> indexMetaData) -
updateExistingAliasMapping
-
createIndexesFromMappings
public java.util.Map<java.lang.String,com.fasterxml.jackson.databind.JsonNode> createIndexesFromMappings()Description copied from interface:IndexManager
Creates the indices for all known mappings- Specified by:
createIndexesFromMappings
in interfaceIndexManager
-
updateExistingMappingIfNeeded
protected com.fasterxml.jackson.databind.JsonNode updateExistingMappingIfNeeded(java.lang.String indexName, IndexMapping indexMapping) -
compareExtensionMetadata
protected boolean compareExtensionMetadata(com.fasterxml.jackson.databind.JsonNode currentMapping, com.fasterxml.jackson.databind.JsonNode updateMapping) -
getMappingDelta
protected com.fasterxml.jackson.databind.node.ObjectNode getMappingDelta(com.fasterxml.jackson.databind.JsonNode currentMapping, com.fasterxml.jackson.databind.JsonNode updateMapping, java.lang.String currentType) -
createCustomAlias
protected void createCustomAlias(java.lang.String alias, java.lang.String indexMapping) -
logElasticsearchVersionInformation
protected void logElasticsearchVersionInformation() -
reloadIndices
public boolean reloadIndices()Description copied from interface:IndexManager
Reloads all indexes- Specified by:
reloadIndices
in interfaceIndexManager
-
reloadIndex
public boolean reloadIndex(java.lang.String indexName)Description copied from interface:IndexManager
Reloads selected index- Specified by:
reloadIndex
in interfaceIndexManager
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
getLockManagerProvider
public java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager> getLockManagerProvider() -
setLockManagerProvider
public void setLockManagerProvider(java.util.function.Function<java.lang.String,org.flowable.common.engine.impl.lock.LockManager> lockManagerProvider) -
getMappingResources
public org.springframework.core.io.Resource[] getMappingResources() -
setMappingResources
public void setMappingResources(org.springframework.core.io.Resource[] mappingResources) -
getMappingExtensionResources
public org.springframework.core.io.Resource[] getMappingExtensionResources() -
setMappingExtensionResources
public void setMappingExtensionResources(org.springframework.core.io.Resource[] mappingExtensionResources)
-