Merge pull request #916 from warpc/893-regenerate_metadata

[refs #893] Ability manually regenerate metadata in repository of main platform;
This commit is contained in:
Vladimir Sharshov 2013-02-13 08:01:38 -08:00
commit 11f95f1271
10 changed files with 83 additions and 7 deletions

View File

@ -140,6 +140,15 @@ class Platforms::RepositoriesController < Platforms::BaseController
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.project_removed') redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.project_removed')
end end
def regenerate_metadata
if AbfWorker::BuildListsPublishTaskManager.repository_regenerate_metadata @repository.id
flash[:notice] = t('flash.repository.regenerate_in_queue')
else
flash[:error] = t('flash.repository.regenerate_already_in_queue')
end
redirect_to platform_repository_path(@platform, @repository)
end
protected protected
def set_members def set_members

View File

@ -103,7 +103,7 @@ class Ability
can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'User', :owner_id => user.id}
can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids}
can([:read, :projects_list, :projects], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} can([:read, :projects_list, :projects], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform}
can([:create, :edit, :update, :destroy, :projects_list, :projects, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform} can([:create, :edit, :update, :destroy, :projects_list, :projects, :add_project, :remove_project, :regenerate_metadata], Repository) {|repository| local_admin? repository.platform}
can([:remove_members, :remove_member, :add_member, :signatures], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)} can([:remove_members, :remove_member, :add_member, :signatures], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)}
can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)} can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)}
can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?} can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?}
@ -159,6 +159,8 @@ class Ability
cannot([:get_list, :create], MassBuild) {|mass_build| mass_build.platform.personal?} cannot([:get_list, :create], MassBuild) {|mass_build| mass_build.platform.personal?}
cannot(:cancel, MassBuild) {|mass_build| mass_build.platform.personal? || mass_build.stop_build} cannot(:cancel, MassBuild) {|mass_build| mass_build.platform.personal? || mass_build.stop_build}
cannot(:regenerate_metadata, Repository) {|repository| !repository.platform.main?}
if @user.system? if @user.system?
can :key_pair, Repository can :key_pair, Repository
else else

View File

@ -179,6 +179,7 @@ class Project < ActiveRecord::Base
end end
def default_head treeish = nil # maybe need change 'head'? def default_head treeish = nil # maybe need change 'head'?
return treeish if repo.commit(treeish).present?
if repo.branches_and_tags.map(&:name).include?(treeish || default_branch) if repo.branches_and_tags.map(&:name).include?(treeish || default_branch)
treeish || default_branch treeish || default_branch
else else

View File

@ -2,7 +2,6 @@
class Repository < ActiveRecord::Base class Repository < ActiveRecord::Base
belongs_to :platform belongs_to :platform
has_many :relations, :as => :target, :dependent => :destroy has_many :relations, :as => :target, :dependent => :destroy
has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy
has_many :members, :through => :actors, :source => :actor, :source_type => 'User' has_many :members, :through => :actors, :source => :actor, :source_type => 'User'

View File

@ -1,6 +1,11 @@
- unless ['edit', 'update'].include? controller.action_name - if ['edit', 'update'].exclude? controller.action_name
.leftlist= f.label :name, t("activerecord.attributes.repository.name"), :class => :label .leftlist= f.label :name, t("activerecord.attributes.repository.name"), :class => :label
.rightlist= f.text_field :name, :class => 'text_field' .rightlist= f.text_field :name, :class => 'text_field'
- elsif can? :regenerate_metadata, @repository
.leftlist
.rightlist
= link_to t("layout.repositories.regenerate_metadata"), regenerate_metadata_platform_repository_path(@platform, @repository),
:method => :put, :confirm => t('layout.confirm'), :class => :button
.leftlist= f.label :description, t("activerecord.attributes.repository.description"), :class => :label .leftlist= f.label :description, t("activerecord.attributes.repository.description"), :class => :label
.rightlist= f.text_field :description, :class => 'text_field' .rightlist= f.text_field :description, :class => 'text_field'

View File

@ -18,6 +18,7 @@ en:
clear: Clear clear: Clear
clear_confirm: Are you sure you want to clear this platform? clear_confirm: Are you sure you want to clear this platform?
clear_warning: Attention! Cleared packages cannot be restored! clear_warning: Attention! Cleared packages cannot be restored!
regenerate_metadata: Regenerate metadata
personal_repositories: personal_repositories:
settings_header: Settings settings_header: Settings
@ -42,6 +43,8 @@ en:
members: members:
successfully_added: "%{name} successfully added to the repository" successfully_added: "%{name} successfully added to the repository"
error_in_adding: "Unable to add %{name} as member" error_in_adding: "Unable to add %{name} as member"
regenerate_in_queue: Repository is queued for regenerate metadata
regenerate_already_in_queue: Repository is already queued for regenerate metadata
activerecord: activerecord:
models: models:

View File

@ -18,6 +18,7 @@ ru:
clear: Очистить clear: Очистить
clear_confirm: Уверены, что хотите очистить платформу? clear_confirm: Уверены, что хотите очистить платформу?
clear_warning: Внимание! Очищенные пакеты не могут быть восстановлены! clear_warning: Внимание! Очищенные пакеты не могут быть восстановлены!
regenerate_metadata: Регенерировать метаданные
personal_repositories: personal_repositories:
settings_header: Настройки settings_header: Настройки
@ -42,6 +43,8 @@ ru:
members: members:
successfully_added: "Участник %{name} успешно добавлен к репозиторию" successfully_added: "Участник %{name} успешно добавлен к репозиторию"
error_in_adding: "Не удалось добавить участника %{name}" error_in_adding: "Не удалось добавить участника %{name}"
regenerate_in_queue: Репозиторий поставлен в очередь на регенерацию метаданных
regenerate_already_in_queue: Репозиторий уже в очереди на регенерацию метаданных
activerecord: activerecord:
models: models:

