[refs #893] add regenerate metadata for repository
This commit is contained in:
parent
cb87aea416
commit
ac69547805
|
@ -140,6 +140,10 @@ class Platforms::RepositoriesController < Platforms::BaseController
|
|||
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.project_removed')
|
||||
end
|
||||
|
||||
def regenerate_metadata
|
||||
AbfWorker::BuildListsPublishTaskManager.repository_regenerate_metadata @repository
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_members
|
||||
|
|
|
@ -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 => 'Group', :owner_id => user.group_ids}
|
||||
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([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)}
|
||||
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(:cancel, MassBuild) {|mass_build| mass_build.platform.personal? || mass_build.stop_build}
|
||||
|
||||
cannot(:regenerate_metadata, Repository) {|repository| !repository.platform.main?}
|
||||
|
||||
if @user.system?
|
||||
can :key_pair, Repository
|
||||
else
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
class Repository < ActiveRecord::Base
|
||||
belongs_to :platform
|
||||
|
||||
|
||||
has_many :relations, :as => :target, :dependent => :destroy
|
||||
has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy
|
||||
has_many :members, :through => :actors, :source => :actor, :source_type => 'User'
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
- unless ['edit', 'update'].include? controller.action_name
|
||||
.leftlist= f.label :name, t("activerecord.attributes.repository.name"), :class => :label
|
||||
.rightlist= f.text_field :name, :class => 'text_field'
|
||||
- else
|
||||
= link_to t("layout.repositories.regenerate_metadata"), regenerate_metadata_platform_repository_path(@platform, @repository), :method => :put, :confirm => t('layout.confirm')
|
||||
%br
|
||||
|
||||
.leftlist= f.label :description, t("activerecord.attributes.repository.description"), :class => :label
|
||||
.rightlist= f.text_field :description, :class => 'text_field'
|
||||
|
|
|
@ -18,6 +18,7 @@ en:
|
|||
clear: Clear
|
||||
clear_confirm: Are you sure you want to clear this platform?
|
||||
clear_warning: Attention! Cleared packages cannot be restored!
|
||||
regenerate_metadata: Regenerate metadata
|
||||
|
||||
personal_repositories:
|
||||
settings_header: Settings
|
||||
|
|
|
@ -18,6 +18,7 @@ ru:
|
|||
clear: Очистить
|
||||
clear_confirm: Уверены, что хотите очистить платформу?
|
||||
clear_warning: Внимание! Очищенные пакеты не могут быть восстановлены!
|
||||
regenerate_metadata: Регенерировать метаданные
|
||||
|
||||
personal_repositories:
|
||||
settings_header: Настройки
|
||||
|
|
|
@ -151,6 +151,7 @@ Rosa::Application.routes.draw do
|
|||
post :remove_members # fixme: change post to delete
|
||||
delete :remove_member
|
||||
post :add_member
|
||||
put :regenerate_metadata
|
||||
end
|
||||
end
|
||||
resources :key_pairs, :only => [:create, :index, :destroy]
|
||||
|
|
|
@ -8,7 +8,8 @@ module AbfWorker
|
|||
LOCKED_PROJECTS_FOR_CLEANUP
|
||||
LOCKED_REPOSITORIES
|
||||
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('_', '-')}"
|
||||
end
|
||||
|
||||
|
@ -20,6 +21,7 @@ module AbfWorker
|
|||
def run
|
||||
create_tasks_for_resign_repositories
|
||||
create_tasks_for_build_rpms
|
||||
create_tasks_for_repository_regenerate_metadata
|
||||
end
|
||||
|
||||
class << self
|
||||
|
@ -50,6 +52,10 @@ module AbfWorker
|
|||
redis.lpush RESIGN_REPOSITORIES, key_pair.repository_id
|
||||
end
|
||||
|
||||
def repository_regenerate_metadata(repository_id)
|
||||
redis.lpush REGENERATE_METADATA, repository_id
|
||||
end
|
||||
|
||||
def unlock_repository(repository_id)
|
||||
redis.lrem LOCKED_REPOSITORIES, 0, repository_id
|
||||
end
|
||||
|
@ -58,8 +64,8 @@ module AbfWorker
|
|||
redis.lrem LOCKED_BUILD_LISTS, 0, build_list.id
|
||||
end
|
||||
|
||||
def unlock_rep_and_platform(build_list)
|
||||
redis.lrem LOCKED_REP_AND_PLATFORMS, 0, "#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}"
|
||||
def unlock_rep_and_platform(build_list, str = nil)
|
||||
redis.lrem LOCKED_REP_AND_PLATFORMS, 0, str || "#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}"
|
||||
end
|
||||
|
||||
def redis
|
||||
|
@ -291,5 +297,48 @@ module AbfWorker
|
|||
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 => nil,
|
||||
:distrib_type => distrib_type,
|
||||
:cmd_params => cmd_params,
|
||||
:platform => {:platform_path => platform_path},
|
||||
:repository => {:id => rep.id},
|
||||
:type => :regenerate,
|
||||
:time_living => 9600, # 160 min
|
||||
:lock_str => lock_str
|
||||
}
|
||||
|
||||
Resque.push(
|
||||
worker_queue,
|
||||
'class' => worker_class,
|
||||
'args' => [options.merge({
|
||||
})]
|
||||
)
|
||||
|
||||
@redis.lpush(LOCKED_REP_AND_PLATFORMS, lock_str)
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,8 +9,11 @@ module AbfWorker
|
|||
|
||||
def perform
|
||||
return if status == STARTED # do nothing when publication started
|
||||
if options['type'] == 'resign'
|
||||
AbfWorker::BuildListsPublishTaskManager.unlock_repository options['id']
|
||||
case options['type']
|
||||
when 'resign'
|
||||
AbfWorker::BuildListsPublishTaskManager.unlock_repository options['id']
|
||||
when 'regenerate'
|
||||
AbfWorker::BuildListsPublishTaskManager.unlock_rep_and_platform nil, options['lock_str']
|
||||
else
|
||||
if options['extra']['create_container'] # Container has been created
|
||||
case status
|
||||
|
|
Loading…
Reference in New Issue