Class DefaultSolrCloudAdminProvider
java.lang.Object
com.broadleafcommerce.search.provider.solr.AbstractBasicAuthAwareSolrProvider
com.broadleafcommerce.search.provider.solr.DefaultSolrCloudAdminProvider
- All Implemented Interfaces:
SolrAdminProvider
,SolrProvider
public class DefaultSolrCloudAdminProvider
extends AbstractBasicAuthAwareSolrProvider
implements SolrAdminProvider
Default implementation using SolrJ client to invoke SolrCloud management APIs (specifically using
CollectionAdminRequest
).- Author:
- Kelly Tisdell (ktisdell)
-
Field Summary
Fields inherited from class com.broadleafcommerce.search.provider.solr.AbstractBasicAuthAwareSolrProvider
CLUSTER_STATUS_PATH
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSolrCloudAdminProvider
(org.apache.solr.client.solrj.impl.CloudSolrClient client, String userName, String password, String defaultConfig, int defaultShards, long deleteCollectionPauseTimeMillis) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Check that the provider can connect to Solr.protected void
createAlias
(String alias, String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Create the new collection with this configuration and assign it to the given alias.protected org.apache.solr.client.solrj.request.CollectionAdminRequest.Create
createCollectionRequest
(String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Build the request to create a collection in Solr.protected org.apache.solr.client.solrj.response.CollectionAdminResponse
Get the current cluster status, to retrieve information about the existing collections.protected String
getCollectionName
(String alias) Retrieve the name of the collection assigned to the alias in Solr.protected String
getConfigName
(String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Returns the previous configuration name for the collection.protected String
protected int
protected long
protected int
getNumLiveNodes
(org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Returns the number of live nodes in the cluster.protected int
getNumShards
(String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Returns the previous number of shards for the collection.protected void
pause()
protected <T extends org.apache.solr.client.solrj.SolrResponse>
TprocessRequest
(org.apache.solr.client.solrj.SolrRequest<T> request) Execute a request in Solr with basic auth credentials, if applicable.Reads a map of alias name to Solr collection name.void
recreateAlias
(String alias) Delete the collection and re-create it.protected String
resolveAlternateNameForCollectionName
(String collectionName) By default, every collection in Solr has an alternative collection.protected String
resolveCollectionNameForAlias
(String aliasName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus, Map<String, String> aliasMap, Map<String, Map<String, Object>> collectionsMap) This attempts to resolve the collection name that is (or should be) associated with an alias.void
swapCollectionAliases
(String primaryAlias, String reindexAlias) Re-assigns the aliases to the other alias' respective collection.protected void
Verify that the provided aliases exist in the alias map, and that they are different.Methods inherited from class com.broadleafcommerce.search.provider.solr.AbstractBasicAuthAwareSolrProvider
determineCollectionsFromAliases, getSolrBasicAuthPassword, getSolrBasicAuthUser, getSolrClient, reloadCollections, reloadCollectionsFromAliases, setBasicAuthCredentialsIfNecessary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.search.provider.solr.SolrProvider
getSolrClient
-
Constructor Details
-
DefaultSolrCloudAdminProvider
-
-
Method Details
-
swapCollectionAliases
public void swapCollectionAliases(String primaryAlias, String reindexAlias) throws com.broadleafcommerce.search.api.SearchIndexException Description copied from interface:SolrAdminProvider
Re-assigns the aliases to the other alias' respective collection. This method assumes that the provided aliases are already mapped to collections.- Specified by:
swapCollectionAliases
in interfaceSolrAdminProvider
- Parameters:
primaryAlias
- The first alias to swapreindexAlias
- The second alias to swap- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an error occurs swapping the alias' collections
-
verifyAlias
protected void verifyAlias(Map<String, String> aliases, String alias1, String alias2) throws com.broadleafcommerce.search.api.SearchIndexExceptionVerify that the provided aliases exist in the alias map, and that they are different.- Parameters:
aliases
- Aliases which exist in Solralias1
- The first alias to verifyalias2
- The second alias to verify- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an alias does not exist, or they are identical
-
readAliases
public Map<String,String> readAliases() throws com.broadleafcommerce.search.api.SearchIndexExceptionDescription copied from interface:SolrAdminProvider
Reads a map of alias name to Solr collection name.- Specified by:
readAliases
in interfaceSolrAdminProvider
- Returns:
- a map containing all aliases mapped to their Solr collection name
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an error occurs reading the aliases
-
checkConnection
public void checkConnection() throws com.broadleafcommerce.search.api.SearchIndexExceptionDescription copied from interface:SolrAdminProvider
Check that the provider can connect to Solr.- Specified by:
checkConnection
in interfaceSolrAdminProvider
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if the connection to Solr failed
-
createAlias
protected void createAlias(String alias, String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) throws com.broadleafcommerce.search.api.SearchIndexException Create the new collection with this configuration and assign it to the given alias.- Parameters:
alias
- The alias to assign to the collectioncollectionName
- The name of the collection to createclusterStatus
- The status of the cluster prior to collection deletion- Throws:
org.apache.solr.client.solrj.SolrServerException
- if an error occurs creating the collection or alias in SolrIOException
- if an error occurs in the Solr connectioncom.broadleafcommerce.search.api.SearchIndexException
-
createCollectionRequest
protected org.apache.solr.client.solrj.request.CollectionAdminRequest.Create createCollectionRequest(String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Build the request to create a collection in Solr.- Parameters:
collectionName
- The name of the collection to createclusterStatus
- The status of the cluster prior to collection deletion- Returns:
- A request to create the collection in Solr
-
recreateAlias
public void recreateAlias(String alias) throws com.broadleafcommerce.search.api.SearchIndexException Delete the collection and re-create it. This is a faster and safer way to remove all documents due to potential OOM errors.- Specified by:
recreateAlias
in interfaceSolrAdminProvider
- Parameters:
alias
- The alias for which the collection should be re-created- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if any error occurs while re-creating the collection and alias
-
getClusterStatus
protected org.apache.solr.client.solrj.response.CollectionAdminResponse getClusterStatus() throws com.broadleafcommerce.search.api.SearchIndexExceptionGet the current cluster status, to retrieve information about the existing collections.- Returns:
- The current cluster status
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an error occurs in connecting to Solr or getting the status
-
getCollectionName
protected String getCollectionName(String alias) throws com.broadleafcommerce.search.api.SearchIndexException Retrieve the name of the collection assigned to the alias in Solr.- Parameters:
alias
- The alias for which to get the collection name- Returns:
- The name of the collection assigned to the alias in Solr
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if any error occurs reading the Solr aliases, or the alias has no collection
-
getConfigName
@Nullable protected String getConfigName(String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Returns the previous configuration name for the collection. Since we delete the entire collection on a full reindex, we need to preserve the collection's configuration and set it on the newly created instance.- Parameters:
collectionName
- The collection nameclusterStatus
- The cluster status before the original collection was deleted- Returns:
- The previous configuration for the collection, or the default config if not found
-
getNumShards
protected int getNumShards(String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Returns the previous number of shards for the collection. Since we delete the entire collection on a full reindex, we need to preserve the collection's configuration and set it on the newly created instance.- Parameters:
collectionName
- The collection nameclusterStatus
- The cluster status before the original collection was deleted- Returns:
- The previous number of shards for the collection, or the default number if not found
-
getNumLiveNodes
protected int getNumLiveNodes(org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus) Returns the number of live nodes in the cluster.- Parameters:
clusterStatus
- The cluster status before the original collection was deleted- Returns:
- The number of live nodes in the cluster
-
processRequest
protected <T extends org.apache.solr.client.solrj.SolrResponse> T processRequest(org.apache.solr.client.solrj.SolrRequest<T> request) throws Exception Execute a request in Solr with basic auth credentials, if applicable.- Type Parameters:
T
- The type of the expected response- Parameters:
request
- The request to execute in Solr- Returns:
- The response to the request from Solr
- Throws:
Exception
- if an error occurs executing the request
-
pause
protected void pause() -
resolveAlternateNameForCollectionName
By default, every collection in Solr has an alternative collection. For example, for catalog, there should be a catalog_collection_1 and catalog_collection_2. If "catalog_collection_1" is passed in, then "catalog_collection_2" is returned and vice versa.- Parameters:
collectionName
-- Returns:
-
resolveCollectionNameForAlias
@Nullable protected String resolveCollectionNameForAlias(String aliasName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus, Map<String, String> aliasMap, Map<String, Map<String, Object>> collectionsMap) This attempts to resolve the collection name that is (or should be) associated with an alias. This uses the alias Map and also uses default naming conventions for aliases and collections.- Parameters:
aliasName
-clusterStatus
-aliasMap
-collectionsMap
-- Returns:
- the name of the collection that is (or should be) associated with the provided aliasName
-
getDefaultConfig
-
getDefaultShards
protected int getDefaultShards() -
getDeleteCollectionPauseTimeMillis
protected long getDeleteCollectionPauseTimeMillis()
-