Skip to content

Instantly share code, notes, and snippets.

@willb
Created October 23, 2012 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willb/3936568 to your computer and use it in GitHub Desktop.
Save willb/3936568 to your computer and use it in GitHub Desktop.
# cmd_setup_ha_cms.rb: sets up highly-available central managers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module Mrg
module Grid
module Config
module Shell
class SetupHaCms < ::Mrg::Grid::Config::Shell::Command
def self.opname
"setup-ha-cms"
end
def self.description
"sets up highly-available central managers"
end
def init_option_parser
OptionParser.new do |opts|
opts.banner = "Usage: wallaby #{self.class.opname} [OPTIONS] CM_HOST [...]\n#{self.class.description}"
opts.on("-h", "--help", "displays this message") do
puts @oparser
exit
end
opts.on("--cm-group GROUP", "Wallaby group for potential central managers" " (will be created if it doesn't exist; default is 'PotentialCMs')") do |grp|
@cm_group_name = grp
end
opts.on("--client-group GROUP", "Wallaby group for nodes that will use these HA CMs" " (will be created if it doesn't exist; defau;t is '+++DEFAULT')") do |grp|
@client_group_name = grp
end
end
end
def act
@cm_group_name ||= "PotentialCMs"
@client_group_name ||= "+++DEFAULT"
store.checkGroupValidity([@cm_group_name, @client_group_name]).each do |grp|
store.addExplicitGroup(grp)
end
cm_group = store.getGroupByName(@cm_group_name)
client_group = store.getGroupByName(@client_group_name)
cms = @wallaby_command_args
had_list = cms.map {|cm_name| "#{cm_name}:$(HAD_PORT)"}.join(", ")
replication_list = cms.map {|cm_name| "#{cm_name}:$(REPLICATION_PORT)"}.join(", ")
condor_host = cms.join(", ")
cm_group.modifyFeatures("ADD", ["HACentralManager"], {})
cm_group.modifyParams("ADD", {"REPLICATION_LIST"=>replication_list, "HAD_LIST"=>had_list})
client_group.modifyParams("ADD", {"CONDOR_HOST"=>condor_host})
cm_group.membership.each {|node| store.getNode(node).modifyMemberships("REMOVE", [@cm_group_name], {})}
cms.each do |cm|
store.getNode(cm).modifyMemberships("ADD", [@cm_group_name], {})
end
return 0
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment