| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  | module Devops | 
					
						
							| 
									
										
										
										
											2015-07-23 16:56:51 +03:00
										 |  |  |   module API2_0 | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  |     module Routes | 
					
						
							|  |  |  |       module DeployRoutes | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  |         def self.registered(app) | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  |           # Run chef-client on reserved server | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : POST | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Content-Type: application/json | 
					
						
							|  |  |  |           #   - body : | 
					
						
							|  |  |  |           #     { | 
					
						
							|  |  |  |           #       "names": [],  -> array of servers names to run chef-client | 
					
						
							|  |  |  |           #       "tags": [],   -> array of tags to apply on each server before running chef-client | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |           #       "build_number": "", -> string, build number to deploy | 
					
						
							|  |  |  |           #       "trace": true -> return output in stream if true | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  |           #     } | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : text stream | 
					
						
							| 
									
										
										
										
											2015-07-23 16:56:51 +03:00
										 |  |  |           app.post_with_headers "/deploy", :headers => [:content_type] do | 
					
						
							|  |  |  |             check_privileges("server", "x") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if r.key?("trace") | 
					
						
							|  |  |  |               stream() do |out| | 
					
						
							|  |  |  |                 status = [] | 
					
						
							|  |  |  |                 begin | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |                   status = Devops::API2_0::Handler::Deploy.new(request).deploy_stream(out) | 
					
						
							|  |  |  |                   out << create_status(status) | 
					
						
							| 
									
										
										
										
											2015-07-23 16:56:51 +03:00
										 |  |  |                 rescue IOError => e | 
					
						
							|  |  |  |                   logger.error e.message | 
					
						
							|  |  |  |                   break | 
					
						
							|  |  |  |                 end | 
					
						
							|  |  |  |               end # stream | 
					
						
							|  |  |  |             else | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |               ids = Devops::API2_0::Handler::Deploy.new(request).deploy() | 
					
						
							| 
									
										
										
										
											2015-07-23 16:56:51 +03:00
										 |  |  |               sleep 1
 | 
					
						
							|  |  |  |               ids.each do |jid| | 
					
						
							|  |  |  |                 uri.path = "#{DevopsConfig.config[:url_prefix]}/v2.0/report/" + jid | 
					
						
							|  |  |  |                 files.push uri.to_s | 
					
						
							|  |  |  |               end | 
					
						
							|  |  |  |               json files | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  |           puts "Deploy routes initialized" | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |