Skip to content

Commit

Permalink
Implement graph refresh methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cben committed Jul 17, 2017
1 parent b5af738 commit e096a65
Showing 1 changed file with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,26 @@ def ems_inv_to_hashes(inventory, options = Config::Options.new)
get_templates(inventory)
get_or_merge_openshift_images(inventory)
EmsRefresh.log_inv_debug_trace(@data, "data:")

# Returning a hash triggers save_inventory_container code path.
@data
end

# We rely on Kubernetes initialize_inventory_collections setting up our collections too.
# TODO: does it mean kubernetes refresh would wipe out the openshift tables?
def ems_inv_populate_collections(inventory, _options = Config::Options.new)
super
get_projects_graph(inventory)
get_routes_graph(inventory)
get_builds_graph(inventory)
get_build_pods_graph(inventory)
get_templates_graph(inventory)
# For now, we're reusing @data_index-reading-and-writing code path for images.
get_or_merge_openshift_images(inventory)
end

## hashes -> save_inventory_container methods

def get_or_merge_openshift_images(inventory)
return unless inventory["image"]
inventory["image"].each { |img| get_or_merge_openshift_image(img) }
Expand Down Expand Up @@ -88,6 +105,93 @@ def get_templates(inventory)
end
end

## InventoryObject refresh methods

def get_projects_graph(inventory)
# TODO
end

def get_routes_graph(inventory)
collection = @inv_collections[:container_routes]

inventory["route"].each do |data|
h = parse_route(data)
h[:container_project] = lazy_find_project(:name => h[:namespace])
h[:container_service] = lazy_find_service(h.delete(:container_service_ref))
custom_attrs = h.extract!(:labels)
container_route = collection.build(h)

get_custom_attributes_graph(container_route, custom_attrs)
end
end

def get_builds_graph(inventory)
collection = @inv_collections[:container_builds]

inventory["build_config"].each do |data|
h = parse_build(data)
h[:container_project] = lazy_find_project(:name => h[:namespace])
custom_attrs = h.extract!(:labels)
container_build = collection.build(h)

get_custom_attributes_graph(container_build, custom_attrs)
end
end

def get_build_pods_graph(inventory)
collection = @inv_collections[:container_build_pods]

inventory["build"].each do |data|
h = parse_build_pod(data)
h[:container_build] = lazy_find_build(h.delete(:build_config_ref))
custom_attrs = h.extract!(:labels)
container_build_pod = collection.build(h)

get_custom_attributes_graph(container_build_pod, custom_attrs)
end
end

def get_templates_graph(inventory)
collection = @inv_collections[:container_templates]

inventory["template"].each do |data|
h = parse_template(data)
h[:container_project] = lazy_find_project(:name => h[:namespace])
parameters = h.delete(:container_template_parameters)
custom_attrs = h.extract!(:labels)

container_template = collection.build(h)

get_template_parameters_graph(container_template, parameters)
get_custom_attributes_graph(container_template, custom_attrs)
end
end

def get_template_parameters_graph(parent, parameters)
collection = @inv_collections[:container_template_parameters]

parameters.each do |h|
h[:container_template] = parent
collection.build(h)
end
end

def get_openshift_images_graph(inventory)
return unless inventory["image"]
end

def lazy_find_service(hash)
return nil if hash.nil?
@inv_collections[:container_services].lazy_find_by(hash, :ref => :by_namespace_and_name)
end

def lazy_find_build(hash)
return nil if hash.nil?
@inv_collections[:container_builds].lazy_find_by(hash, :ref => :by_namespace_and_name)
end

## Shared parsing methods

def parse_project(project_item)
new_result = {:name => project_item.metadata.name}
unless project_item.metadata.annotations.nil?
Expand Down

0 comments on commit e096a65

Please sign in to comment.