Class: MarathonDeploy::Deployment
- Inherits:
-
Object
- Object
- MarathonDeploy::Deployment
- Defined in:
- lib/marathon_deploy/deployment.rb
Constant Summary collapse
- DEPLOYMENT_RECHECK_INTERVAL =
MarathonDefaults::DEPLOYMENT_RECHECK_INTERVAL
- DEPLOYMENT_TIMEOUT =
MarathonDefaults::DEPLOYMENT_TIMEOUT
- HEALTHY_WAIT_TIMEOUT =
MarathonDefaults::HEALTHY_WAIT_TIMEOUT
- HEALTHY_WAIT_RECHECK_INTERVAL =
MarathonDefaults::HEALTHY_WAIT_RECHECK_INTERVAL
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#deploymentId ⇒ Object
readonly
Returns the value of attribute deploymentId.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #applicationExists? ⇒ Boolean
- #cancel(deploymentId, force = false) ⇒ Object
- #create_app ⇒ Object
- #health_checks_defined? ⇒ Boolean
- #healthcheck_timeout ⇒ Object
-
#initialize(url, application) ⇒ Deployment
constructor
A new instance of Deployment.
- #rolling_restart ⇒ Object
- #timeout ⇒ Object
- #update_app(force = false) ⇒ Object
- #versions ⇒ Object
- #wait_for_application(message = "Deployment of application #{@application.id} in progress") ⇒ Object
- #wait_for_deployment_id(message = "Deployment with deploymentId #{@deploymentId} in progress") ⇒ Object
- #wait_until_healthy ⇒ Object
Constructor Details
#initialize(url, application) ⇒ Deployment
Returns a new instance of Deployment.
16 17 18 19 20 21 |
# File 'lib/marathon_deploy/deployment.rb', line 16 def initialize(url, application) raise ArgumentError, "second argument to deployment object must be an Application", caller unless (!application.nil? && application.class == Application) raise Error::BadURLError, "invalid url => #{url}", caller if (!HttpUtil.valid_url(url)) @url = HttpUtil.clean_url(url) @application = application end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
14 15 16 |
# File 'lib/marathon_deploy/deployment.rb', line 14 def application @application end |
#deploymentId ⇒ Object (readonly)
Returns the value of attribute deploymentId.
14 15 16 |
# File 'lib/marathon_deploy/deployment.rb', line 14 def deploymentId @deploymentId end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
14 15 16 |
# File 'lib/marathon_deploy/deployment.rb', line 14 def url @url end |
Instance Method Details
#applicationExists? ⇒ Boolean
122 123 124 125 126 127 128 |
# File 'lib/marathon_deploy/deployment.rb', line 122 def applicationExists? response = list_app if (response.code.to_i == 200) return true end return false end |
#cancel(deploymentId, force = false) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/marathon_deploy/deployment.rb', line 113 def cancel(deploymentId,force=false) raise ArgumentError, "deploymentId must be specified to cancel deployment", caller if (deploymentId.empty?) if (running_for_deployment_id?) response = HttpUtil.delete(@url + MarathonDefaults::MARATHON_DEPLOYMENT_REST_PATH + deploymentId + "?force=#{force}") $LOG.debug("Cancellation response [#{response.code}] => " + JSON.pretty_generate(JSON.parse(response.body))) end return response end |
#create_app ⇒ Object
130 131 132 133 134 |
# File 'lib/marathon_deploy/deployment.rb', line 130 def create_app response = HttpUtil.post(@url + MarathonDefaults::MARATHON_APPS_REST_PATH,@application.json) @deploymentId = get_deployment_id return response end |
#health_checks_defined? ⇒ Boolean
154 155 156 157 158 |
# File 'lib/marathon_deploy/deployment.rb', line 154 def health_checks_defined? health_checks = @application.health_checks return true unless health_checks.nil? or health_checks.empty? return false end |
#healthcheck_timeout ⇒ Object
27 28 29 |
# File 'lib/marathon_deploy/deployment.rb', line 27 def healthcheck_timeout return HEALTHY_WAIT_TIMEOUT end |
#rolling_restart ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/marathon_deploy/deployment.rb', line 146 def rolling_restart url = @url + MarathonDefaults::MARATHON_APPS_REST_PATH + @application.id + '/restart' $LOG.debug("Calling marathon api with url: #{url}") response = HttpUtil.post(url,{}) $LOG.info("Restart of #{@application.id} returned status code: #{response.code}") $LOG.info(JSON.pretty_generate(JSON.parse(response.body))) end |
#timeout ⇒ Object
23 24 25 |
# File 'lib/marathon_deploy/deployment.rb', line 23 def timeout return DEPLOYMENT_TIMEOUT end |
#update_app(force = false) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/marathon_deploy/deployment.rb', line 136 def update_app(force=false) url = @url + MarathonDefaults::MARATHON_APPS_REST_PATH + @application.id url += force ? '?force=true' : '' $LOG.debug("Updating app #{@application.id} #{url}") response = HttpUtil.put(url,@application.json) @deploymentId = Utils.response_body(response)[:deploymentId] return response end |
#versions ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/marathon_deploy/deployment.rb', line 31 def versions if (!applicationExists?) response = HttpUtil.get(@url + MarathonDefaults::MARATHON_APPS_REST_PATH + @application.id + '/versions') response_body = Utils.response_body(response) return response_body[:versions] else return Array.new end end |
#wait_for_application(message = "Deployment of application #{@application.id} in progress") ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/marathon_deploy/deployment.rb', line 66 def wait_for_application( = "Deployment of application #{@application.id} in progress") deployment_seen = false Timeout::timeout(DEPLOYMENT_TIMEOUT) do while running_for_application_id? deployment_seen = true #response = list_all #STDOUT.print "." if ( $LOG.level == 1 ) $LOG.info() deployments_for_application_id.each do |item| $LOG.debug(deployment_string(item)) end #$LOG.debug(JSON.pretty_generate(JSON.parse(response.body))) sleep(DEPLOYMENT_RECHECK_INTERVAL) end #STDOUT.puts "" if ( $LOG.level == 1 ) if (deployment_seen) $LOG.info("Deployment of application #{@application.id} ended") end end end |
#wait_for_deployment_id(message = "Deployment with deploymentId #{@deploymentId} in progress") ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/marathon_deploy/deployment.rb', line 41 def wait_for_deployment_id( = "Deployment with deploymentId #{@deploymentId} in progress") startTime = Time.now deployment_seen = false Timeout::timeout(DEPLOYMENT_TIMEOUT) do while running_for_deployment_id? deployment_seen = true #response = list_all #STDOUT.print "." if ( $LOG.level == 1 ) elapsedTime = '%.2f' % (Time.now - startTime) $LOG.info( + " (elapsed time #{elapsedTime}s)") deployments = deployments_for_deployment_id deployments.each do |item| $LOG.debug(deployment_string(item)) end sleep(DEPLOYMENT_RECHECK_INTERVAL) end #STDOUT.puts "" if ( $LOG.level == 1 ) if (deployment_seen) elapsedTime = '%.2f' % (Time.now - startTime) $LOG.info("Deployment with deploymentId #{@deploymentId} ended (Total deployment time #{elapsedTime}s)") end end end |
#wait_until_healthy ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/marathon_deploy/deployment.rb', line 87 def wait_until_healthy startTime = Time.now Timeout::timeout(HEALTHY_WAIT_TIMEOUT) do loop do break if (!health_checks_defined?) sick = get_alive(false) elapsedTime = '%.2f' % (Time.now - startTime) if (!sick.empty?) $LOG.info("#{sick.size}/#{@application.instances} instances are not healthy, retrying in #{HEALTHY_WAIT_RECHECK_INTERVAL}s (elapsed time #{elapsedTime}s)") $LOG.debug("Sick instances: " + sick.join(',')) else healthy = get_alive(true) if (healthy.size == @application.instances) elapsedTime = '%.2f' % (Time.now - startTime) $LOG.info("#{healthy.size} of #{@application.instances} expected instances are healthy (Total health-check time #{elapsedTime}s).") $LOG.debug("Healthy instances running: " + healthy.join(',')) break else $LOG.info("#{healthy.size} healthy instances seen, #{@application.instances} healthy instances expected, retrying in in #{HEALTHY_WAIT_RECHECK_INTERVAL}s") end end sleep(HEALTHY_WAIT_RECHECK_INTERVAL) end end end |