From: Jan Provaznik <jprovazn(a)redhat.com>
https://www.aeolusproject.org/redmine/issues/3160
---
src/app/controllers/deployments_controller.rb | 3 +++
src/app/models/deployment.rb | 9 +++++++++
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/src/app/controllers/deployments_controller.rb
b/src/app/controllers/deployments_controller.rb
index d259a8f..3cdc9c6 100644
--- a/src/app/controllers/deployments_controller.rb
+++ b/src/app/controllers/deployments_controller.rb
@@ -304,6 +304,9 @@ class DeploymentsController < ApplicationController
errors = []
@deployments_to_stop.each do |deployment|
+ # TODO: move all this logic to model
+ deployment.state = Deployment::STATE_SHUTTING_DOWN
+ deployment.save!
deployment.instances.each do |instance|
log_prefix = "#{t('deployments.deployment')}:
#{instance.deployment.name}, #{t('instances.instance')}: #{instance.name}"
begin
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index b2db8c8..3347367 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -73,6 +73,7 @@ class Deployment < ActiveRecord::Base
before_create :inject_launch_parameters
before_create :generate_uuid
before_create :set_pool_family
+ before_create :set_new_state
USER_MUTABLE_ATTRS = ['name']
STATE_MIXED = "mixed"
@@ -161,6 +162,8 @@ class Deployment < ActiveRecord::Base
return
end
+ self.state = Deployment::STATE_SHUTTING_DOWN
+ save!
if instances.all? {|i| i.destroyable? or i.state == Instance::STATE_RUNNING}
destroy_deployment_config
# The deployment will be destroyed from an InstanceObserver callback once
@@ -212,6 +215,8 @@ class Deployment < ActiveRecord::Base
#
# TODO: need to be able to handle deployable-level errors
#
+ self.state = STATE_PENDING
+ save!
status = { :errors => {}, :successes => {} }
status[:errors] = create_instances_with_params(user)
all_inst_match, account, errors = find_match_with_common_account
@@ -571,4 +576,8 @@ class Deployment < ActiveRecord::Base
end
errors
end
+
+ def set_new_state
+ self.state ||= STATE_NEW
+ end
end
--
1.7.7.6