Skip to content
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

Add checks to plugin undeploy #986

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions openc3/lib/openc3/models/plugin_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,15 @@ def as_json(*a)

# Undeploy all models associated with this plugin
def undeploy
errors = []
microservice_count = 0
microservices = MicroserviceModel.find_all_by_plugin(plugin: @name, scope: @scope)
microservices.each do |name, model_instance|
model_instance.destroy
begin
model_instance.destroy
rescue Exception => error
errors << error
end
microservice_count += 1
end
# Wait for the operator to wake up and remove the microservice processes
Expand All @@ -308,15 +313,44 @@ def undeploy
# Save TargetModel for last as it has the most to cleanup
[InterfaceModel, RouterModel, ToolModel, WidgetModel, TargetModel].each do |model|
model.find_all_by_plugin(plugin: @name, scope: @scope).each do |name, model_instance|
model_instance.destroy
begin
model_instance.destroy
rescue Exception => error
errors << error
end
end
end
# Cleanup Redis stuff that might have been left by microservices
microservices.each do |name, model_instance|
model_instance.cleanup
begin
model_instance.cleanup
rescue Exception => error
errors << error
end
end
# Raise all the errors at once
if errors.length > 0
message = ''
errors.each do |error|
message += "\n#{error.formatted}\n"
end
raise message
end
rescue Exception => error
Logger.error("Error undeploying plugin model #{@name} in scope #{@scope} due to #{error}")
Logger.error("Error undeploying plugin model #{@name} in scope #{@scope} due to: #{error}")
ensure
# Double check everything is gone
found = []
[MicroserviceModel, InterfaceModel, RouterModel, ToolModel, WidgetModel, TargetModel].each do |model|
model.find_all_by_plugin(plugin: @name, scope: @scope).each do |name, model_instance|
found << model_instance
end
end
if found.length > 0
# If undeploy failed we need to not move forward with anything else
Logger.error("Error undeploying plugin model #{@name} in scope #{@scope} due to: Plugin submodels still exist after undeploy = #{found.length}")
raise "Plugin #{@name} submodels still exist after undeploy = #{found.length}"
end
end

# Reinstall
Expand Down
Loading