Class: MarathonDeploy::MarathonClient
- Inherits:
-
Object
- Object
- MarathonDeploy::MarathonClient
- Defined in:
- lib/marathon_deploy/marathon_client.rb
Instance Attribute Summary collapse
-
#application ⇒ Object
Returns the value of attribute application.
-
#marathon_url ⇒ Object
readonly
Returns the value of attribute marathon_url.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #deploy ⇒ Object
-
#initialize(url, options = {}) ⇒ MarathonClient
constructor
TODO: Options will contain environment, datacenter.
Constructor Details
#initialize(url, options = {}) ⇒ MarathonClient
TODO: Options will contain environment, datacenter
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/marathon_deploy/marathon_client.rb', line 13 def initialize(url, = {}) raise Error::BadURLError, "invalid url => #{url}", caller if (!HttpUtil.valid_url(url)) @marathon_url = HttpUtil.clean_url(url) @options = if @options[:username] and @options[:password] @options[:basic_auth] = { :username => @options[:username], :password => @options[:password] } @options.delete(:username) @options.delete(:password) end end |
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
10 11 12 |
# File 'lib/marathon_deploy/marathon_client.rb', line 10 def application @application end |
#marathon_url ⇒ Object (readonly)
Returns the value of attribute marathon_url.
9 10 11 |
# File 'lib/marathon_deploy/marathon_client.rb', line 9 def marathon_url @marathon_url end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/marathon_deploy/marathon_client.rb', line 9 def @options end |
Instance Method Details
#deploy ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/marathon_deploy/marathon_client.rb', line 29 def deploy deployment = Deployment.new(@marathon_url,application, [:deployment_timeout]) $LOG.info("Checking if any deployments are already running for application #{application.id}") begin deployment.wait_for_application("Deployment already running for application #{application.id}") rescue Timeout::Error => e raise Timeout::Error, "Timed out after #{deployment.timeout}s waiting for existing deployment of #{application.id} to finish. Check marathon ui #{@marathon_url + '/#deployments'} for stuck deployments!", caller end $LOG.info("Starting deployment of #{application.id}") # if application with this ID already exists if (deployment.applicationExists?) $LOG.info("#{application.id} already exists. Performing update.") response = deployment.update_app # if no application with this ID is seen in marathon else response = deployment.create_app end if ((300..999).include?(response.code.to_i)) rspjson = JSON.parse(response.body) $LOG.error('Deployment error: ' + rspjson['message']) if rspjson.has_key?('message') $LOG.error("With details: #{rspjson}") $LOG.error("Deployment response body => " + JSON.pretty_generate(rspjson)) raise Error::DeploymentError, "Deployment returned response code #{response.code}", caller end $LOG.info("Deployment started for #{application.id} with deployment id #{deployment.deploymentId}") unless (deployment.deploymentId.nil?) # wait for deployment to finish, according to marathon deployment API call begin deployment.wait_for_deployment rescue Timeout::Error => e $LOG.warn("Timed out after waiting for deployment to start") $LOG.warn("Deployment did not start at all") $LOG.warn("Possible reason: deploying the same plan already (use option -f to ensure that plans are unique)") end begin deployment.wait_for_deployment_id rescue Timeout::Error => e $LOG.error("Timed out waiting for deployment of #{application.id} to complete. Canceling deploymentId #{deployment.deploymentId} and rolling back!") deployment.cancel(deployment.deploymentId) raise Timeout::Error, "Deployment of #{application.id} timed out after #{deployment.timeout} seconds", caller end # wait for all instances with defined health checks to be healthy if (!deployment.health_checks_defined?) $LOG.warn("No health checks were defined for application #{application.id}. No health checking will be performed.") end begin deployment.wait_until_healthy rescue Timeout::Error => e raise Timeout::Error, "Timed out after #{deployment.healthcheck_timeout}s waiting for #{application.instances} instances of #{application.id} to become healthy. Check marathon ui #{@marathon_url + '/#deployments'} for more information.", caller end end |