#860: update logic for creating build list container

This commit is contained in:
Vokhmin Alexey V 2013-01-28 18:44:06 +04:00
parent 01108360c9
commit fed1c76ca2
9 changed files with 88 additions and 41 deletions

View File

@ -90,7 +90,7 @@ class Projects::BuildListsController < Projects::BaseController
end
def create_container
AbfWorker::BuildListsPublishTaskManager.create_container_for @build_list
@build_list.publish_container
redirect_to :back, :notice => t('layout.build_lists.container_will_be_created')
end

View File

@ -77,11 +77,7 @@ module BuildListsHelper
end
def container_url
"http://#{request.host_with_port}/downloads#{@build_list.container_path}".html_safe
end
def build_list_log_url(log_type)
"http://#{request.host_with_port}/#{@build_list.fs_log_path(log_type)}".html_safe
"http://#{request.host_with_port}/downloads/#{@build_list.save_to_platform.name}/container/#{@build_list.id}".html_safe
end
def log_reload_time_options

View File

@ -123,12 +123,8 @@ class BuildList < ActiveRecord::Base
serialize :include_repos
serialize :results, Array
after_commit :place_build
after_destroy lambda {
if save_to_platform
system "rm -rf #{save_to_platform.path}/container/#{id}"
end
}
after_commit :place_build
after_destroy :remove_container
state_machine :status, :initial => :waiting_for_response do
@ -147,7 +143,9 @@ class BuildList < ActiveRecord::Base
end
end
after_transition :on => :published, :do => [:set_version_and_tag, :actualize_packages]
after_transition :on => :published,
:do => [:set_version_and_tag, :actualize_packages, :destroy_container]
after_transition :on => :reject_publish, :do => :destroy_container
after_transition :on => :cancel, :do => :cancel_job
after_transition :on => [:published, :fail_publish, :build_error], :do => :notify_users
@ -211,6 +209,40 @@ class BuildList < ActiveRecord::Base
later :publish, :queue => :clone_build
HUMAN_CONTAINER_STATUSES = { WAITING_FOR_RESPONSE => :waiting_for_publish,
BUILD_PUBLISHED => :container_published,
BUILD_PUBLISH => :container_publish,
FAILED_PUBLISH => :container_failed_publish
}
state_machine :container_status, :initial => :waiting_for_publish do
after_transition :on => :publish_container, :do => :create_container
after_transition :on => [:fail_publish_container, :destroy_container],
:do => :remove_container
event :publish_container do
transition [:waiting_for_publish, :container_failed_publish] => :container_publish
end
event :published_container do
transition :container_publish => :container_published
end
event :fail_publish_container do
transition :container_publish => :container_failed_publish
end
event :destroy_container do
transition [:container_failed_publish, :container_published] => :waiting_for_publish
end
HUMAN_CONTAINER_STATUSES.each do |code,name|
state name, :value => code
end
end
def set_version_and_tag
pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first
# TODO: remove 'return' after deployment ABF kernel 2.0
@ -228,6 +260,10 @@ class BuildList < ActiveRecord::Base
end
end
def can_create_container?
success? && [WAITING_FOR_RESPONSE, FAILED_PUBLISH].include?(container_status)
end
#TODO: Share this checking on product owner.
def can_cancel?
build_started? || build_pending?
@ -296,10 +332,6 @@ class BuildList < ActiveRecord::Base
I18n.t("layout.build_lists.human_duration", {:hours => (duration/3600).to_i, :minutes => (duration%3600/60).to_i})
end
def fs_log_path(log_type = :build)
container_path? ? "downloads/#{container_path}/log/#{project.name}/#{log_type.to_s}.log" : nil
end
def in_work?
status == BUILD_STARTED
#[WAITING_FOR_RESPONSE, BUILD_PENDING, BUILD_STARTED].include?(status)
@ -318,12 +350,7 @@ class BuildList < ActiveRecord::Base
end
def log(load_lines)
if new_core?
abf_worker_log
else
log = `tail -n #{load_lines.to_i} #{Rails.root + 'public' + fs_log_path}`
$?.success? ? log : I18n.t('layout.build_lists.log.not_available')
end
new_core? ? abf_worker_log : I18n.t('layout.build_lists.log.not_available')
end
def last_published
@ -337,6 +364,14 @@ class BuildList < ActiveRecord::Base
protected
def create_container
AbfWorker::BuildListsPublishTaskManager.create_container_for self
end
def remove_container
system "rm -rf #{save_to_platform.path}/container/#{id}" if save_to_platform
end
def abf_worker_priority
mass_build_id ? '' : 'default'
end

View File

