Class: Droonga::Catalog::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/catalog/generator.rb

Defined Under Namespace

Classes: Dataset, Replica, Replicas

Constant Summary collapse

DEFAULT_DATASET =
Catalog::Dataset::DEFAULT_NAME
DEFAULT_HOSTS =
[NodeName::DEFAULT_HOST]
DEFAULT_N_WORKERS =
4
DEFAULT_N_SLICES =
1
DEFAULT_PLUGINS =
["groonga", "search", "crud", "dump", "system", "catalog"]
DEFAULT_PORT =
NodeName::DEFAULT_PORT
DEFAULT_TAG =
NodeName::DEFAULT_TAG

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerator

Returns a new instance of Generator.



44
45
46
47
48
# File 'lib/droonga/catalog/generator.rb', line 44

def initialize
  @version        = 2
  @effective_date = Time.now
  @datasets       = {}
end

Instance Attribute Details

#datasetsObject (readonly)

Returns the value of attribute datasets.



32
33
34
# File 'lib/droonga/catalog/generator.rb', line 32

def datasets
  @datasets
end

Class Method Details

.generate(datasets_params) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/droonga/catalog/generator.rb', line 35

def generate(datasets_params)
  generator = new
  datasets_params.each do |name, params|
    generator.add_dataset(name, params)
  end
  generator.generate
end

Instance Method Details

#add_dataset(name, options) ⇒ Object



50
51
52
# File 'lib/droonga/catalog/generator.rb', line 50

def add_dataset(name, options)
  @datasets[name] = Dataset.new(name, options)
end

#dataset_for_host(host) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/droonga/catalog/generator.rb', line 69

def dataset_for_host(host)
  @datasets.each do |name, dataset|
    if dataset.replicas.hosts.include?(host)
      return dataset
    end
  end
  nil
end

#generateObject



54
55
56
57
58
59
60
# File 'lib/droonga/catalog/generator.rb', line 54

def generate
  {
    "version"       => @version,
    "effectiveDate" => @effective_date.iso8601,
    "datasets"      => catalog_datasets,
  }
end

#load(catalog) ⇒ Object



62
63
64
65
66
67
# File 'lib/droonga/catalog/generator.rb', line 62

def load(catalog)
  catalog["datasets"].each do |name, catalog_dataset|
    load_dataset(name, catalog_dataset)
  end
  self
end

#modify(dataset_modifications) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/droonga/catalog/generator.rb', line 78

def modify(dataset_modifications)
  dataset_modifications.each do |name, modification|
    dataset = @datasets[name]
    next unless dataset

    replicas = dataset.replicas

    if modification[:replica_hosts]
      replicas.hosts = modification[:replica_hosts]
    end

    if modification[:add_replica_hosts]
      replicas.hosts += modification[:add_replica_hosts]
      replicas.hosts.uniq!
    end

    if modification[:remove_replica_hosts]
      replicas.hosts -= modification[:remove_replica_hosts]
    end
  end
end