YUKI Hiroshi
null+****@clear*****
Tue Apr 21 16:22:51 JST 2015
YUKI Hiroshi 2015-04-21 16:22:51 +0900 (Tue, 21 Apr 2015) New Revision: 5fd4d5a58b1a583659bc6b19773bb70ed065bb8d https://github.com/droonga/droonga-engine/commit/5fd4d5a58b1a583659bc6b19773bb70ed065bb8d Message: Refine droonga-engine-unjoin as a subclass of RemoteCommandBase Modified files: bin/droonga-engine-unjoin Modified: bin/droonga-engine-unjoin (+37 -67) =================================================================== --- bin/droonga-engine-unjoin 2015-04-21 16:15:59 +0900 (029add4) +++ bin/droonga-engine-unjoin 2015-04-21 16:22:51 +0900 (060584f) @@ -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 @@ -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) @@ -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 @@ -155,6 +124,7 @@ module Droonga end end end + end end -Droonga::UnjoinCommand.new.run +exit(Droonga::Command::Unjoin.new.run) -------------- next part -------------- HTML����������������������������... Download