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 usingCollectionAdminRequest).- Author:
- Kelly Tisdell (ktisdell)
-
-
Field Summary
-
Fields inherited from class com.broadleafcommerce.search.provider.solr.AbstractBasicAuthAwareSolrProvider
CLUSTER_STATUS_PATH
-
-
Constructor Summary
Constructors Constructor Description DefaultSolrCloudAdminProvider(org.apache.solr.client.solrj.impl.CloudSolrClient client, String userName, String password, String defaultConfig, int defaultShards, long deleteCollectionPauseTimeMillis)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckConnection()Check that the provider can connect to Solr.protected voidcreateAlias(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.CreatecreateCollectionRequest(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.CollectionAdminResponsegetClusterStatus()Get the current cluster status, to retrieve information about the existing collections.protected StringgetCollectionName(String alias)Retrieve the name of the collection assigned to the alias in Solr.protected StringgetConfigName(String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus)Returns the previous configuration name for the collection.protected StringgetDefaultConfig()protected intgetDefaultShards()protected longgetDeleteCollectionPauseTimeMillis()protected intgetNumLiveNodes(org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus)Returns the number of live nodes in the cluster.protected intgetNumShards(String collectionName, org.apache.solr.client.solrj.response.CollectionAdminResponse clusterStatus)Returns the previous number of shards for the collection.protected voidpause()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.Map<String,String>readAliases()Reads a map of alias name to Solr collection name.voidrecreateAlias(String alias)Delete the collection and re-create it.voidswapCollectionAliases(String primaryAlias, String reindexAlias)Re-assigns the aliases to the other alias' respective collection.protected voidverifyAlias(Map<String,String> aliases, String alias1, String alias2)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
-
-
-
-
Method Detail
-
swapCollectionAliases
public void swapCollectionAliases(String primaryAlias, String reindexAlias) throws com.broadleafcommerce.search.api.SearchIndexException
Description copied from interface:SolrAdminProviderRe-assigns the aliases to the other alias' respective collection. This method assumes that the provided aliases are already mapped to collections.- Specified by:
swapCollectionAliasesin 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.SearchIndexException
Verify 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.SearchIndexException
Description copied from interface:SolrAdminProviderReads a map of alias name to Solr collection name.- Specified by:
readAliasesin 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:SolrAdminProviderCheck that the provider can connect to Solr.- Specified by:
checkConnectionin 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:
recreateAliasin 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 ExceptionExecute 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()
-
getDefaultConfig
protected String getDefaultConfig()
-
getDefaultShards
protected int getDefaultShards()
-
getDeleteCollectionPauseTimeMillis
protected long getDeleteCollectionPauseTimeMillis()
-
-