Navigation Menu

Skip to content

Commit

Permalink
Modify catalog with generator's instance methods
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 28, 2014
1 parent 7aefaa5 commit 9f3dfc1
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions lib/droonga/command/serf_event_handler.rb
Expand Up @@ -85,12 +85,10 @@ def process_node_join

return unless @payload["type"] == "replica"

modifications = {
dataset => {
:add_replica_hosts => [host],
},
}
modify_catalog(modifications)
modify_catalog do |generator|
generator.datasets[dataset].replicas.hosts << host
generator.datasets[dataset].replicas.hosts.uniq!
end
end

def process_node_unjoin
Expand All @@ -102,21 +100,17 @@ def process_node_unjoin

return unless @payload["type"] == "replica"

modifications = {
dataset => {
:remove_replica_hosts => [host],
},
}
modify_catalog(modifications)
modify_catalog do |generator|
generator.datasets[dataset].replicas.hosts -= [host]
end
end

def modify_catalog(modifications)
def modify_catalog
current_catalog = JSON.parse(Path.catalog.read)
current_params = CatalogGenerator.catalog_to_params(current_catalog)
updated_params = CatalogGenerator.update_params(current_params,
modifications)
updated_catalog = CatalogGenerator.generate(updated_params)
SafeFileWriter.write(Path.catalog, JSON.pretty_generate(updated_catalog))
generator = CatalogGenerator.new
generator.load(current_catalog)
yield(generator)
SafeFileWriter.write(Path.catalog, JSON.pretty_generate(generator.catalog))
end

def live_nodes
Expand Down

0 comments on commit 9f3dfc1

Please sign in to comment.