Skip to content

Commit

Permalink
Merge pull request #986 from OpenC3/plugin_undeploy_checks
Browse files Browse the repository at this point in the history
Add checks to plugin undeploy
  • Loading branch information
ryanmelt authored Dec 18, 2023
2 parents f2c48a9 + deb694d commit b4c2afb
Showing 1 changed file with 38 additions and 4 deletions.
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

0 comments on commit b4c2afb

Please sign in to comment.