Module: SolrCloud::Connection::AliasAdmin

Included in:
SolrCloud::Connection
Defined in:
lib/solr_cloud/connection/alias_admin.rb

Overview

methods having to do with aliases, to be included by the connection object. These are split out only to make it easier to deal with them.

Defined Under Namespace

Classes: AliasCollectionPair

Instance Method Summary collapse

Instance Method Details

#alias_mapHash<String,Alias>

Get the aliases and create a map of the form AliasName -> AliasObject

Returns:

  • (Hash<String,Alias>)

    A hash mapping alias names to alias objects



70
71
72
73
74
75
76
# File 'lib/solr_cloud/connection/alias_admin.rb', line 70

def alias_map
  raw_alias_map.keys.each_with_object({}) do |alias_name, h|
    a = Alias.new(name: alias_name, connection: self)
    c = Collection.new(name: raw_alias_map[alias_name], connection: self)
    h[alias_name] = AliasCollectionPair.new(a, c)
  end
end

#alias_namesArray<String>

List of alias names

Returns:

  • (Array<String>)

    the alias names



47
48
49
# File 'lib/solr_cloud/connection/alias_admin.rb', line 47

def alias_names
  alias_map.keys
end

#aliasesArray<SolrCloud::Alias>

List of alias objects

Returns:



41
42
43
# File 'lib/solr_cloud/connection/alias_admin.rb', line 41

def aliases
  alias_map.values.map(&:alias)
end

#create_alias(name:, collection_name:, force: false) ⇒ Alias

Create an alias for the given collection name.

In general, prefer SolrCloud::Collection#alias_as instead of running everything through the connection object.

Parameters:

  • name (String)

    Name of the new alias

  • collection_name (String)

    name of the collection

  • force (Boolean) (defaults to: false)

    whether to overwrite an existing alias

Returns:

  • (Alias)

    the newly-created alias

Raises:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/solr_cloud/connection/alias_admin.rb', line 21

def create_alias(name:, collection_name:, force: false)
  unless legal_solr_name?(name)
    raise IllegalNameError.new("'#{name}' is not a valid solr alias name. Use only ASCII letters/numbers, dash, and underscore")
  end
  raise NoSuchCollectionError.new("Can't find collection #{collection_name}") unless has_collection?(collection_name)
  if has_alias?(name) && !force
    raise WontOverwriteError.new("Alias '#{name}' already points to collection '#{self.get_alias(name).collection.name}'; won't overwrite without force: true")
  end
  connection.get("solr/admin/collections", action: "CREATEALIAS", name: name, collections: collection_name)
  get_alias(name)
end

#get_alias(name) ⇒ Alias?

Get an alias object for the given name, erroring out if not found

Parameters:

  • name (String)

    the name of the existing alias

Returns:

  • (Alias, nil)

    The alias if found, otherwise nil



54
55
56
57
# File 'lib/solr_cloud/connection/alias_admin.rb', line 54

def get_alias(name)
  return nil unless has_alias?(name)
  alias_map[name].alias
end

#get_alias!(name) ⇒ SolrCloud::Alias

Get an alias object for the given name, erroring out if not found

Parameters:

  • name (String)

    the name of the existing alias

Returns:

Raises:



63
64
65
66
# File 'lib/solr_cloud/connection/alias_admin.rb', line 63

def get_alias!(name)
  raise NoSuchAliasError unless has_alias?(name)
  get_alias(name)
end

#has_alias?(name) ⇒ Boolean

Is there an alias with this name?

Returns:

  • (Boolean)


35
36
37
# File 'lib/solr_cloud/connection/alias_admin.rb', line 35

def has_alias?(name)
  alias_names.include? name
end

#raw_alias_mapHash<String, String>

The “raw” alias map, which just maps alias names to collection names

Returns:

  • (Hash<String, String>)


80
81
82
# File 'lib/solr_cloud/connection/alias_admin.rb', line 80

def raw_alias_map
  connection.get("solr/admin/collections", action: "LISTALIASES").body["aliases"]
end