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



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

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



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

def alias_names
  alias_map.keys
end

#aliasesArray<SolrCloud::Alias>

List of alias objects

Returns:



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

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:



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

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 '#{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



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

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:



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

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)


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

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>)


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

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