| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | module Connectors | 
					
						
							|  |  |  |   class Stack < Base | 
					
						
							|  |  |  |     include Helpers::InsertCommand, | 
					
						
							|  |  |  |       Helpers::ListCommand, | 
					
						
							| 
									
										
										
										
											2015-07-14 16:51:40 +03:00
										 |  |  |       Helpers::DeleteCommand, | 
					
						
							|  |  |  |       Helpers::UpdateCommand | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def initialize(db) | 
					
						
							| 
									
										
										
										
											2015-09-21 15:54:33 +03:00
										 |  |  |       super(db) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def collection_name | 
					
						
							|  |  |  |       'stacks' | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-22 19:29:42 +03:00
										 |  |  |     def stacks(options={}) | 
					
						
							|  |  |  |       list(options) | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-04 12:36:10 +03:00
										 |  |  |     def set_stack_run_list id, run_list | 
					
						
							|  |  |  |       collection.update({"_id" => id}, {"$set" => {"run_list" => run_list}}) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-04 13:17:07 +03:00
										 |  |  |     def lock_persisting_stack(id) | 
					
						
							|  |  |  |       collection.update({'_id' => id}, {'$set' => {'persisting_is_locked' => true}}) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def unlock_persisting_stack(id) | 
					
						
							|  |  |  |       collection.update({'_id' => id}, {'$set' => {'persisting_is_locked' => false}}) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 16:37:33 +03:00
										 |  |  |     def stack(name, options={}) | 
					
						
							|  |  |  |       query = {'name' => name}.merge(options) | 
					
						
							|  |  |  |       bson = collection.find(query).to_a.first | 
					
						
							| 
									
										
										
										
											2015-08-18 20:01:17 +03:00
										 |  |  |       raise RecordNotFound.new("'#{name}' not found") unless bson | 
					
						
							| 
									
										
										
										
											2015-08-18 16:37:33 +03:00
										 |  |  |       model_from_bson(bson) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-04 13:17:07 +03:00
										 |  |  |     def stack_by_id(id) | 
					
						
							|  |  |  |       query = {'_id' => id} | 
					
						
							|  |  |  |       bson = collection.find(query).to_a.first | 
					
						
							|  |  |  |       raise RecordNotFound.new("'#{id}' not found") unless bson | 
					
						
							|  |  |  |       model_from_bson(bson) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 18:48:46 +03:00
										 |  |  |     def change_stacks_deploy_env(from, to) | 
					
						
							|  |  |  |       collection.update({deploy_env: from}, {'$set' => {deploy_env: to}}, {multi: true}) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  |     private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def model_from_bson(bson) | 
					
						
							|  |  |  |       provider = bson['provider'] | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       Devops::Model::StackFactory.get_class(provider).build_from_bson(bson) | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |