From: Greg Blomquist <gblomqui(a)redhat.com>
Now, when a deployment is deleted, a message is sent to the config server to
delete the configs associated with that deployment.
A couple of notes:
* this patch assumes that all instances in a deployable are launched in the
same provider account
* a 404 from the config server is ignored by the delete_deployment_config
process, in case an admin manually deleted the configs from the config server
already
---
src/app/models/config_server.rb | 15 ++++++++++++++-
src/app/models/deployment.rb | 14 ++++++++++++++
2 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/src/app/models/config_server.rb b/src/app/models/config_server.rb
index 80d6507..5a43614 100644
--- a/src/app/models/config_server.rb
+++ b/src/app/models/config_server.rb
@@ -71,6 +71,8 @@ class ConfigServer < ActiveRecord::Base
validates_presence_of :secret
validate :validate_connection
+ API_VERSION = "1"
+
# Reports the error message (if any) produced by testing the connection to
# this config server.
def connection_error_msg
@@ -97,13 +99,24 @@ class ConfigServer < ActiveRecord::Base
end
def send_config(instance_config)
- url = "#{endpoint}/configs/0/#{instance_config.uuid}"
+ url = "#{endpoint}/configs/#{API_VERSION}/#{instance_config.uuid}"
args = get_connection_args(url, "post")
data = CGI::escape(instance_config.to_s)
args[:payload] = "data=#{data}"
RestClient::Request.execute(args)
end
+ def delete_deployment_config(deployment_uuid)
+ url = "#{endpoint}/deployment/#{API_VERSION}/#{deployment_uuid}"
+ args = get_connection_args(url, "delete")
+ begin
+ RestClient::Request.execute(args)
+ rescue RestClient::ResourceNotFound => e
+ # allow for 404s, this means that the configs don't exist on this config
+ # server
+ end
+ end
+
private
def status
# smells like a factory in here
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index c696b58..0ff2293 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -140,11 +140,13 @@ class Deployment < ActiveRecord::Base
def stop_instances_and_destroy!
if destroyable?
+ destroy_deployment_config
destroy
return
end
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
# all instances are stopped.
self.scheduled_for_deletion = true
@@ -453,6 +455,18 @@ class Deployment < ActiveRecord::Base
end
end
+ def destroy_deployment_config
+ # the implication here is that if there is an instance in this deployment
+ # with userdata, then a config server was associated with this deployment;
+ # further, the config server associated with one instance is the same config
+ # server used for all instances in the deployment
+ # this logic could easily change
+ if instances.any? {|instance| instance.user_data}
+ configserver = instances.first.provider_account.config_server
+ configserver.delete_deployment_config(uuid) if configserver
+ end
+ end
+
def generate_uuid
self[:uuid] = UUIDTools::UUID.timestamp_create.to_s
end
--
1.7.4.4