-
Notifications
You must be signed in to change notification settings - Fork 371
Add async recursive delete for apps and service instances #5299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
johha
wants to merge
6
commits into
main
Choose a base branch
from
recursive-app-service-delete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3607217
Add async recursive delete for apps and service instances
johha 05ca1aa
temp logging
johha 52c1b1f
fix logger
johha 1029646
improve audit log so it shows in CF CLI
johha 8dbfcc5
Ensure last operation is set to in progress/failed + better logging
johha 8e4afae
revert setting SI last_operation for sub resource state
johha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| require 'actions/service_instance_unshare' | ||
| require 'cloud_controller/errors/api_error' | ||
| require 'actions/mixins/bindings_delete' | ||
| require 'errors/sub_resource_error' | ||
|
|
||
| module VCAP::CloudController | ||
| module V3 | ||
|
|
@@ -13,9 +14,6 @@ class ServiceInstanceDelete | |
| class DeleteFailed < StandardError | ||
| end | ||
|
|
||
| class UnbindingOperatationInProgress < StandardError | ||
| end | ||
|
|
||
| DeleteStatus = Struct.new(:finished, :operation).freeze | ||
| DeleteStarted = ->(operation) { DeleteStatus.new(false, operation) } | ||
| DeleteComplete = DeleteStatus.new(true, nil).freeze | ||
|
|
@@ -24,9 +22,10 @@ class UnbindingOperatationInProgress < StandardError | |
| PollingFinished = PollingStatus.new(true, nil).freeze | ||
| ContinuePolling = ->(retry_after) { PollingStatus.new(false, retry_after) } | ||
|
|
||
| def initialize(service_instance, event_repo) | ||
| def initialize(service_instance, event_repo, fail_if_in_progress: true) | ||
| @service_instance = service_instance | ||
| @service_event_repository = event_repo | ||
| @fail_if_in_progress = fail_if_in_progress | ||
| end | ||
|
|
||
| def blocking_operation_in_progress? | ||
|
|
@@ -38,7 +37,11 @@ def delete | |
| operation_in_progress! if blocking_operation_in_progress? | ||
|
|
||
| errors = remove_associations | ||
| raise errors.first if errors.any? | ||
| if errors.any? | ||
| raise errors.first if @fail_if_in_progress # Single-shot callers fail on the first error | ||
|
|
||
| SubResourceError.raise_from(errors) | ||
| end | ||
|
|
||
| result = send_deprovison_to_broker | ||
| if result[:finished] | ||
|
|
@@ -49,6 +52,11 @@ def delete | |
| end | ||
|
|
||
| result | ||
| rescue SubResourceError => e | ||
| raise if !@fail_if_in_progress && e.any_in_progress? # re-raise SubResourceError so that root job continues to run | ||
|
|
||
| update_last_operation_with_failure(e.message) unless service_instance.operation_in_progress? | ||
| raise e | ||
| rescue StandardError => e | ||
| update_last_operation_with_failure(e.message) unless service_instance.operation_in_progress? | ||
| raise e | ||
|
Comment on lines
+58
to
62
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most parts of the rescue blocks are identical, so maybe merge them: |
||
|
|
@@ -154,7 +162,9 @@ def unshare_all_spaces | |
|
|
||
| unshare_action = ServiceInstanceUnshare.new | ||
| space_guids.each_with_object([]) do |space_guid, errors| | ||
| unshare_action.unshare(service_instance, Space.first(guid: space_guid), service_event_repository.user_audit_info) | ||
| unshare_action.unshare(service_instance, Space.first(guid: space_guid), service_event_repository.user_audit_info, fail_if_in_progress: @fail_if_in_progress) | ||
| rescue SubResourceError => e | ||
| errors.concat(e.underlying_errors) | ||
| rescue StandardError => e | ||
| errors << e | ||
| end | ||
|
|
@@ -182,14 +192,12 @@ def operation_in_progress! | |
| raise CloudController::Errors::ApiError.new_from_details('AsyncServiceInstanceOperationInProgress', service_instance.name) | ||
| end | ||
|
|
||
| def unbinding_operation_in_progress!(binding) | ||
| raise UnbindingOperatationInProgress.new( | ||
| if binding.is_a?(VCAP::CloudController::ServiceBinding) | ||
| "An operation for the service binding between app #{binding.app.name} and service instance #{service_instance.name} is in progress." | ||
| else | ||
| "An operation for a service binding of service instance #{service_instance.name} is in progress." | ||
| end | ||
| ) | ||
| def unbinding_in_progress_message(binding) | ||
| if binding.is_a?(VCAP::CloudController::ServiceBinding) | ||
| "An operation for the service binding between app #{binding.app.name} and service instance #{service_instance.name} is in progress." | ||
| else | ||
| "An operation for a service binding of service instance #{service_instance.name} is in progress." | ||
| end | ||
| end | ||
|
|
||
| def delete_failed!(message) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,11 +5,13 @@ | |
| require 'actions/app_update' | ||
| require 'actions/app_patch_environment_variables' | ||
| require 'actions/app_delete' | ||
| require 'errors/sub_resource_error' | ||
| require 'actions/app_restart' | ||
| require 'actions/app_apply_manifest' | ||
| require 'actions/app_start' | ||
| require 'actions/app_stop' | ||
| require 'actions/app_assign_droplet' | ||
| require 'jobs/v3/recursive_delete_app_job' | ||
| require 'decorators/include_space_decorator' | ||
| require 'decorators/include_organization_decorator' | ||
| require 'decorators/include_space_organization_decorator' | ||
|
|
@@ -154,12 +156,23 @@ def destroy | |
| unauthorized! unless permission_queryer.can_write_to_active_space?(space.id) | ||
| require_writable_space!(space) | ||
|
|
||
| delete_action = AppDelete.new(user_audit_info) | ||
| deletion_job = VCAP::CloudController::Jobs::DeleteActionJob.new(AppModel, app.guid, delete_action) | ||
| if async_recursive_delete_enabled? | ||
| job = Jobs::Enqueuer.new(queue: Jobs::Queues.generic).enqueue_or_find_active_pollable( | ||
| resource_model: AppModel, | ||
| resource_guid: app.guid, | ||
| operation: 'app.delete' | ||
| ) { VCAP::CloudController::V3::RecursiveDeleteAppJob.new(app.guid, user_audit_info) } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
|
|
||
| job = Jobs::Enqueuer.new(queue: Jobs::Queues.generic).enqueue_pollable(deletion_job) do |pollable_job| | ||
| DeleteAppErrorTranslatorJob.new(pollable_job) | ||
| app_not_found! unless job | ||
| else | ||
| delete_action = AppDelete.new(user_audit_info) | ||
| deletion_job = VCAP::CloudController::Jobs::DeleteActionJob.new(AppModel, app.guid, delete_action) | ||
|
|
||
| job = Jobs::Enqueuer.new(queue: Jobs::Queues.generic).enqueue_pollable(deletion_job) do |pollable_job| | ||
| DeleteAppErrorTranslatorJob.new(pollable_job) | ||
| end | ||
| end | ||
|
|
||
| VCAP::AppLogEmitter.emit(app.guid, "Enqueued job to delete app with guid #{app.guid}") | ||
| head HTTP::ACCEPTED, 'Location' => url_builder.build_url(path: "/v3/jobs/#{job.guid}") | ||
| end | ||
|
|
@@ -372,7 +385,7 @@ class DeleteAppErrorTranslatorJob < VCAP::CloudController::Jobs::ErrorTranslator | |
| include V3ErrorsHelper | ||
|
|
||
| def translate_error(e) | ||
| if e.instance_of?(VCAP::CloudController::AppDelete::SubResourceError) | ||
| if e.instance_of?(VCAP::CloudController::SubResourceError) | ||
| underlying_errors = e.underlying_errors.map { |err| unprocessable(err.message) } | ||
| e = CloudController::Errors::CompoundError.new(underlying_errors) | ||
| end | ||
|
|
@@ -382,6 +395,10 @@ def translate_error(e) | |
|
|
||
| private | ||
|
|
||
| def async_recursive_delete_enabled? | ||
| !!VCAP::CloudController::Config.config.get(:temporary_enable_async_recursive_delete, :apps) | ||
| end | ||
|
|
||
| def handle_order_by_presented_value(page_results) | ||
| return unless page_results.try(:pagination_options).try(:order_by) == 'desired_state' | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point
@fail_if_in_progresswill always be false.