| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  | #root = File.join(File.dirname(__FILE__), "..") | 
					
						
							|  |  |  | #$LOAD_PATH.push root unless $LOAD_PATH.include? root | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require File.join(File.dirname(__FILE__), "worker") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "providers/provider_factory" | 
					
						
							|  |  |  | require "commands/server" | 
					
						
							|  |  |  | require "db/mongo/models/server" | 
					
						
							| 
									
										
										
										
											2014-11-17 14:23:59 +03:00
										 |  |  | require "db/mongo/models/report" | 
					
						
							| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | class BootstrapWorker < Worker | 
					
						
							|  |  |  |   include ServerCommands | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 14:23:59 +03:00
										 |  |  |   def perform(dir, e_provider, server, owner, conf) | 
					
						
							| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  |     set_status jid, "init" | 
					
						
							|  |  |  |     config = convert_config(conf) | 
					
						
							| 
									
										
										
										
											2014-11-17 14:23:59 +03:00
										 |  |  |     file = File.join(dir, jid) | 
					
						
							|  |  |  |     File.open(file, "w") do |out| | 
					
						
							| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  |       begin | 
					
						
							|  |  |  |         set_status jid, "running" | 
					
						
							|  |  |  |         mongo = mongo_connector(config) | 
					
						
							|  |  |  |         ::Provider::ProviderFactory.init(config) | 
					
						
							|  |  |  |         provider = ::Provider::ProviderFactory.get(e_provider) | 
					
						
							|  |  |  |         logger.debug "Provider: #{provider.inspect}" | 
					
						
							|  |  |  |         s = Server.new(server) | 
					
						
							|  |  |  |         s.options = convert_config(server["options"]) | 
					
						
							| 
									
										
										
										
											2014-11-17 14:23:59 +03:00
										 |  |  |         o = { | 
					
						
							|  |  |  |           "file" => file, | 
					
						
							|  |  |  |           "_id" => jid, | 
					
						
							|  |  |  |           "created_by" => owner, | 
					
						
							|  |  |  |           "project" => s.project, | 
					
						
							|  |  |  |           "deploy_env" => s.deploy_env, | 
					
						
							|  |  |  |           "type" => Report::BOOTSTRAP_TYPE | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         mongo.save_report(Report.new(o)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  |         key = mongo.key(s.key) | 
					
						
							|  |  |  |         out << "\nBootstrap with run list: #{s.options[:run_list].inspect}" | 
					
						
							|  |  |  |         status = bootstrap(s, out, key.path, logger) | 
					
						
							|  |  |  |         if status == 0
 | 
					
						
							|  |  |  |           out << "Chef node name: #{s.chef_node_name}\n" | 
					
						
							|  |  |  |           mongo.server_set_chef_node_name s | 
					
						
							|  |  |  |           out << "Chef node name has been updated\n" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         set_status jid, (status == 0 ? "completed" : "failed") | 
					
						
							|  |  |  |       rescue Exception => e | 
					
						
							|  |  |  |         out << "\n" | 
					
						
							|  |  |  |         out << e.message | 
					
						
							|  |  |  |         out << "\n" | 
					
						
							|  |  |  |         out << e.backtrace.join("\n") | 
					
						
							|  |  |  |         set_status jid, "failed" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 |