Skip to content

Commit

Permalink
Merge pull request #15393 from zeari/unify_container_definition
Browse files Browse the repository at this point in the history
Merge container_definition and container
  • Loading branch information
Fryguy authored Jul 26, 2017
2 parents 56f639e + 750d3c4 commit b4554f7
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 133 deletions.
7 changes: 4 additions & 3 deletions app/models/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ class Container < ApplicationRecord
include ArchivedMixin
include_concern 'Purging'

has_one :container_group, :through => :container_definition
belongs_to :container_group
belongs_to :ext_management_system, :foreign_key => :ems_id
has_one :container_node, :through => :container_group
has_one :container_replicator, :through => :container_group
has_one :container_project, :through => :container_group
has_one :old_container_project, :through => :container_group
belongs_to :container_definition
belongs_to :container_image
has_many :container_port_configs, :dependent => :destroy
has_many :container_env_vars, :dependent => :destroy
has_one :container_image_registry, :through => :container_image
has_one :security_context, :through => :container_definition
has_one :security_context, :as => :resource, :dependent => :destroy

# Metrics destroy are handled by the purger
has_many :metrics, :as => :resource
Expand Down
20 changes: 0 additions & 20 deletions app/models/container_definition.rb

This file was deleted.

20 changes: 0 additions & 20 deletions app/models/container_definition/purging.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/container_env_var.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class ContainerEnvVar < ApplicationRecord
belongs_to :container_definition
belongs_to :container
end
8 changes: 3 additions & 5 deletions app/models/container_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ class ContainerGroup < ApplicationRecord
# :name, :uid, :creation_timestamp, :resource_version, :namespace
# :labels, :restart_policy, :dns_policy

has_many :containers,
:through => :container_definitions
has_many :container_definitions, :dependent => :destroy
has_many :container_images, -> { distinct }, :through => :container_definitions
has_many :containers, :dependent => :destroy
has_many :container_images, -> { distinct }, :through => :containers
belongs_to :ext_management_system, :foreign_key => "ems_id"
has_many :labels, -> { where(:section => "labels") }, :class_name => CustomAttribute, :as => :resource, :dependent => :destroy
has_many :node_selector_parts, -> { where(:section => "node_selectors") }, :class_name => "CustomAttribute", :as => :resource, :dependent => :destroy
Expand Down Expand Up @@ -84,7 +82,7 @@ def disconnect_inv
return if ems_id.nil?
_log.info "Disconnecting Pod [#{name}] id [#{id}] from EMS [#{ext_management_system.name}]" \
"id [#{ext_management_system.id}] "
self.container_definitions.each(&:disconnect_inv)
self.containers.each(&:disconnect_inv)
self.container_node_id = nil
self.container_services = []
self.container_replicator_id = nil
Expand Down
2 changes: 1 addition & 1 deletion app/models/container_port_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ContainerPortConfig < ApplicationRecord
# :port, :host_port, :protocol
belongs_to :container_definition
belongs_to :container
end
4 changes: 2 additions & 2 deletions app/models/container_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ContainerProject < ApplicationRecord
has_many :container_replicators
has_many :container_services
has_many :containers, :through => :container_groups
has_many :container_definitions, :through => :container_groups
has_many :containers, :through => :container_groups
has_many :container_images, -> { distinct }, :through => :container_groups
has_many :container_nodes, -> { distinct }, :through => :container_groups
has_many :container_quotas
Expand All @@ -31,7 +31,7 @@ class ContainerProject < ApplicationRecord
virtual_total :services_count, :container_services
virtual_total :routes_count, :container_routes
virtual_total :replicators_count, :container_replicators
virtual_total :containers_count, :container_definitions
virtual_total :containers_count, :containers
virtual_total :images_count, :container_images

include EventMixin
Expand Down
44 changes: 18 additions & 26 deletions app/models/ems_refresh/save_inventory_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,35 +161,36 @@ def save_container_groups_inventory(ems, hashes)
end

