From 39931738050d94d4686f2a26d07bebe12a24ca8a Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Thu, 7 Apr 2011 13:10:34 +0400 Subject: [PATCH 1/5] minor --- lib/build_server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build_server.rb b/lib/build_server.rb index 8f073a728..513b81cc4 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -15,7 +15,7 @@ class BuildServer SRPM_NOT_FOUND = 12800 def self.client - @@client ||= XMLRPC::Client.new(:host => AppConfig['build_server_ip'], :port => AppConfig['build_server_port'], :path => AppConfig['build_server_path']) + @@client ||= XMLRPC::Client.new3(:host => APP_CONFIG['build_server_ip'], :port => APP_CONFIG['build_server_port'], :path => APP_CONFIG['build_server_path']) end From 58f8ce453e3c4d9f1e3a277a7971b962a0d7a1bc Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Thu, 7 Apr 2011 13:10:46 +0400 Subject: [PATCH 2/5] Platform create/delete RPC calls --- app/models/platform.rb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index a60902a8c..4f8f8dd07 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -5,7 +5,8 @@ class Platform < ActiveRecord::Base validates :name, :presence => true, :uniqueness => true validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9\-.]+$/ }, :allow_nil => false, :allow_blank => false - before_create :create_directory + before_create :xml_rpc_create + before_destroy :xml_rpc_destroy def path build_path(unixname) @@ -31,13 +32,35 @@ class Platform < ActiveRecord::Base File.join(APP_CONFIG['root_path'], dir) end + def git_path(dir) + File.join(build_path(dir), 'git') + end + def create_directory exists = File.exists?(path) && File.directory?(path) raise "Directory #{path} already exists" if exists if new_record? FileUtils.mkdir_p(path) elsif unixname_changed? - FileUtils.mv(build_path(unixname_was), buildpath(unixname)) + FileUtils.mv(build_path(unixname_was), build_path(unixname)) end end + + def xml_rpc_create + result = BuildServer.add_platform name, build_path(unixname), [], git_path(unixname) + if result == BuildServer::SUCCESS + return true + else + raise "Failed to create platform #{name}. Path: #{build_path(unixname)}" + end + end + + def xml_rpc_destroy + result = BuildServer.delete_platform name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to delete platform #{name}." + end + end end From f27f5558e96d48cf173ae45d9f0d9462809a49a4 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Thu, 7 Apr 2011 13:27:30 +0400 Subject: [PATCH 3/5] minor build server xmlrpc fix --- lib/build_server.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/build_server.rb b/lib/build_server.rb index 513b81cc4..e3b2a1cd1 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -35,10 +35,14 @@ class BuildServer def self.create_repo name, platform_name - self.client.call('create_repo', name, platform_name) + self.client.call('create_repository', name, platform_name) end + def self.delete_repo name, platform_name + self.client.call('delete_repository', name, platform_name) + end + def self.clone_repo new_name, old_name, new_platform_name self.client.call('clone_repo', new_name, old_name, new_platform_name) end From 5ca703b96bb0cc52ebfc5007cbeaf6ce0a408259 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Thu, 7 Apr 2011 13:27:50 +0400 Subject: [PATCH 4/5] Repository create/delete RPC calls --- app/models/repository.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index c578c4732..c1411e2b7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -7,7 +7,8 @@ class Repository < ActiveRecord::Base scope :recent, order("name ASC") - before_create :create_directory + before_create :xml_rpc_create + before_destroy :xml_rpc_destroy def path build_path(unixname) @@ -27,7 +28,6 @@ class Repository < ActiveRecord::Base File.join(platform.path, dir) end - #TODO: Spec me def create_directory exists = File.exists?(path) && File.directory?(path) raise "Directory #{path} already exists" if exists @@ -38,5 +38,24 @@ class Repository < ActiveRecord::Base FileUtils.mv(build_path(unixname_was), buildpath(unixname)) end end + + def xml_rpc_create + result = BuildServer.create_repo name, platform.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to create repository #{name} inside platform #{platform.name}." + end + end + + def xml_rpc_destroy + result = BuildServer.delete_repo name, platform.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to delete repository #{name} inside platform #{platform.name}." + end + + end end From 689b5441dc1c17a35580b8c488661404b0dab857 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Thu, 7 Apr 2011 13:32:14 +0400 Subject: [PATCH 5/5] XML-RPC Project create/delete/add_to_repo calls --- app/models/project.rb | 32 ++++++++++++++++++++++++++++++-- app/models/repository.rb | 1 - 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 2d4b41837..5b0c972b4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -8,7 +8,9 @@ class Project < ActiveRecord::Base scope :recent, order("name ASC") - before_create :create_directory, :create_git_repo + #before_create :create_directory, :create_git_repo + before_create :xml_rpc_create, :create_git_repo + before_destroy :xml_rpc_destroy # Redefining a method from Project::HasRepository module to reflect current situation def git_repo_path @@ -26,13 +28,21 @@ class Project < ActiveRecord::Base return p end + def add_to_repository(platf, repo) + result = BuildServer.add_to_repo(repository.name, platf.name) + if result == BuildServer::SUCCESS + return true + else + raise "Failed to add project #{name} to repo #{repo.name)} of platform #{platf.name}." + end + end + protected def build_path(dir) File.join(repository.path, dir) end - #TODO: Spec me def create_directory exists = File.exists?(path) && File.directory?(path) raise "Directory #{path} already exists" if exists @@ -46,4 +56,22 @@ class Project < ActiveRecord::Base def create_git_repo Git::Repository.create(git_repo_path) end + + def xml_rpc_create + result = BuildServer.create_project name, platform.name, repository.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to create project #{name} (repo #{repository.name)}) inside platform #{platform.name}." + end + end + + def xml_rpc_destroy + result = BuildServer.delete_project name, platform.name, repository.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to delete repository #{name} (repo #{repository.name)}) inside platform #{platform.name}." + end + end end diff --git a/app/models/repository.rb b/app/models/repository.rb index c1411e2b7..7a6431c84 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -55,7 +55,6 @@ class Repository < ActiveRecord::Base else raise "Failed to delete repository #{name} inside platform #{platform.name}." end - end end