@ -8,13 +8,13 @@
%h3= t("layout.build_lists.main_data")
.leftlist= t("activerecord.attributes.build_list.container_path")
.rightlist
- if @build_list.status == BuildList::BUILD_PUBLISHED
- if @build_list.build_published?
= raw "%s %s" % [t("layout.build_lists.container_published"),
link_to("#{@build_list.save_to_platform.name}/#{@build_list.save_to_repository.name}",
[@build_list.save_to_platform, @build_list.save_to_repository])]
- elsif @build_list.container_path.present?
- elsif @build_list.container_published?
= link_to container_url, container_url
- elsif @build_list.container_path == ''
- elsif @build_list.container_publish?
= t("layout.build_lists.creating")
.both
@ -91,9 +91,6 @@
- if @build_list.can_cancel? && can?(:cancel, @build_list)
= link_to t("layout.build_lists.cancel"), cancel_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button'
- if @build_list.success? && can?(:create_container, @build_list)
= link_to t("layout.build_lists.create_container"), create_container_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button'
- if @build_list.can_publish? && @build_list.save_to_platform.released && @build_list.advisory.nil? && can?(:publish, @build_list)
#advisory_block
@ -133,15 +130,17 @@
var r = new Rosa.Routers.BuildListsAdvisoriesRouter();
});
- if BuildList::HUMAN_STATUSES[@build_list.status].in?([:build_started, :build_error, :success]) && (!@build_list.new_core? || @build_list.build_started?)
- log_params = { :build_started => @build_list.build_started?, :get_log_path => log_build_list_path(@build_list) }
= render 'shared/log', ( @build_list.new_core? ? log_params : log_params.merge({:download_log_url => build_list_log_url(:build)}) )
- if @build_list.build_started?
= render 'shared/log', { :build_started => true, :get_log_path => log_build_list_path(@build_list) }
- if (can_publish = @build_list.can_publish? && can?(:publish, @build_list))
.hr
= submit_tag t("layout.publish"), :confirm => t("layout.confirm"), :name => 'publish' if can_publish
- if @build_list.can_reject_publish? && can?(:reject_publish, @build_list)
= submit_tag t("layout.reject_publish"), :confirm => t("layout.confirm"), :name => 'reject_publish'
- if @build_list.can_create_container? && can?(:create_container, @build_list)
= link_to t("layout.build_lists.create_container"), create_container_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button'
.hr
%h3= t("layout.build_lists.items_header")

View File

@ -0,0 +1,11 @@
class AddContainerStatusToBuildList < ActiveRecord::Migration
def up
add_column :build_lists, :container_status, :integer
remove_column :build_lists, :container_path
end
def down
remove_column :build_lists, :container_status
add_column :build_lists, :container_path, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130119125710) do
ActiveRecord::Schema.define(:version => 20130128123151) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -105,7 +105,6 @@ ActiveRecord::Schema.define(:version => 20130119125710) do
create_table "build_lists", :force => true do |t|
t.integer "bs_id"
t.string "container_path"
t.integer "status"
t.string "project_version"
t.integer "project_id"
@ -133,6 +132,7 @@ ActiveRecord::Schema.define(:version => 20130119125710) do
t.text "results"
t.boolean "new_core", :default => true
t.string "last_published_commit_hash"
t.integer "container_status"
end
add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"

View File

@ -68,10 +68,8 @@ module AbfWorker
def create_container_for(build_list)
platform_path = "#{build_list.save_to_platform.path}/container/#{build_list.id}"
return if File.directory?(platform_path)
system "rm -rf #{platform_path}"
system "mkdir -p #{platform_path}"
build_list.update_column(:container_path, '')
packages = {:sources => [], :binaries => {:x86_64 => [], :i586 => []}}
packages[:sources] = build_list.packages.by_package_type('source').pluck(:sha1).compact

View File

@ -11,7 +11,12 @@ module AbfWorker
else
if options['extra']['create_container'] # Container has been created
bl = BuildList.find(options['id'])
bl.update_column(:container_path, "/#{bl.save_to_platform.name}/container/#{bl.id}")
case status
when COMPLETED
bl.published_container
when FAILED, CANCELED
bl.fail_publish_container
end
update_results(bl, options)
else
update_rpm_builds options, status

View File

@ -6,6 +6,12 @@ module Modules
included do
def destroy
destroy_files_from_file_store if Rails.env.production?
super
end
later :destroy, :queue => :clone_build
def destroy_files_from_file_store
files = []
self.results.each {|r| files << r['sha1'] if r['sha1'].present?}
if self.respond_to? :packages
@ -25,10 +31,7 @@ module Modules
end
end
end
super
end
later :destroy, :queue => :clone_build
end
end
end