save_inventory_multi(ems.container_groups, hashes, :use_association, [:ems_ref],
[:container_definitions, :containers, :labels, :tags,
[:containers, :labels, :tags,
:node_selector_parts, :container_conditions, :container_volumes],
[:container_node, :container_replicator, :project, :namespace, :build_pod_name],
true)
store_ids_for_new_records(ems.container_groups, hashes, :ems_ref)
end

def save_container_definitions_inventory(container_group, hashes)
def save_containers_inventory(container_group, hashes)
return if hashes.nil?

container_group.container_definitions.reset
container_group.containers.reset

hashes.each do |h|
h[:ems_id] = container_group[:ems_id]
h[:container_image_id] = h[:container_image][:id]
end

save_inventory_multi(container_group.container_definitions, hashes, :use_association, [:ems_ref],
[:container_port_configs, :container_env_vars, :security_context, :container],
[], true)
store_ids_for_new_records(container_group.container_definitions, hashes, :ems_ref)
save_inventory_multi(container_group.containers, hashes, :use_association, [:ems_ref],
[:container_port_configs, :container_env_vars, :security_context],
[:container_image], true)
store_ids_for_new_records(container_group.containers, hashes, :ems_ref)
end

def save_container_port_configs_inventory(container_definition, hashes)
def save_container_port_configs_inventory(container, hashes)
return if hashes.nil?

container_definition.container_port_configs.reset
container.container_port_configs.reset

save_inventory_multi(container_definition.container_port_configs, hashes, :use_association, [:ems_ref])
store_ids_for_new_records(container_definition.container_port_configs, hashes, :ems_ref)
save_inventory_multi(container.container_port_configs, hashes, :use_association, [:ems_ref])
store_ids_for_new_records(container.container_port_configs, hashes, :ems_ref)
end

def save_container_service_port_configs_inventory(container_service, hashes)
Expand All @@ -201,12 +202,12 @@ def save_container_service_port_configs_inventory(container_service, hashes)
store_ids_for_new_records(container_service.container_service_port_configs, hashes, :ems_ref)
end

def save_container_env_vars_inventory(container_definition, hashes)
def save_container_env_vars_inventory(container, hashes)
return if hashes.nil?
container_definition.container_env_vars.reset
container.container_env_vars.reset

save_inventory_multi(container_definition.container_env_vars, hashes, :use_association, [:name, :value, :field_path])
store_ids_for_new_records(container_definition.container_env_vars, hashes, [:name, :value, :field_path])
save_inventory_multi(container.container_env_vars, hashes, :use_association, [:name, :value, :field_path])
store_ids_for_new_records(container.container_env_vars, hashes, [:name, :value, :field_path])
end

def save_container_images_inventory(ems, hashes)
Expand Down Expand Up @@ -243,15 +244,6 @@ def save_container_component_statuses_inventory(ems, hashes)
store_ids_for_new_records(ems.container_component_statuses, hashes, :name)
end

def save_container_inventory(container_definition, hash)
# The hash could be nil when the container is in transition (still downloading
# the image, or stuck in Pending, or unable to fetch the image). Passing nil to
# save_inventory_single is used to delete any pre-existing entity in containers,
hash[:container_image_id] = hash[:container_image][:id] unless hash.nil?
hash[:ems_id] = container_definition[:ems_id] unless hash.nil?
save_inventory_single(:container, container_definition, hash, [], :container_image, true)
end

def save_container_conditions_inventory(container_entity, hashes)
return if hashes.nil?

Expand All @@ -261,8 +253,8 @@ def save_container_conditions_inventory(container_entity, hashes)
store_ids_for_new_records(container_entity.container_conditions, hashes, :name)
end

def save_security_context_inventory(container_definition, hash)
save_inventory_single(:security_context, container_definition, hash)
def save_security_context_inventory(container, hash)
save_inventory_single(:security_context, container, hash)
end

def save_container_volumes_inventory(container_group, hashes)
Expand Down
6 changes: 3 additions & 3 deletions app/models/manageiq/providers/container_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class ContainerManager < BaseManager
has_many :computer_system_hardwares, :through => :computer_systems, :source => :hardware
has_many :computer_system_operating_systems, :through => :computer_systems, :source => :operating_system
has_many :container_volumes, :through => :container_groups
has_many :container_port_configs, :through => :container_definitions
has_many :container_env_vars, :through => :container_definitions
has_many :security_contexts, :through => :container_definitions
has_many :container_port_configs, :through => :containers
has_many :container_env_vars, :through => :containers
has_many :security_contexts, :through => :containers
has_many :container_service_port_configs, :through => :container_services
has_many :container_routes, :through => :container_services
has_many :container_quota_items, :through => :container_quotas
Expand Down
1 change: 0 additions & 1 deletion app/models/miq_schedule_worker/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def archived_entities_purge_timer
queue_work(:class_name => "ContainerGroup", :method_name => "purge_timer", :zone => nil)
queue_work(:class_name => "ContainerImage", :method_name => "purge_timer", :zone => nil)
queue_work(:class_name => "ContainerProject", :method_name => "purge_timer", :zone => nil)
queue_work(:class_name => "ContainerDefinition", :method_name => "purge_timer", :zone => nil)
end

def miq_schedule_queue_scheduled_work(schedule_id, rufus_job)
Expand Down
4 changes: 0 additions & 4 deletions spec/factories/container_definition.rb

This file was deleted.

47 changes: 0 additions & 47 deletions spec/models/container_definition/purging_spec.rb

This file was deleted.

0 comments on commit b4554f7

Please sign in to comment.