Navigation Menu

Skip to content

Commit

Permalink
Refine droonga-engine-unjoin as a subclass of RemoteCommandBase
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 21, 2015
1 parent 3108a97 commit 5fd4d5a
Showing 1 changed file with 37 additions and 67 deletions.
104 changes: 37 additions & 67 deletions bin/droonga-engine-unjoin
Expand Up @@ -15,84 +15,51 @@
# 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 "slop"
require "json"
require "pathname"
require "socket"

require "droonga/engine/version"
require "droonga/path"
require "droonga/command/remote_command_base"
require "droonga/node_name"
require "droonga/catalog/dataset"
require "droonga/catalog/loader"
require "droonga/catalog/fetcher"
require "droonga/catalog/generator"
require "droonga/catalog/loader"
require "droonga/serf"

module Droonga
class UnjoinCommand
def run
parse_options

puts "Start to unjoin a node #{@options[:host]}"
puts " by #{@options["receiver-host"]} (this host)"
puts ""

do_unjoin

puts("Done.")
exit(true)
end

private
def parse_options
options = Slop.parse(:help => true) do |option|
option.on(:host=,
"Host name of the replica removed from cluster.",
:required => true)
option.on("receiver-host=",
"Host name of this host.",
:default => Socket.gethostname)
option.on(:dataset=,
"Dataset name of for the node to be unjoined.",
:default => Catalog::Dataset::DEFAULT_NAME)
option.on(:port=,
"Port number of the source cluster to be connected.",
:as => Integer,
:default => NodeName::DEFAULT_PORT)
option.on(:tag=,
"Tag name of the soruce cluster to be connected.",
:default => NodeName::DEFAULT_TAG)

option.separator("Miscellaneous:")
option.on(:verbose, "Output details for internal operations.",
:default => false)
module Command
class Unjoin << RemoteCommandBase
def run
parse_options do |option|
option.on("receiver-host=",
"Host name of this host.",
:default => Socket.gethostname)
option.on(:dataset=,
"Dataset name of for the node to be unjoined.",
:default => Catalog::Dataset::DEFAULT_NAME)
end

puts "Start to unjoin a node #{node.to_s}"
puts " by #{@options["receiver-host"]} (this host)"
puts ""

succeeded = do_unjoin

puts("Done.") if succeeded
succeeded
end
@options = options
rescue Slop::MissingOptionError => error
$stderr.puts(error)
exit(false)
end

def replica_remove_host
@options[:host]
end

def tag
@options[:tag]
end
def replica_remove_host
host
end

def port
@options[:port]
end
def replica_remove_node
node
end

def dataset_name
@options[:dataset]
end

def replica_remove_node
"#{replica_remove_host}:#{port}/#{tag}"
end

def cluster_id
catalog.cluster_id
end
Expand All @@ -119,15 +86,15 @@ module Droonga
end

def remaining_node
@remaining_node ||= detect_remaining_node
@remaining_node ||= prepare_remaining_node
end

def remaining_node_serf
@remaining_node_serf ||= Serf.new(remaining_node,
@remaining_node_serf ||= Serf.new(remaining_node.to_s,
:verbose => @options[:verbose])
end

def detect_remaining_node
def prepare_remaining_node
generator = Catalog::Generator.new
generator.load(raw_catalog)

Expand All @@ -141,7 +108,9 @@ module Droonga
other_hosts = dataset.replicas.hosts

remaining_host = other_hosts.first || replica_remove_host
"#{remaining_host}:#{port}/#{tag}"
NodeName.new(:host => remaining_host,
:port => port,
:tag => tag)
end

def do_unjoin
Expand All @@ -155,6 +124,7 @@ module Droonga
end
end
end
end
end

Droonga::UnjoinCommand.new.run
exit(Droonga::Command::Unjoin.new.run)

0 comments on commit 5fd4d5a

Please sign in to comment.