Class: Orch::Marathon
- Inherits:
-
Object
- Object
- Orch::Marathon
- Defined in:
- lib/marathon.rb
Instance Method Summary collapse
- #delete(url_list, id) ⇒ Object
- #deploy(url_list, app_id, json_payload) ⇒ Object
- #find_diffs(spec, job) ⇒ Object
-
#initialize(options) ⇒ Marathon
constructor
A new instance of Marathon.
- #restart(url_list, app_id) ⇒ Object
- #verify(url_list, json_payload) ⇒ Object
Constructor Details
#initialize(options) ⇒ Marathon
Returns a new instance of Marathon.
16 17 |
# File 'lib/marathon.rb', line 16 def initialize() end |
Instance Method Details
#delete(url_list, id) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/marathon.rb', line 41 def delete(url_list, id) if url_list.nil? exit_with_msg "marathon_url not defined" end response = http_delete(url_list, "/v2/apps/#{id}", JSON_HEADERS) if response.code == 200.to_s puts "successfully deleted #{id}" elsif response.code == 404.to_s puts "job: #{id} - does not exist to delete" else puts "Response #{response.code} #{response.}: #{response.body}" end return response end |
#deploy(url_list, app_id, json_payload) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/marathon.rb', line 19 def deploy(url_list, app_id, json_payload) if url_list.nil? exit_with_msg "marathon_url not defined" end response = http_put(url_list, "/v2/apps/#{app_id}", json_payload, JSON_HEADERS) # TODO: should we do anyting with version or deploymentId that gets returned? if response.code == 201.to_s puts "successfully created marathon job: #{app_id}" elsif response.code == 200.to_s puts "successfully updated marathon job: #{app_id}" elsif response.code == 401.to_s puts "Authentication required" exit 1 else puts "Response #{response.code} #{response.}: #{response.body}" end return response end |
#find_diffs(spec, job) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/marathon.rb', line 103 def find_diffs(spec, job) foundDiff = false spec.each_key do |key| if spec[key].is_a?(Hash) if find_diffs(spec[key], job[key]) == true foundDiff = true end next end if spec[key].is_a?(Array) if spec[key].length != job[key].length printf "difference for field: #{key} - length of array is different\n" printf " spec: #{spec[key].to_json}\n" printf " server: #{job[key].to_json}\n" foundDiff = true end # TODO: this will not work if arrays are not in same order spec[key].zip(job[key]).each do |subSpec, subJob| if find_diffs(subSpec, subJob) == true foundDiff = true end next end next end specVal = spec[key] jobVal = job[key] if spec[key].to_s.numeric? specVal = Float(spec[key]) jobVal = Float(job[key]) end if specVal != jobVal printf "difference for field: #{key}\n" printf " spec: #{specVal}\n" printf " server: #{jobVal}\n" foundDiff = true end end return foundDiff end |
#restart(url_list, app_id) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/marathon.rb', line 86 def restart(url_list, app_id) if url_list.nil? exit_with_msg "marathon_url not defined" end # POST /v2/apps/{appId}/restart: Rolling restart of all tasks of the given app response = http_post(url_list, "/v2/apps/#{app_id}/restart", {}.to_json, JSON_HEADERS) if response.code == 200.to_s puts "success" else puts "Response #{response.code} #{response.}: #{response.body}" end return response end |
#verify(url_list, json_payload) ⇒ Object
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 |
# File 'lib/marathon.rb', line 59 def verify(url_list, json_payload) if url_list.nil? puts "no marathon_url - can not verify with server" return end spec = Hashie::Mash.new(JSON.parse(json_payload)) response = http_get(url_list, "/v2/apps/#{spec.id}", JSON_HEADERS) if response.code == 200.to_s job = Hashie::Mash.new(JSON.parse(response.body)) foundDiffs = find_diffs(spec, job.app) elsif response.code == 401.to_s puts "Authentication required" exit 1 elsif response.code == 404.to_s puts "job: #{spec.id} - not defined in Marathon" foundDiffs = true else puts "Response #{response.code} #{response.}: #{response.body}" foundDiffs = true end return foundDiffs end |