Permalink
Browse files

When deleting a service associated with app, check if the service is …

…being

used by other apps. If so, present the apps using the service with the message
asking for delete confirmation.

Change-Id: I8cda0da70a2397d551df04a1f1319404857d17b7
  • Loading branch information...
AB Srinivasan Patrick Bozeman
AB Srinivasan authored and Patrick Bozeman committed Aug 19, 2011
1 parent 0eeda16 commit 9874544a119f03524e7762cb8a0ea8a4a8542ab1
Showing with 29 additions and 5 deletions.
  1. +29 −5 lib/cli/commands/apps.rb
View
@@ -202,21 +202,29 @@ def delete_app(appname, force)
app = client.app_info(appname)
services_to_delete = []
app_services = app[:services]
+ services_apps_hash = provisioned_services_apps_hash
app_services.each { |service|
del_service = force && no_prompt ? 'Y' : 'N'
unless no_prompt || force
- del_service = ask("Provisioned service [#{service}] detected, would you like to delete it? [yN]: ")
+ apps_using_service = services_apps_hash[service].reject!{ |app| app == appname}
+ if apps_using_service.size > 0
+ del_service = ask("Provisioned service [#{service}] is being used by #{apps_using_service.entries}, would you still like to delete it? [yN]: ")
+ else
+ del_service = ask("Provisioned service [#{service}] detected, would you like to delete it? [yN]: ")
+ end
end
services_to_delete << service if del_service.upcase == 'Y'
}
display "Deleting application [#{appname}]: ", false
client.delete_app(appname)
display 'OK'.green
- services_to_delete.each do |s|
- display "Deleting service [#{s}]: ", false
- client.delete_service(s)
- display 'OK'.green
+ unless services_to_delete.length == 0
+ services_to_delete.each do |s|
+ display "Deleting service [#{s}]: ", false
+ client.delete_service(s)
+ display 'OK'.green
+ end
end
end
@@ -697,6 +705,22 @@ def bind_services(appname, services)
end
end
+ def provisioned_services_apps_hash
+ apps = client.apps
+ services_apps_hash = {}
+ apps.each {|app|
+ app[:services].each { |svc|
+ svc_apps = services_apps_hash[svc]
+ unless svc_apps
+ svc_apps = Set.new
+ services_apps_hash[svc] = svc_apps
+ end
+ svc_apps.add(app[:name])
+ } unless app[:services] == nil
+ }
+ services_apps_hash
+ end
+
def check_app_limit
usage = client_info[:usage]
limits = client_info[:limits]

0 comments on commit 9874544

Please sign in to comment.