Navigation Menu

Skip to content

Commit

Permalink
Normalize roles to downcase
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 29, 2015
1 parent eb144e3 commit 5a3fc19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/droonga/cluster.rb
Expand Up @@ -170,7 +170,7 @@ def forward(message, destination)
end

def bounce(message)
role = message["targetRole"]
role = message["targetRole"].downcase
logger.info("bounce: trying to bounce message to another " +
"node with the role: #{role}")
raise NotStartedYet.new unless @engine_nodes
Expand Down
6 changes: 3 additions & 3 deletions lib/droonga/dispatcher.rb
Expand Up @@ -351,9 +351,9 @@ def public_farm_path(route)
end

def acceptable_role?(message)
message["targetRole"].nil? or
message["targetRole"] == NodeRole::ANY or
message["targetRole"] == NodeRole.mine
return true unless message["targetRole"]
role = message["targetRole"].downcase
role == NodeRole::ANY or role == NodeRole.mine
end

def process_input_message(message)
Expand Down
12 changes: 7 additions & 5 deletions lib/droonga/node_role.rb
Expand Up @@ -20,11 +20,11 @@

module Droonga
class NodeRole
SERVICE_PROVIDER = "service-provider"
ABSORB_SOURCE = "absorb-source"
ABSORB_DESTINATION = "absorb-destination"
SERVICE_PROVIDER = "service-provider".downcase
ABSORB_SOURCE = "absorb-source".downcase
ABSORB_DESTINATION = "absorb-destination".downcase

ANY = "any"
ANY = "any".downcase

ROLES = [
SERVICE_PROVIDER,
Expand All @@ -41,7 +41,8 @@ def mine
if Path.serf_tags_file.exist?
tags = Path.serf_tags_file.read
tags = JSON.parse(tags)
return tags[Serf::Tag.node_role] if tags[Serf::Tag.node_role]
role_from_tag = tags[Serf::Tag.node_role]
return role_from_tag.downcase if role_from_tag
end
SERVICE_PROVIDER
rescue Errno::ENOENT, JSON::ParserError
Expand All @@ -63,6 +64,7 @@ def valid?(role)
end

def normalize(role)
role = role.downcase
role = SERVICE_PROVIDER unless valid?(role)
role
end
Expand Down

0 comments on commit 5a3fc19

Please sign in to comment.