Last active
December 24, 2015 02:59
-
-
Save ncdc/6733946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def with_gear_rotation(options={}) | |
local_gear_env = ::OpenShift::Runtime::Utils::Environ.for_gear(@container_dir) | |
proxy_cart = options[:proxy_cart] = @cartridge_model.web_proxy | |
gears = [] | |
if proxy_cart and options[:all] | |
gears = gear_registry.entries[:web] | |
else | |
gears = gear_registry.entries[:web][uuid] | |
end | |
parallel_concurrency_ratio = options[:parallel_concurrency_ratio] || PARALLEL_CONCURRENCY_RATIO | |
batch_size = calculate_batch_size(gears.size, parallel_concurrency_ratio) | |
threads = [batch_size, MAX_THREADS].min | |
parallel_output = Parallel.map(gears, :in_threads => threads) do |target_gear| | |
rotate_and_yield(target_gear, local_gear_env, options) | |
end | |
end | |
def rotate_and_yield(target_gear, local_gear_env, options) | |
proxy_cart = options[:proxy_cart] | |
if proxy_cart | |
update_proxy_status(action: :disable, | |
gear_uuid: gear_uuid, | |
cartridge: proxy_cart) | |
end | |
yield(target_gear, local_gear_env, options) | |
if proxy_cart | |
update_proxy_status(action: :enable, | |
gear_uuid: gear_uuid, | |
cartridge: proxy_cart) | |
end | |
end | |
# Restart gear as supported by cartridges | |
def restart(cart_name, options={}) | |
with_gear_rotation do |target_gear, local_gear_env, options| | |
restart_gear(target_gear, local_gear_env, cart_name, options) | |
end | |
end | |
def restart_gear(target_gear, local_gear_env, cart_name, options) | |
gear_uuid = target_gear.to_ssh_url | |
if gear_uuid == uuid | |
@cartridge_model.start_cartridge('restart', | |
cart_name, | |
user_initiated: true, | |
out: options[:out], | |
err: options[:err]) | |
else | |
out, err, rc = run_in_container_context("/usr/bin/oo-ssh #{gear} gear restart --cart #{cart_name}", | |
env: local_gear_env, | |
expected_exitstatus: 0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment