diff --git a/app/assets/javascripts/angularjs/locales.js.erb b/app/assets/javascripts/angularjs/locales.js.erb index 5d5901301..fdd2c2d0c 100644 --- a/app/assets/javascripts/angularjs/locales.js.erb +++ b/app/assets/javascripts/angularjs/locales.js.erb @@ -11,7 +11,7 @@ var _locales = { 'Всего %1 тега', 'Всего %1 тегов' ], - <%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}':'#{BuildList.human_status(s)}'"}.join(',') %> + <%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %> }, <%I18n.locale = :en%> 'en-us': { @@ -23,6 +23,6 @@ var _locales = { 'Total %1 tag', 'Total %1 tags' ], - <%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}':'#{BuildList.human_status(s)}'"}.join(',') %> + <%= BuildList::STATUSES.map{|s| "'build_list.status.#{s}': '#{BuildList.human_status(s)}'"}.join(',') %> } }; \ No newline at end of file diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index 7b09b838d..0b10f801d 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -16,11 +16,6 @@ class Api::V1::JobsController < Api::V1::BaseController if current_user.system? if task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker')) @build_list = BuildList.where(:id => task['args'][0]['id']).first - # Temporally - if @build_list.build_for_platform.name == 'red3' - @build_list.restart_job - @build_list = nil - end end end diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index f45646057..171229ff3 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -21,10 +21,7 @@ class Platforms::RepositoriesController < Platforms::BaseController end def update - if @repository.update_attributes( - :description => params[:repository][:description], - :publish_without_qa => (params[:repository][:publish_without_qa] || @repository.publish_without_qa) - ) + if @repository.update_attributes params[:repository].slice(:description, :synchronizing_publications).merge(:publish_without_qa => (params[:repository][:publish_without_qa] || @repository.publish_without_qa)) flash[:notice] = I18n.t("flash.repository.updated") redirect_to platform_repository_path(@platform, @repository) else diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 5e9f0abc9..95f1b00e6 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -33,7 +33,7 @@ class Projects::BuildListsController < Projects::BaseController :build_for_platform, :user, :source_packages, - :project + :project => :project_statistics ) @build_server_status = AbfWorker::StatusInspector.projects_status diff --git a/app/models/ability.rb b/app/models/ability.rb index 16156b7d6..f2f4ca4a7 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -63,7 +63,7 @@ class Ability can([:mass_import, :run_mass_import], Project) if user.platforms.main.find{ |p| local_admin?(p) }.present? can :read, Project, :visibility => 'open' can [:read, :archive, :membered, :get_id], Project, :owner_type => 'User', :owner_id => user.id - can [:read, :archive, :membered, :get_id], Project, :owner_type => 'Group', :owner_id => user.group_ids + can [:read, :archive, :membered, :get_id], Project, :owner_type => 'Group', :owner_id => user_group_ids can([:read, :archive, :membered, :get_id], Project, read_relations_for('projects')) {|project| local_reader? project} can(:write, Project) {|project| local_writer? project} # for grack can [:update, :sections, :manage_collaborators, :autocomplete_maintainers, :add_member, :remove_member, :update_member, :members], Project do |project| @@ -80,7 +80,7 @@ class Ability can [:read, :log, :owned, :everything], BuildList, :user_id => user.id can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} - can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids} + can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user_group_ids} can([:read, :log, :everything, :list], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project} can(:publish_into_testing, BuildList) { |build_list| can?(:create, build_list) && build_list.save_to_platform.main? } @@ -108,7 +108,7 @@ class Ability can([:cancel, :create_container], BuildList) {|build_list| can?(:write, build_list.project)} can [:read, :owned, :related, :members], Platform, :owner_type => 'User', :owner_id => user.id - can [:read, :related, :members], Platform, :owner_type => 'Group', :owner_id => user.group_ids + can [:read, :related, :members], Platform, :owner_type => 'Group', :owner_id => user_group_ids can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform} can [:read, :related], Platform, :id => user.repositories.pluck(:platform_id) can([:update, :destroy, :change_visibility], Platform) {|platform| owner?(platform) } @@ -118,7 +118,7 @@ class Ability can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)) && !mass_build.stop_build} 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')) {|repository| can? :show, 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, :regenerate_metadata, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository) {|repository| local_admin? repository.platform} @@ -133,7 +133,7 @@ class Ability can([:read, :create, :withdraw], Token) {|token| local_admin?(token.subject)} can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id, :platform_type => 'main'} - can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids, :platform_type => 'main'} + can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user_group_ids, :platform_type => 'main'} can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.main?} can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.main?} @@ -141,17 +141,17 @@ class Ability can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)} can [:read, :create], PrivateUser, :platform => {:owner_type => 'User', :owner_id => user.id} - can [:read, :create], PrivateUser, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} + can [:read, :create], PrivateUser, :platform => {:owner_type => 'Group', :owner_id => user_group_ids} can :read, Issue, :project => {:owner_type => 'User', :owner_id => user.id} - can :read, Issue, :project => {:owner_type => 'Group', :owner_id => user.group_ids} + can :read, Issue, :project => {:owner_type => 'Group', :owner_id => user_group_ids} can(:read, Issue, read_relations_for('issues', 'projects')) {|issue| can? :read, issue.project rescue nil} can(:create, Issue) {|issue| can? :read, issue.project} can(:update, Issue) {|issue| issue.user_id == user.id or local_admin?(issue.project)} cannot :manage, Issue, :project => {:has_issues => false} # switch off issues can [:read, :commits, :files], PullRequest, :to_project => {:owner_type => 'User', :owner_id => user.id} - can [:read, :commits, :files], PullRequest, :to_project => {:owner_type => 'Group', :owner_id => user.group_ids} + can [:read, :commits, :files], PullRequest, :to_project => {:owner_type => 'Group', :owner_id => user_group_ids} can([:read, :commits, :files], PullRequest, read_relations_for('pull_requests', 'to_projects')) {|pull| can? :read, pull.to_project} can :create, PullRequest can(:update, PullRequest) {|pull| pull.user_id == user.id or local_admin?(pull.to_project)} @@ -230,7 +230,7 @@ class Ability ["#{table}.#{key} IN ( SELECT target_id FROM relations WHERE relations.target_type = ? AND (relations.actor_type = 'User' AND relations.actor_id = ? OR - relations.actor_type = 'Group' AND relations.actor_id IN (?)))", parent.classify, @user, @user.group_ids] + relations.actor_type = 'Group' AND relations.actor_id IN (?)))", parent.classify, @user, user_group_ids] end def local_reader?(target) @@ -246,6 +246,15 @@ class Ability end def owner?(target) - target.owner == @user or @user.own_groups.include?(target.owner) + target.owner == @user or user_own_groups.include?(target.owner) end + + def user_own_groups + @user_own_groups ||= @user.own_groups + end + + def user_group_ids + @user_group_ids ||= @user.group_ids + end + end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 0ec8933ff..28969f3ed 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -157,6 +157,11 @@ class BuildList < ActiveRecord::Base after_transition :on => :published, :do => [:set_version_and_tag, :actualize_packages] after_transition :on => :publish, :do => :set_publisher + after_transition(:on => :publish) do |build_list, transition| + if transition.from == BUILD_PUBLISHED_INTO_TESTING + build_list.cleanup_packages_from_testing + end + end after_transition :on => :cancel, :do => :cancel_job after_transition :on => [:published, :fail_publish, :build_error, :tests_failed], :do => :notify_users @@ -307,6 +312,27 @@ class BuildList < ActiveRecord::Base [SUCCESS, BUILD_PUBLISH, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && [WAITING_FOR_RESPONSE, FAILED_PUBLISH].include?(container_status) end + def can_publish_into_repository? + return true if !save_to_repository.synchronizing_publications? || save_to_platform.personal? || project.architecture_dependent? + arch_ids = save_to_platform.platform_arch_settings.by_default.pluck(:arch_id) + BuildList.where( + :project_id => project_id, + :save_to_repository_id => save_to_repository_id, + :arch_id => arch_ids, + :commit_hash => commit_hash, + :status => [ + SUCCESS, + BUILD_PUBLISHED, + BUILD_PUBLISH, + FAILED_PUBLISH, + TESTS_FAILED, + BUILD_PUBLISHED_INTO_TESTING, + BUILD_PUBLISH_INTO_TESTING, + FAILED_PUBLISH_INTO_TESTING + ] + ).group(:arch_id).count == arch_ids.size + end + #TODO: Share this checking on product owner. def can_cancel? build_started? || build_pending? @@ -333,7 +359,7 @@ class BuildList < ActiveRecord::Base end def can_auto_publish? - auto_publish? && can_publish? && has_new_packages? + auto_publish? && can_publish? && has_new_packages? && can_publish_into_repository? end def can_publish? @@ -356,7 +382,8 @@ class BuildList < ActiveRecord::Base def average_build_time return 0 unless project - project.project_statistics.where(:arch_id => arch_id).pluck(:average_build_time).first || 0 + @average_build_time ||= project.project_statistics. + find{ |ps| ps.arch_id == arch_id }.try(:average_build_time) || 0 end def self.human_status(status) @@ -487,6 +514,14 @@ class BuildList < ActiveRecord::Base } end + def cleanup_packages_from_testing + AbfWorker::BuildListsPublishTaskManager.cleanup_packages_from_testing( + build_for_platform_id, + save_to_repository_id, + id + ) + end + protected def create_container diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index 1515e5106..ff29c772a 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -44,9 +44,11 @@ class MassBuild < ActiveRecord::Base if project = Project.joins(:repositories).where('repositories.id in (?)', save_to_platform.repository_ids).find_by_name(name) begin return if self.reload.stop_build + increase_rt = increase_release_tag? arches_list.each do |arch| rep_id = (project.repository_ids & save_to_platform.repository_ids).first - project.build_for self, rep_id, arch + project.build_for self, rep_id, arch, 0, increase_rt + increase_rt = false end rescue RuntimeError, Exception end diff --git a/app/models/project.rb b/app/models/project.rb index 9bf614d09..f60746b9d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -47,7 +47,7 @@ class Project < ActiveRecord::Base attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch, :has_issues, :has_wiki, :maintainer_id, :publish_i686_into_x86_64, - :url, :srpms_list, :mass_import, :add_to_repository_id + :url, :srpms_list, :mass_import, :add_to_repository_id, :architecture_dependent attr_readonly :owner_id, :owner_type scope :recent, order("lower(#{table_name}.name) ASC") @@ -161,7 +161,7 @@ class Project < ActiveRecord::Base #path #share by NFS end - def build_for(mass_build, repository_id, arch = Arch.find_by_name('i586'), priority = 0) + def build_for(mass_build, repository_id, arch = Arch.find_by_name('i586'), priority = 0, increase_rt = false) build_for_platform = mass_build.build_for_platform save_to_platform = mass_build.save_to_platform user = mass_build.user @@ -179,7 +179,7 @@ class Project < ActiveRecord::Base default_branch end - increase_release_tag(project_version, user, "MassBuild##{mass_build.id}: Increase release tag") if mass_build.increase_release_tag? + increase_release_tag(project_version, user, "MassBuild##{mass_build.id}: Increase release tag") if increase_rt build_list = build_lists.build do |bl| bl.save_to_platform = save_to_platform diff --git a/app/models/repository.rb b/app/models/repository.rb index 62e6c6092..667988ede 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -25,7 +25,7 @@ class Repository < ActiveRecord::Base before_destroy :detele_directory - attr_accessible :name, :description, :publish_without_qa + attr_accessible :name, :description, :publish_without_qa, :synchronizing_publications attr_readonly :name, :platform_id attr_accessor :projects_list diff --git a/app/views/platforms/repositories/_form.html.haml b/app/views/platforms/repositories/_form.html.haml index 0e430665c..3ae96c914 100644 --- a/app/views/platforms/repositories/_form.html.haml +++ b/app/views/platforms/repositories/_form.html.haml @@ -7,6 +7,10 @@ .leftlist= f.label :publish_without_qa, t("activerecord.attributes.repository.publish_without_qa"), :class => :label .rightlist= f.check_box :publish_without_qa, :class => 'check_box' + +.leftlist= f.label :synchronizing_publications +.rightlist= f.check_box :synchronizing_publications + .both .hr diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index 5cbc139ab..d81448ccd 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -160,6 +160,10 @@ .flash_notify .alert.alert-error= t('layout.build_lists.publish_with_extra_fail') .both + %div{'ng-show' => 'build_list.can_publish && build_list.can_publish_in_future && !build_list.can_publish_into_repository'} + .flash_notify + .alert.alert-error= t('flash.build_list.not_all_build_lists_success') + .both - if can?(:cancel, @build_list) = link_to t("layout.build_lists.cancel"), cancel_build_list_path(@build_list), diff --git a/app/views/projects/build_lists/show.json.jbuilder b/app/views/projects/build_lists/show.json.jbuilder index 4a9b46b16..03a1a6d98 100644 --- a/app/views/projects/build_lists/show.json.jbuilder +++ b/app/views/projects/build_lists/show.json.jbuilder @@ -18,6 +18,7 @@ json.build_list do json.extra_build_lists_published @build_list.extra_build_lists_published? json.can_publish_in_future can_publish_in_future?(@build_list) + json.can_publish_into_repository @build_list.can_publish_into_repository? json.container_path container_url if @build_list.container_published? diff --git a/app/views/projects/projects/_form.html.haml b/app/views/projects/projects/_form.html.haml index 04b3f4cb9..af92b3e1b 100644 --- a/app/views/projects/projects/_form.html.haml +++ b/app/views/projects/projects/_form.html.haml @@ -25,6 +25,10 @@ .check= f.check_box :is_package, 'ng-model' => 'project.is_package', 'ng-change' => 'project.publish_i686_into_x86_64 = false' .forcheck= f.label :is_package .both + %div{'ng-show' => 'project.is_package'} + .check= f.check_box :architecture_dependent, 'ng-model' => 'project.architecture_dependent' + .forcheck= f.label :architecture_dependent + .both - unless [:new, :create].include? act #publish_form{'ng-show' => 'project.is_package'} .check= f.check_box :publish_i686_into_x86_64, 'ng-model' => 'project.publish_i686_into_x86_64' diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index 8abaa2253..376ef745d 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -193,4 +193,5 @@ en: can_not_published: Build can only be published with status "Build complete" frozen_platform: In case of a repository for package storage with frozen platform allowed only bugfix and security updates wrong_include_repos: Include repos have to belongs to build for platform - wrong_commit_hash: Unable find commit '%{commit_hash}' in project + wrong_commit_hash: "Unable find commit '%{commit_hash}' in project" + not_all_build_lists_success: 'Project has been builded successfully not for all default arches' diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 1e4a2cc5e..308224f62 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -180,10 +180,10 @@ ru: flash: build_list: - saved: Билд лист для версии '%{project_version}', платформы '%{build_for_platform}' и архитектуры '%{arch}' создан успешно - save_error: Не удалось сохранить билд лист для версии '%{project_version}', платформы '%{build_for_platform}' и архитектуры '%{arch}' + saved: "Билд лист для версии '%{project_version}', платформы '%{build_for_platform}' и архитектуры '%{arch}' создан успешно" + save_error: "Не удалось сохранить билд лист для версии '%{project_version}', платформы '%{build_for_platform}' и архитектуры '%{arch}'" no_project_version_selected: Выберите какую-нибудь версию - no_project_version_found: Выбранная версия '%{project_version}' не найдена + no_project_version_found: "Выбранная версия '%{project_version}' не найдена" no_arch_or_platform_selected: Выберите хотя бы одну архитектуру и платформу wrong_platform: Для основного репозитория (main) может быть выбран только его же основная платформа! wrong_build_for_platform: Тип платформы "build_for_platform" должен быть "main" @@ -193,4 +193,5 @@ ru: can_not_published: Опубликовать сборку можно только со статусом "Собран" frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления wrong_include_repos: Включаемые репозитории должны принадлежать платформе для сборки - wrong_commit_hash: Невозможно найти коммит '%{commit_hash}' в проекте + wrong_commit_hash: "Невозможно найти коммит '%{commit_hash}' в проекте" + not_all_build_lists_success: Проект собран успешно не для всех дефолтных архитектур diff --git a/config/locales/models/project.en.yml b/config/locales/models/project.en.yml index 586f0c5fb..fceb6f333 100644 --- a/config/locales/models/project.en.yml +++ b/config/locales/models/project.en.yml @@ -116,6 +116,7 @@ en: publish_i686_into_x86_64: Publish i686 packages into x86_64 repository (only for rhel) maintainer: Maintainer of project maintainer_id: Maintainer of project + architecture_dependent: Architecture-dependent errors: project: uname: The name can only use lower case Latin letters (a-z), numbers (0-9) and underscore (_) diff --git a/config/locales/models/project.ru.yml b/config/locales/models/project.ru.yml index 12821d64c..fae79540c 100644 --- a/config/locales/models/project.ru.yml +++ b/config/locales/models/project.ru.yml @@ -116,6 +116,7 @@ ru: publish_i686_into_x86_64: Публиковать i686 пакеты в x86_64 репозиторий (только для rhel) maintainer_id: Майнтейнер проекта maintainer: Майнтейнер проекта + architecture_dependent: Архитектурно-зависимый errors: project: uname: В имени можно использовать только строчные символы латинского алфавита (a-z), цифры (0-9) и символ нижнего подчеркивания (_) diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index a431aea3d..98a444abd 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -70,3 +70,4 @@ en: created_at: Created updated_at: Updated owner: Owner + synchronizing_publications: Publish only on success all build_lists for each arch (checking by commit hash) diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 9474f1ffb..38e61a860 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -70,3 +70,4 @@ ru: created_at: Создан updated_at: Обновлен owner: Владелец + synchronizing_publications: Публиковать сборочные листы только при успешной сборке под каждую архитектуру (проверка по хэшу коммита) diff --git a/db/migrate/20140113205657_add_synchronize_publication_to_repository.rb b/db/migrate/20140113205657_add_synchronize_publication_to_repository.rb new file mode 100644 index 000000000..ddf57995f --- /dev/null +++ b/db/migrate/20140113205657_add_synchronize_publication_to_repository.rb @@ -0,0 +1,5 @@ +class AddSynchronizePublicationToRepository < ActiveRecord::Migration + def change + add_column :repositories, :synchronizing_publications, :boolean, :default => false, :null => false + end +end diff --git a/db/migrate/20140113215223_add_architecture_dependent_to_project.rb b/db/migrate/20140113215223_add_architecture_dependent_to_project.rb new file mode 100644 index 000000000..b1fd34e95 --- /dev/null +++ b/db/migrate/20140113215223_add_architecture_dependent_to_project.rb @@ -0,0 +1,5 @@ +class AddArchitectureDependentToProject < ActiveRecord::Migration + def change + add_column :projects, :architecture_dependent, :boolean, :default => false, :null => false + end +end diff --git a/db/schema.rb b/db/schema.rb index f90c5de5a..eee0323ca 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131126154305) do +ActiveRecord::Schema.define(:version => 20140113215223) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -439,6 +439,7 @@ ActiveRecord::Schema.define(:version => 20131126154305) do t.integer "maintainer_id" t.boolean "publish_i686_into_x86_64", :default => false t.string "owner_uname", :null => false + t.boolean "architecture_dependent", :default => false, :null => false end add_index "projects", ["owner_id", "name", "owner_type"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false @@ -487,12 +488,13 @@ ActiveRecord::Schema.define(:version => 20131126154305) do add_index "relations", ["target_type", "target_id"], :name => "index_relations_on_target_type_and_target_id" create_table "repositories", :force => true do |t| - t.string "description", :null => false - t.integer "platform_id", :null => false + t.string "description", :null => false + t.integer "platform_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "name", :null => false - t.boolean "publish_without_qa", :default => true + t.string "name", :null => false + t.boolean "publish_without_qa", :default => true + t.boolean "synchronizing_publications", :default => false, :null => false end add_index "repositories", ["platform_id"], :name => "index_repositories_on_platform_id" diff --git a/lib/abf_worker/build_lists_publish_task_manager.rb b/lib/abf_worker/build_lists_publish_task_manager.rb index ec8f57ed6..08cdd8636 100644 --- a/lib/abf_worker/build_lists_publish_task_manager.rb +++ b/lib/abf_worker/build_lists_publish_task_manager.rb @@ -5,7 +5,9 @@ module AbfWorker %w(PROJECTS_FOR_CLEANUP LOCKED_PROJECTS_FOR_CLEANUP LOCKED_BUILD_LISTS - PACKAGES_FOR_CLEANUP).each do |kind| + PACKAGES_FOR_CLEANUP + REP_AND_PLS_OF_BUILD_LISTS_FOR_CLEANUP_FROM_TESTING + BUILD_LISTS_FOR_CLEANUP_FROM_TESTING).each do |kind| const_set kind, "#{REDIS_MAIN_KEY}#{kind.downcase.gsub('_', '-')}" end @@ -57,6 +59,14 @@ module AbfWorker end end + def cleanup_packages_from_testing(platform_id, repository_id, *build_lists) + return if build_lists.blank? + rep_pl = "#{repository_id}-#{platform_id}" + key = "#{BUILD_LISTS_FOR_CLEANUP_FROM_TESTING}-#{rep_pl}" + redis.sadd REP_AND_PLS_OF_BUILD_LISTS_FOR_CLEANUP_FROM_TESTING, rep_pl + redis.sadd key, build_lists + end + def unlock_build_list(build_list) redis.lrem LOCKED_BUILD_LISTS, 0, build_list.id end @@ -212,8 +222,15 @@ module AbfWorker locked_rep.present? && locked_rep.include?(rep.to_i) ? nil : [rep.to_i, pl.to_i] end.compact + for_cleanup_from_testing = @redis.smembers(REP_AND_PLS_OF_BUILD_LISTS_FOR_CLEANUP_FROM_TESTING).map do |key| + next if @redis.scard("#{BUILD_LISTS_FOR_CLEANUP_FROM_TESTING}-#{key}") == 0 + rep, pl = *key.split('-') + locked_rep.present? && locked_rep.include?(rep.to_i) ? nil : [rep.to_i, pl.to_i] + end.compact if testing + for_cleanup_from_testing ||= [] + counter = 1 - available_repos = available_repos.map{ |bl| [bl.save_to_repository_id, bl.build_for_platform_id] } | for_cleanup + available_repos = available_repos.map{ |bl| [bl.save_to_repository_id, bl.build_for_platform_id] } | for_cleanup | for_cleanup_from_testing available_repos.each do |save_to_repository_id, build_for_platform_id| next if RepositoryStatus.not_ready.where(:repository_id => save_to_repository_id, :platform_id => build_for_platform_id).exists? break if counter > @workers_count @@ -253,12 +270,20 @@ module AbfWorker packages = JSON.parse packages old_packages[:sources] |= packages['sources'] Arch.pluck(:name).each do |arch| - old_packages[:binaries][arch.to_sym] |= packages['binaries'][arch] + old_packages[:binaries][arch.to_sym] |= packages['binaries'][arch] || [] end end + if testing + build_lists_for_cleanup_from_testing = @redis.smembers("#{BUILD_LISTS_FOR_CLEANUP_FROM_TESTING}-#{save_to_repository_id}-#{build_for_platform_id}") + BuildList.where(:id => build_lists_for_cleanup_from_testing).each do |b| + self.class.fill_packages(b, old_packages, :fullname) + end if build_lists_for_cleanup_from_testing.present? + end + build_lists_for_cleanup_from_testing ||= [] + bl = build_lists.first - return false if !bl && old_packages[:sources].empty? + return false if !bl && old_packages[:sources].empty? && old_packages[:binaries].values.flatten.empty? save_to_repository = Repository.find save_to_repository_id # Checks mirror sync status @@ -300,7 +325,10 @@ module AbfWorker }, :repository => {:id => save_to_repository_id}, :time_living => 9600, # 160 min - :extra => {:repository_status_id => repository_status.id} + :extra => { + :repository_status_id => repository_status.id, + :build_lists_for_cleanup_from_testing => build_lists_for_cleanup_from_testing + } } packages, build_list_ids, new_sources = self.class.packages_structure, [], {} @@ -336,6 +364,15 @@ module AbfWorker @redis.lpush LOCKED_PROJECTS_FOR_CLEANUP, key end + rep_pl = "#{save_to_repository_id}-#{build_for_platform_id}" + r_key = "#{BUILD_LISTS_FOR_CLEANUP_FROM_TESTING}-#{rep_pl}" + build_lists_for_cleanup_from_testing.each do |key| + @redis.srem r_key, key + end + if @redis.scard(r_key) == 0 + @redis.srem REP_AND_PLS_OF_BUILD_LISTS_FOR_CLEANUP_FROM_TESTING, rep_pl + end + return true end diff --git a/lib/abf_worker/publish_observer.rb b/lib/abf_worker/publish_observer.rb index 7ad128c9a..f12d9e7f1 100644 --- a/lib/abf_worker/publish_observer.rb +++ b/lib/abf_worker/publish_observer.rb @@ -37,6 +37,14 @@ module AbfWorker end update_results elsif !extra['resign'] # Simple publish + bls = extra['build_lists_for_cleanup_from_testing'] + if status != COMPLETED && bls.present? + AbfWorker::BuildListsPublishTaskManager.cleanup_packages_from_testing( + repository_status.platform_id, + repository_status.repository_id, + bls + ) + end update_rpm_builds end ensure