YUKI Hiroshi
null+****@clear*****
Thu Dec 18 18:33:49 JST 2014
YUKI Hiroshi 2014-12-18 18:33:49 +0900 (Thu, 18 Dec 2014) New Revision: 892b91a815b704b72ce7bed22ed8331bf36da528 https://github.com/droonga/droonga-engine/commit/892b91a815b704b72ce7bed22ed8331bf36da528 Message: Add droonga-engine-set-role command (mainly for debugging) Added files: bin/droonga-engine-set-role Added: bin/droonga-engine-set-role (+84 -0) 100755 =================================================================== --- /dev/null +++ bin/droonga-engine-set-role 2014-12-18 18:33:49 +0900 (39c5fed) @@ -0,0 +1,84 @@ +#!/usr/bin/env ruby +# +# Copyright (C) 2014 Droonga Project +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# 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 "socket" + +require "droonga/engine/version" +require "droonga/catalog_generator" +require "droonga/serf" + +class SetRoleCommand + def run + parse_options + puts "Setting role of #{@options[:host]} to #{@options[:role]}..." + set_node_role + puts("Done.") + exit(true) + end + + private + def parse_options + options = Slop.parse(:help => true) do |option| + option.on(:role=, + "New role for the target node.", + :required => true) + + option.separator("Connections:") + option.on(:host=, + "Host name of the target node.", + :required => true) + option.on("receiver-host=", + "Host name of this host.", + :default => Socket.gethostname) + option.on(:dataset=, + "Dataset name of for the target node.", + :default => Droonga::CatalogGenerator::DEFAULT_DATASET) + option.on(:port=, + "Port number of the source cluster to be connected.", + :as => Integer, + :default => Droonga::CatalogGenerator::DEFAULT_PORT) + option.on(:tag=, + "Tag name of the soruce cluster to be connected.", + :default => Droonga::CatalogGenerator::DEFAULT_TAG) + end + @options = options + rescue Slop::MissingOptionError => error + $stderr.puts(error) + exit(false) + end + + def target_node + "#{@options[:host]}:#{@options[:port]}/#{@options[:tag]}" + end + + def run_remote_command(target, command, options) + serf = Droonga::Serf.new(nil, target) + result = serf.send_query(command, options) + #puts(result[:result]) + puts(result[:error]) unless result[:error].empty? + result[:response] + end + + def set_node_role + run_remote_command(target_node, "change_role", + "node" => target_node, + "role" => @options[:role]) + end +end + +SetRoleCommand.new.run -------------- next part -------------- HTML����������������������������...Download