From cbab2a76717cc23bd5b2915b1a9288781de2bb29 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Mon, 11 Apr 2011 12:34:34 +0400 Subject: [PATCH 1/3] minor fix --- app/controllers/build_lists_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/build_lists_controller.rb b/app/controllers/build_lists_controller.rb index 6101a9699..ae3dd5e8c 100644 --- a/app/controllers/build_lists_controller.rb +++ b/app/controllers/build_lists_controller.rb @@ -1,5 +1,5 @@ class BuildListsController < ApplicationController - before_filter :authenticate_user! + before_filter :authenticate_user!, :except => [:status_build, :pre_build, :post_build] before_filter :find_platform, :only => [:index, :filter] before_filter :find_repository, :only => [:index, :filter] before_filter :find_project, :only => [:index, :filter] @@ -87,4 +87,4 @@ class BuildListsController < ApplicationController @build_list = BuildList.find_by_bs_id!(params[:id]) end -end \ No newline at end of file +end From deb95b8e4068e776f3696ab5f686f44f726a93b2 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Mon, 11 Apr 2011 12:34:50 +0400 Subject: [PATCH 2/3] build server xmlrpc consistency --- lib/build_server.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/build_server.rb b/lib/build_server.rb index e3b2a1cd1..ce4fccc62 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -71,4 +71,8 @@ class BuildServer def self.add_build_list project_name, branch_name, platform_name, arch_name self.client.call('add_build_list', project_name, branch_name, platform_name, arch_name) end + + def self.freeze platform_name, new_repo_name = nil + self.client.call('freeze_platform', platform_name, new_repo_name) + end end From cd6e7ade15e00ffd1d13d6a212876879cfb06d6a Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Mon, 11 Apr 2011 12:35:08 +0400 Subject: [PATCH 3/3] Product Builder xml-rpc and Product model --- app/controllers/products_controller.rb | 26 ++++++++++++++++++++ app/helpers/products_helper.rb | 2 ++ app/models/platform.rb | 2 ++ app/models/product.rb | 11 +++++++++ config/routes.rb | 5 ++++ db/migrate/20110411082826_create_products.rb | 16 ++++++++++++ db/schema.rb | 11 ++++++++- lib/product_builder.rb | 15 +++++++++++ spec/controllers/products_controller_spec.rb | 5 ++++ spec/helpers/products_helper_spec.rb | 15 +++++++++++ spec/models/product_spec.rb | 5 ++++ 11 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 app/controllers/products_controller.rb create mode 100644 app/helpers/products_helper.rb create mode 100644 app/models/product.rb create mode 100644 db/migrate/20110411082826_create_products.rb create mode 100644 lib/product_builder.rb create mode 100644 spec/controllers/products_controller_spec.rb create mode 100644 spec/helpers/products_helper_spec.rb create mode 100644 spec/models/product_spec.rb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 000000000..a633719f1 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,26 @@ +class ProductsController < ApplicationController + before_filter :authenticate_user!, :except => [:product_begin, :product_end] + before_filter :find_product_by_name, :only => [:product_begin, :product_end] + + def product_begin + @product.build_status = Product::STATUS::BUILDING + @product.build_path = params[:path] + @product.save! + + render :nothing => true, :status => 200 + end + + def product_end + @product.build_status = ((params[:status] == BuildServer::SUCCESS) ? Product::BUILD_COMPLETED : Product::BUILD_FAILED) + @product.build_path = params[:path] + @product.save! + + render :nothing => true, :status => 200 + end + + protected + + def find_product_by_name + @product = Product.find_by_name params[:product_name] + end +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 000000000..ab5c42b32 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/models/platform.rb b/app/models/platform.rb index 4f8f8dd07..bb1566114 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -1,6 +1,7 @@ class Platform < ActiveRecord::Base belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' has_many :repositories, :dependent => :destroy + has_many :products, :dependent => :destroy validates :name, :presence => true, :uniqueness => true validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false @@ -8,6 +9,7 @@ class Platform < ActiveRecord::Base before_create :xml_rpc_create before_destroy :xml_rpc_destroy + def path build_path(unixname) end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 000000000..51661c3b8 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,11 @@ +class Product < ActiveRecord::Base + validates :name, :presence => true, :uniqueness => true + validates :platform_id, :presence => true + validates :build_status, :inclusion => { :in => [ NEVER_BUILT, BUILD_COMPLETED, BUILD_FAILED ] } + + belongs_to :platform + + NEVER_BUILT = 2 + BUILD_COMPLETED = 0 + BUILD_FAILED = 1 +end diff --git a/config/routes.rb b/config/routes.rb index 874c20a22..e0c59f946 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,8 @@ Rosa::Application.routes.draw do get 'unfreeze' end + resources :products + resources :repositories do resources :projects do resource :repo, :controller => "git/repositories", :only => [:show] @@ -26,6 +28,9 @@ Rosa::Application.routes.draw do match 'build_lists/post_build', :to => "build_lists#post_build" match 'build_lists/circle_build', :to => "build_lists#circle_build" + match 'product_begin', :to => 'products#product_begin' + match 'product_end', :to => 'products#product_end' + # Tree match 'platforms/:platform_id/repositories/:repository_id/projects/:project_id/git/tree/:treeish(/*path)', :controller => "git/trees", :action => :show, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :tree diff --git a/db/migrate/20110411082826_create_products.rb b/db/migrate/20110411082826_create_products.rb new file mode 100644 index 000000000..64a50e87b --- /dev/null +++ b/db/migrate/20110411082826_create_products.rb @@ -0,0 +1,16 @@ +class CreateProducts < ActiveRecord::Migration + def self.up + create_table :products do |t| + t.string :name, :null => false + t.integer :platform_id, :null => false + t.integer :build_status, :default => 2, :null => false ### NOTE :default => 2 comes from Product::NEVER_BUILT status which we unable to use here + t.string :build_path + + t.timestamps + end + end + + def self.down + drop_table :products + end +end diff --git a/db/schema.rb b/db/schema.rb index a7a7d0fdc..96e8a1e44 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110407144147) do +ActiveRecord::Schema.define(:version => 20110411082826) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -54,6 +54,15 @@ ActiveRecord::Schema.define(:version => 20110407144147) do t.boolean "released", :default => false end + create_table "products", :force => true do |t| + t.string "name", :null => false + t.integer "platform_id", :null => false + t.integer "build_status", :default => 2, :null => false + t.string "build_path" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "projects", :force => true do |t| t.string "name" t.string "unixname" diff --git a/lib/product_builder.rb b/lib/product_builder.rb new file mode 100644 index 000000000..9b847f555 --- /dev/null +++ b/lib/product_builder.rb @@ -0,0 +1,15 @@ +require 'xmlrpc/client' +class ProductBuilder + + SUCCESS = 0 + ERROR = 1 + + + def self.client + @@client ||= XMLRPC::Client.new3(:host => APP_CONFIG['product_builder_ip'], :port => APP_CONFIG['product_builder_port'], :path => APP_CONFIG['product_builder_path']) + end + + def self.create_product name, platform_name, params, packages, post_install, path, repos + self.client.call('create_product', name, platform_name, params, packages, post_install, path, repos) + end +end diff --git a/spec/controllers/products_controller_spec.rb b/spec/controllers/products_controller_spec.rb new file mode 100644 index 000000000..77af8e7cd --- /dev/null +++ b/spec/controllers/products_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe ProductsController do + +end diff --git a/spec/helpers/products_helper_spec.rb b/spec/helpers/products_helper_spec.rb new file mode 100644 index 000000000..e5212c5f2 --- /dev/null +++ b/spec/helpers/products_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the ProductsHelper. For example: +# +# describe ProductsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe ProductsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb new file mode 100644 index 000000000..267720887 --- /dev/null +++ b/spec/models/product_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Product do + pending "add some examples to (or delete) #{__FILE__}" +end