Class: InfluxdbSetup::SetupShardSpaces

Inherits:
Command
  • Object
show all
Defined in:
lib/influxdb_setup/setup_shard_spaces.rb

Instance Attribute Summary

Attributes inherited from Command

#config

Instance Method Summary collapse

Methods inherited from Command

#initialize, #log

Constructor Details

This class inherits a constructor from InfluxdbSetup::Command

Instance Method Details

#callObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/influxdb_setup/setup_shard_spaces.rb', line 3

def call
  db = @config.db_name
  root = @config.build_client

  expected_default_config = {
    "name"              => "default",
    "database"          => db,
    "regex"             => "/.*/",
    "retentionPolicy"   => "7d",
    "shardDuration"     => "1h",
    "replicationFactor" => 1,
    "split"             => 1
  }

  expected_archive_config = {
    "name"              => "archives",
    "database"          => db,
    "regex"             => "/archive.*/",
    "retentionPolicy"   => "365d",
    "shardDuration"     => "7d",
    "replicationFactor" => 1,
    "split"             => 1
  }

  actual_default_shard = root.get_shard_space(db, "default")
  actual_archive_shard = root.get_shard_space(db, "archives")

  if actual_default_shard.nil?
    log "Creating default shard space"
    root.create_shard_space(db, expected_default_config.except("database"))
  elsif actual_default_shard != expected_default_config
    log "Updating default shard space"
    root.update_shard_space(db, "default", expected_default_config.except("database"))
  else
    log "Shard default up to date"
  end

  if actual_archive_shard.nil?
    log "Creating archives shard space"
    root.create_shard_space(db, expected_archive_config.except("database"))
  elsif actual_archive_shard != expected_archive_config
    log "Updating archives shard space"
    root.update_shard_space(db, "archives", expected_archive_config.except("database"))
  else
    log "Shard archives up to date"
  end
end