| 
									
										
										
										
											2015-07-23 12:54:36 +03:00
										 |  |  | require 'commands/commands_storage' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  | module StackCommands | 
					
						
							| 
									
										
										
										
											2015-07-23 12:54:36 +03:00
										 |  |  |   extend self | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-05 15:06:18 +03:00
										 |  |  |   def sync_bootstrap_proc | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  |     lambda do |out, stack, mongo| | 
					
						
							| 
									
										
										
										
											2015-07-30 02:14:45 +03:00
										 |  |  |       # two tries each 4 seconds, then 5 tries each 10 seconds, then 5 tries each minute. | 
					
						
							|  |  |  |       sleep_times = [4]*2 + [10]*5 + [60]*5
 | 
					
						
							| 
									
										
										
										
											2015-07-21 17:13:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  |       begin | 
					
						
							| 
									
										
										
										
											2015-07-21 17:13:10 +03:00
										 |  |  |         out << "Syncing stack '#{stack.id}'...\n" | 
					
						
							|  |  |  |         sleep_times.each do |sleep_time| | 
					
						
							|  |  |  |           sleep sleep_time | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  |           stack.sync_details! | 
					
						
							| 
									
										
										
										
											2015-08-20 22:15:34 +03:00
										 |  |  | 	  case stack.stack_status | 
					
						
							| 
									
										
										
										
											2015-08-20 21:55:44 +03:00
										 |  |  | 	  when 'CREATE_IN_PROGRESS' | 
					
						
							|  |  |  |             out << "." | 
					
						
							|  |  |  | 	    out.flush | 
					
						
							|  |  |  | 	  when 'CREATE_COMPLETE' | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  |             mongo.stack_update(stack) | 
					
						
							| 
									
										
										
										
											2015-08-19 19:34:46 +03:00
										 |  |  |             out << "\nStack '#{stack.id}' status is now #{stack.stack_status}\n" | 
					
						
							| 
									
										
										
										
											2015-08-18 17:53:39 +03:00
										 |  |  |             out.flush | 
					
						
							| 
									
										
										
										
											2015-08-20 21:55:44 +03:00
										 |  |  |             return 0
 | 
					
						
							|  |  |  | 	  when 'ROLLBACK_COMPLETE' | 
					
						
							|  |  |  |             out << "\nStack '#{stack.id}' status is rolled back\n" | 
					
						
							|  |  |  | 	    return 1
 | 
					
						
							|  |  |  | 	  else | 
					
						
							|  |  |  | 	    out << "\nUnknown status: '#{stack.stack_status}'" | 
					
						
							|  |  |  | 	    return 2
 | 
					
						
							|  |  |  | 	  end | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  |         end | 
					
						
							|  |  |  |       rescue StandardError => e | 
					
						
							|  |  |  |         logger.error e.message | 
					
						
							| 
									
										
										
										
											2015-08-18 17:53:39 +03:00
										 |  |  |         out << "Error: #{e.message}\n" | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  |         return 5
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 16:39:41 +03:00
										 |  |  | =begin | 
					
						
							| 
									
										
										
										
											2015-08-05 15:06:18 +03:00
										 |  |  |   def bootstrap_stack_servers_proc(out, stack, mongo, provider, logger) | 
					
						
							|  |  |  |     mongo.stack_servers(stack.id).each do |server| | 
					
						
							|  |  |  |       key = mongo.key(server.key) | 
					
						
							|  |  |  |       two_phase_bootstrap(server, out, provider, mongo, key.path, logger) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-07-30 13:18:55 +03:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-08-12 16:39:41 +03:00
										 |  |  | =end | 
					
						
							| 
									
										
										
										
											2015-07-30 13:18:55 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 12:54:36 +03:00
										 |  |  |   CommandsStorage.add_job_lambda( | 
					
						
							| 
									
										
										
										
											2015-08-05 15:06:18 +03:00
										 |  |  |     sync_bootstrap: sync_bootstrap_proc | 
					
						
							| 
									
										
										
										
											2015-07-23 12:54:36 +03:00
										 |  |  |   ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:59:26 +03:00
										 |  |  | end |