View File

@ -156,6 +156,7 @@ Rosa::Application.routes.draw do
post :remove_members # fixme: change post to delete post :remove_members # fixme: change post to delete
delete :remove_member delete :remove_member
post :add_member post :add_member
put :regenerate_metadata
end end
end end
resources :key_pairs, :only => [:create, :index, :destroy] resources :key_pairs, :only => [:create, :index, :destroy]

View File

@ -8,7 +8,8 @@ module AbfWorker
LOCKED_PROJECTS_FOR_CLEANUP LOCKED_PROJECTS_FOR_CLEANUP
LOCKED_REPOSITORIES LOCKED_REPOSITORIES
LOCKED_REP_AND_PLATFORMS LOCKED_REP_AND_PLATFORMS
LOCKED_BUILD_LISTS).each do |kind| LOCKED_BUILD_LISTS
REGENERATE_METADATA).each do |kind|
const_set kind, "#{REDIS_MAIN_KEY}#{kind.downcase.gsub('_', '-')}" const_set kind, "#{REDIS_MAIN_KEY}#{kind.downcase.gsub('_', '-')}"
end end
@ -19,6 +20,7 @@ module AbfWorker
def run def run
create_tasks_for_resign_repositories create_tasks_for_resign_repositories
create_tasks_for_repository_regenerate_metadata
create_tasks_for_build_rpms create_tasks_for_build_rpms
end end
@ -50,6 +52,11 @@ module AbfWorker
redis.lpush RESIGN_REPOSITORIES, key_pair.repository_id redis.lpush RESIGN_REPOSITORIES, key_pair.repository_id
end end
def repository_regenerate_metadata(repository_id)
return false if Resque.redis.lrange(REGENERATE_METADATA, 0, -1).include? repository_id.to_s
redis.lpush REGENERATE_METADATA, repository_id
end
def unlock_repository(repository_id) def unlock_repository(repository_id)
redis.lrem LOCKED_REPOSITORIES, 0, repository_id redis.lrem LOCKED_REPOSITORIES, 0, repository_id
end end
@ -58,8 +65,8 @@ module AbfWorker
redis.lrem LOCKED_BUILD_LISTS, 0, build_list.id redis.lrem LOCKED_BUILD_LISTS, 0, build_list.id
end end
def unlock_rep_and_platform(build_list) def unlock_rep_and_platform(build_list, str = nil)
redis.lrem LOCKED_REP_AND_PLATFORMS, 0, "#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}" redis.lrem LOCKED_REP_AND_PLATFORMS, 0, str || "#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}"
end end
def redis def redis
@ -297,5 +304,49 @@ module AbfWorker
end end
end end
def create_tasks_for_repository_regenerate_metadata
worker_queue = 'publish_worker_default'
worker_class = 'AbfWorker::PublishWorkerDefault'
lock_str = "#{rep.id}-#{rep.platform_id}"
regen_repos = @redis.lrange REGENERATE_METADATA, 0, -1
locked_rep_and_pl = @redis.lrange(LOCKED_REP_AND_PLATFORMS, 0, -1)
Repository.where(:id => regen_repos).each do |rep|
next if locked_rep_and_pl.include?("#{rep.id}-#{rep.platform_id}")
@redis.lrem REGENERATE_METADATA, 0, rep.id
platform_path = "#{rep.platform.path}/repository"
distrib_type = rep.platform.distrib_type
cmd_params = {
'RELEASED' => rep.platform.released,
'REPOSITORY_NAME' => rep.name,
'TYPE' => distrib_type,
'REGENERATE_METADATA' => true
}.map{ |k, v| "#{k}=#{v}" }.join(' ')
options = {
:id => Time.now.to_i,
:arch => 'x86_64',
:distrib_type => distrib_type,
:cmd_params => cmd_params,
:platform => {:platform_path => platform_path},
:repository => {:id => rep.id},
:type => :publish,
:time_living => 9600, # 160 min
:skip_feedback => true,
:extra => {:lock_str => lock_str, :regenerate => true}
}
Resque.push(
worker_queue,
'class' => worker_class,
'args' => [options.merge({
})]
)
@redis.lpush(LOCKED_REP_AND_PLATFORMS, lock_str)
end
return true
end
end end
end end

View File

@ -12,7 +12,9 @@ module AbfWorker
if options['type'] == 'resign' if options['type'] == 'resign'
AbfWorker::BuildListsPublishTaskManager.unlock_repository options['id'] AbfWorker::BuildListsPublishTaskManager.unlock_repository options['id']
else else
if options['extra']['create_container'] # Container has been created if options['extra']['regenerate'] # Regenerate metadata
AbfWorker::BuildListsPublishTaskManager.unlock_rep_and_platform nil, options['extra']['lock_str']
elsif options['extra']['create_container'] # Container has been created
case status case status
when COMPLETED when COMPLETED
subject.published_container subject.published_container