Class DefaultSolrCloudAdminProvider

    • Constructor Detail

      • DefaultSolrCloudAdminProvider

        public DefaultSolrCloudAdminProvider​(org.apache.solr.client.solrj.impl.CloudSolrClient client,
                                             String userName,
                                             String password,
                                             String defaultConfig,
                                             int defaultShards,
                                             long deleteCollectionPauseTimeMillis)
    • Method Detail

      • 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()
      • getDefaultConfig

        protected String getDefaultConfig()
      • getDefaultShards

        protected int getDefaultShards()
      • getDeleteCollectionPauseTimeMillis

        protected long getDeleteCollectionPauseTimeMillis()