[PATCH conductor 2/2] This patch detect duplicate images in deployable.xml and for those images it do only one request for fetch data from iwhd.
Jozef Zigmund
jzigmund at redhat.com
Tue May 22 15:11:30 UTC 2012
On Tuesday 22 May 2012 16:15:03 Tomas Hrcka wrote:
> ---
> src/app/controllers/pools_controller.rb | 18 ++++++++++++++++--
> src/app/models/deployable.rb | 11 +++++++++++
> src/app/models/pool.rb | 18 +++++++++++++++++-
> src/app/views/pools/_images.html.haml | 15 ++++++---------
> 4 files changed, 50 insertions(+), 12 deletions(-)
>
> diff --git a/src/app/controllers/pools_controller.rb
> b/src/app/controllers/pools_controller.rb index 6eaa6f1..ee7576b 100644
> --- a/src/app/controllers/pools_controller.rb
> +++ b/src/app/controllers/pools_controller.rb
> @@ -99,9 +99,23 @@ class PoolsController < ApplicationController
> save_breadcrumb(pool_path(@pool, :viewstate => viewstate_id),
> @pool.name) require_privilege(Privilege::VIEW, @pool)
> @statistics = @pool.statistics(current_user)
> - @view = filter_view? ? 'deployments/list' : 'deployments/pretty_view'
> unless params[:details_tab] - if params[:details_tab] == 'deployments'
> +
> + unless params[:details_tab]
unless-else combitanion, rather use if params[:details_tab].nil? - else
> @view = filter_view? ? 'deployments/list' : 'deployments/pretty_view'
> + else
> + case params[:details_tab]
> + when 'images'
> + #this case covers fetching of unique images and constructing
> collection for filter table + @header = [{:name => "catalog"},
> {:name => "deployable"}, {:name => "image"}, {:name => "provider_image"}] +
> puts
> "==========================================================================
> ============================================================================
> =====================" + puts
> "==========================================================================
> ============================================================================
> =====================" +
> + puts
> "==========================================================================
> ============================================================================
> =====================" + puts
> "==========================================================================
> ============================================================================
> ====================="
remove this ^
> + @catalog_images =
> @pool.catalog_images_collection(@pool.catalogs.list_for_user(current_user,
> Privilege::VIEW)) + when 'deployments'
> + @view = filter_view? ? 'deployments/list' :
> 'deployments/pretty_view' + end
> end
>
> #TODO add links to real data for history,properties,permissions
> diff --git a/src/app/models/deployable.rb b/src/app/models/deployable.rb
> index 201123f..c99cca2 100644
> --- a/src/app/models/deployable.rb
> +++ b/src/app/models/deployable.rb
> @@ -85,6 +85,17 @@ class Deployable < ActiveRecord::Base
> uuids.map { |uuid| Aeolus::Image::Warehouse::Image.find(uuid) }
> end
>
> + def fetch_unique_images
> + uuids = fetch_image_uuids || []
> + uniq_uuids = uuids.uniq
> + result_hash = {}
> + uniq_uuids.each do |uuid|
> + result_hash[uuid] = { :image =>
> Aeolus::Image::Warehouse::Image.find(uuid), :count => uuids.count(uuid)} +
> end
> + result_hash
> + end
> +
> +
> def fetch_image_uuids
> deployable = fetch_deployable
> deployable.image_uuids unless deployable.nil?
> diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
> index f8daa58..a47a64a 100644
> --- a/src/app/models/pool.rb
> +++ b/src/app/models/pool.rb
> @@ -165,7 +165,23 @@ class Pool < ActiveRecord::Base
> def self.additional_privilege_target_types
> [Deployment, Instance, Catalog, Quota]
> end
> -
> + def catalog_images_collection(catalog_list)
> + catalog_images = []
> + catalog_list.each do |catalog|
> + catalog.deployables.each do |deployable|
> + deployable.fetch_unique_images.each do |key,value|
> + row = {:catalog => catalog.name ,:deployable => deployable.name,
> + :image => "#{value[:image].name} #{value[:image].uuid}",
> :provider_images =>[] } +
> + value[:image].provider_images.each do |provider_image|
> + row[:provider_images] << I18n.t('pools.images.pushed', :uuid =>
> provider_image.uuid, :provider => provider_image.provider_name) +
> end
> + value[:count].times {catalog_images << row}
> + end
> + end
> + end
> + catalog_images
> + end
> private
>
> def self.apply_search_filter(search)
> diff --git a/src/app/views/pools/_images.html.haml
> b/src/app/views/pools/_images.html.haml index ff43d1d..f63a050 100644
> --- a/src/app/views/pools/_images.html.haml
> +++ b/src/app/views/pools/_images.html.haml
> @@ -5,12 +5,9 @@
> =image_tag 'flash_error_icon.png', :alt => 'Errors'
> =flash[:error]
> -else
> - =filter_table(@header, @catalogs) do |catalog|
> - - catalog.deployables.each do |deployable|
> - - deployable.fetch_images.compact.each do |image|
> - %tr
> - %td= catalog.name
> - %td= deployable.name
> - %td= "#{image.name} (#{image.uuid})"
> - - image.provider_images.each do |provider_image|
> - %td= t('pools.images.pushed', :uuid => provider_image.uuid,
> :provider => provider_image.provider_name)
> +=filter_table(@header, at catalog_images) do |catalog_image|
> + %tr{:class => cycle('nostripe','stripe')}
> + %td=catalog_image[:catalog]
> + %td=catalog_image[:deployable]
> + %td=catalog_image[:image]
> + %td=catalog_image[:provider_images]
ACK. Pls fix inline notes.
More information about the aeolus-devel
mailing list