Navigation Menu

Skip to content

Commit

Permalink
Detect role of myself based on serf tags file
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 21, 2015
1 parent e90a13e commit fcf7f91
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 0 additions & 2 deletions lib/droonga/command/remote.rb
Expand Up @@ -18,7 +18,6 @@
require "droonga/path"
require "droonga/serf"
require "droonga/node_name"
require "droonga/node_role"
require "droonga/catalog/generator"
require "droonga/catalog/modifier"
require "droonga/catalog/fetcher"
Expand Down Expand Up @@ -119,7 +118,6 @@ class ChangeRole < Base
def process
log("old role: #{@serf.role}")
@serf.role = @params["role"]
NodeRole.mine = @serf.role
log("new role: #{@serf.role}")
end
end
Expand Down
20 changes: 11 additions & 9 deletions lib/droonga/node_role.rb
Expand Up @@ -13,6 +13,10 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "json"

require "droonga/path"

module Droonga
class NodeRole
SERVICE_PROVIDER = "service-provider"
Expand All @@ -31,16 +35,14 @@ def normalize(role)
end

def mine
if @mine
@mine.to_s
else
SERVICE_PROVIDER
if Path.serf_tags_file.exist?
tags = Path.serf_tags_file.read
tags = JSON.parse(tags)
return tags["role"] if tags["role"]
end
end

def mine=(new_role)
@mine = new(new_role)
@mine.to_s
SERVICE_PROVIDER
rescue Errno::ENOENT, JSON::ParserError
SERVICE_PROVIDER
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/droonga/serf.rb
Expand Up @@ -63,9 +63,7 @@ def run_agent(loop)
def initialize_tags
set_tag("type", "engine")
set_tag("cluster_id", cluster_id)
current_role = role
set_tag("role", current_role)
NodeRole.mine = current_role
set_tag("role", role)
end

def leave
Expand Down

0 comments on commit fcf7f91

Please sign in to comment.