Class Aliases


  • public class Aliases
    extends Object
    Holds collection aliases -- virtual collections that point to one or more other collections. We might add other types of aliases here some day. Immutable.
    • Field Detail

      • EMPTY

        public static final Aliases EMPTY
        An empty, minimal Aliases primarily used to support the non-cloud solr use cases. Not normally useful in cloud situations where the version of the node needs to be tracked even if all aliases are removed. The -1 version makes it subordinate to any real version, and furthermore we never "set" this EMPTY instance into ZK.
    • Method Detail

      • size

        public int size()
      • fromJSON

        public static Aliases fromJSON​(byte[] bytes,
                                       int zNodeVersion)
        Create an instance from the JSON bytes read from zookeeper. Generally this should only be done by a ZkStateReader.
        Parameters:
        bytes - The bytes read via a getData request to zookeeper (possibly null)
        zNodeVersion - the version of the data in zookeeper that this instance corresponds to
        Returns:
        A new immutable Aliases object
      • toJSON

        public byte[] toJSON()
        Serialize our state.
      • getZNodeVersion

        public int getZNodeVersion()
      • getCollectionAliasMap

        public Map<String,​String> getCollectionAliasMap()
        Get a map similar to the JSON data as stored in zookeeper. Callers may prefer use of getCollectionAliasListMap() instead, if collection names will be iterated.
        Returns:
        an unmodifiable Map of collection aliases mapped to a comma delimited string of the collection(s) the alias maps to. Does not return null.
      • getCollectionAliasListMap

        public Map<String,​List<String>> getCollectionAliasListMap()
        Get a fully parsed map of collection aliases.
        Returns:
        an unmodifiable Map of collection aliases mapped to a list of the collection(s) the alias maps to. Does not return null.
      • getCollectionAliasProperties

        public Map<String,​String> getCollectionAliasProperties​(String alias)
        Returns an unmodifiable Map of properties for a given alias. This method will never return null.
        Parameters:
        alias - the name of an alias also found as a key in getCollectionAliasListMap()
        Returns:
        The properties for the alias (possibly empty).
      • resolveAliases

        public List<String> resolveAliases​(String aliasName)
        List the collections associated with a particular alias. One level of alias indirection is supported (alias to alias to collection). Such indirection may be deprecated in the future, use with caution.
        Returns:
        An unmodifiable list of collections names that the input alias name maps to. If there are none, the input is returned.
      • hasAlias

        public boolean hasAlias​(String aliasName)
        Returns true if an alias is defined, false otherwise.
      • isRoutedAlias

        public boolean isRoutedAlias​(String aliasName)
        Returns true if an alias exists and is a routed alias, false otherwise.
      • resolveSimpleAlias

        public String resolveSimpleAlias​(String aliasName)
                                  throws SolrException
        Resolve an alias that points to a single collection. One level of alias indirection is supported.
        Parameters:
        aliasName - alias name
        Returns:
        original name if there's no such alias, or a resolved name. If an alias points to more than 1 collection (directly or indirectly) an exception is thrown
        Throws:
        SolrException - if either direct or indirect alias points to more than 1 name.
      • resolveSimpleAliasGivenAliasMap

        public static String resolveSimpleAliasGivenAliasMap​(Map<String,​List<String>> collectionAliasListMap,
                                                             String aliasName)
                                                      throws SolrException
        Throws:
        SolrException
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
      • resolveAliasesGivenAliasMap

        public static List<String> resolveAliasesGivenAliasMap​(Map<String,​List<String>> collectionAliasListMap,
                                                               String aliasName)
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
      • cloneWithCollectionAlias

        public Aliases cloneWithCollectionAlias​(String alias,
                                                String collections)
        Creates a new Aliases instance with the same data as the current one but with a modification based on the parameters.

        Note that the state in zookeeper is unaffected by this method and the change must still be persisted via ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)

        Parameters:
        alias - the alias to update, must not be null
        collections - the comma separated list of collections for the alias, null to remove the alias
      • cloneWithRename

        public Aliases cloneWithRename​(String before,
                                       String after)
                                throws SolrException
        Rename an alias. This performs a "deep rename", which changes also the second-level alias lists. Renaming routed aliases is not supported.

        Note that the state in zookeeper is unaffected by this method and the change must still be persisted via ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)

        Parameters:
        before - previous alias name, must not be null
        after - new alias name. If this is null then it's equivalent to calling cloneWithCollectionAlias(String, String) with the second argument set to null, ie. removing an alias.
        Returns:
        new instance with the renamed alias
        Throws:
        SolrException - when either before or after is empty, or the before name is a routed alias
      • cloneWithCollectionAliasProperties

        public Aliases cloneWithCollectionAliasProperties​(String alias,
                                                          String propertiesKey,
                                                          String propertiesValue)
        Set the value for some properties on a collection alias. This is done by creating a new Aliases instance with the same data as the current one but with a modification based on the parameters.

        Note that the state in zookeeper is unaffected by this method and the change must still be persisted via ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)

        Parameters:
        alias - the alias to update
        propertiesKey - the key for the properties
        propertiesValue - the properties to add/replace, null to remove the key.
        Returns:
        An immutable copy of the aliases with the new properties.
      • cloneWithCollectionAliasProperties

        public Aliases cloneWithCollectionAliasProperties​(String alias,
                                                          Map<String,​String> properties)
                                                   throws SolrException
        Set the values for some properties keys on a collection alias. This is done by creating a new Aliases instance with the same data as the current one but with a modification based on the parameters.

        Note that the state in zookeeper is unaffected by this method and the change must still be persisted via ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)

        Parameters:
        alias - the alias to update
        properties - the properties to add/replace, null values in the map will remove the key.
        Returns:
        An immutable copy of the aliases with the new properties.
        Throws:
        SolrException