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)
  • Constructor Details

    • DefaultSolrCloudAdminProvider

      public DefaultSolrCloudAdminProvider(org.apache.solr.client.solrj.impl.CloudSolrClient client, String userName, String password, String defaultConfig, int defaultShards, long deleteCollectionPauseTimeMillis)
  • 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 interface SolrAdminProvider
      Parameters:
      primaryAlias - The first alias to swap
      reindexAlias - 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 Solr
      alias1 - The first alias to verify
      alias2 - 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: SolrAdminProvider
      Reads a map of alias name to Solr collection name.
      Specified by:
      readAliases in interface SolrAdminProvider
      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.SearchIndexException
      Description copied from interface: SolrAdminProvider
      Check that the provider can connect to Solr.
      Specified by:
      checkConnection in interface SolrAdminProvider
      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 collection
      collectionName - The name of the collection to create
      clusterStatus - 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 Solr
      IOException - if an error occurs in the Solr connection
      com.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 create
      clusterStatus - 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 interface SolrAdminProvider
      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.SearchIndexException
      Get 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 name
      clusterStatus - 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 name
      clusterStatus - 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

      @Nullable protected String resolveAlternateNameForCollectionName(String collectionName)
      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

      protected String getDefaultConfig()
    • getDefaultShards

      protected int getDefaultShards()
    • getDeleteCollectionPauseTimeMillis

      protected long getDeleteCollectionPauseTimeMillis()