Class: Droonga::CatalogGenerator

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 =
[Address::DEFAULT_HOST]
DEFAULT_N_WORKERS =
4
DEFAULT_N_SLICES =
1
DEFAULT_PLUGINS =
["groonga", "search", "crud", "dump", "system", "catalog"]
DEFAULT_PORT =
Address::DEFAULT_PORT
DEFAULT_TAG =
Address::DEFAULT_TAG

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCatalogGenerator

Returns a new instance of CatalogGenerator.



43
44
45
46
47
# File 'lib/droonga/catalog_generator.rb', line 43

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

Instance Attribute Details

#datasetsObject (readonly)

Returns the value of attribute datasets.



31
32
33
# File 'lib/droonga/catalog_generator.rb', line 31

def datasets
  @datasets
end

Class Method Details

.generate(datasets_params) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/droonga/catalog_generator.rb', line 34

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



49
50
51
# File 'lib/droonga/catalog_generator.rb', line 49

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

#dataset_for_host(host) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/droonga/catalog_generator.rb', line 68

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

#generateObject



53
54
55
56
57
58
59
# File 'lib/droonga/catalog_generator.rb', line 53

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

#load(catalog) ⇒ Object



61
62
63
64
65
66
# File 'lib/droonga/catalog_generator.rb', line 61

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

#modify(dataset_modifications) ⇒ Object



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

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