[Title] Refactored Build Server's Exception Handling
authordonghee yang <donghee.yang@samsung.com>
Wed, 26 Dec 2012 05:51:26 +0000 (14:51 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Wed, 26 Dec 2012 05:51:26 +0000 (14:51 +0900)
src/build_server/BuildServerException.rb [new file with mode: 0644]
src/build_server/SocketJobRequestListener.rb
test/build-server.basic1/build-cli-04.testcase
test/build-server.basic1/build-cli-12.testcase
test/build-server.basic1/build-cli-12_1.testcase
test/build-server.basic1/build-cli-14.testcase
test/build-server.basic1/build-cli-15.testcase
test/build-server.basic1/build-cli-27.testcase
test/build-server.basic1/build-cli-30.testcase
test/build-server.multi-svr2/01.testcase
test/build-server.multi_dist2/build-svr3-05.testcase

diff --git a/src/build_server/BuildServerException.rb b/src/build_server/BuildServerException.rb
new file mode 100644 (file)
index 0000000..8faed9a
--- /dev/null
@@ -0,0 +1,31 @@
+class BuildServerException < Exception
+       @@err_msgs = {
+               "ERR001" => "Invalid request format is used!",
+               "ERR002" => "Distribution not found!",
+               "ERR003" => "Unsupported OS name used!",
+               "ERR004" => "User account not found!",
+               "ERR005" => "Project access denied!",
+               "ERR006" => "Job creation failed!",
+               "ERR007" => "No supported OS defined in build server!",
+               "ERR008" => "Distribution locked!",
+               "ERR009" => "Project not found!",
+               "ERR010" => "Build operation not allowed on this project type!",
+               "ERR011" => "Project password required!",
+               "ERR012" => "Project password not matched!",
+               "ERR013" => "Project from file-name/distribution not found!",
+               "ERR014" => "Job cancel failed!",
+               "ERR015" => "Server password not matched!"
+       }
+
+       def initialize(code)
+               @err_code = code
+       end
+
+       def err_message()
+               if not message().nil? and not message().empty? then
+                       return "Error: #{@@err_msgs[@err_code]}: #{message()}"
+               else
+                       return "Error: #{@@err_msgs[@err_code]}"
+               end
+       end
+end
index d06f0d692f0a37d01aaa17d515fdb41f8e8968ee..8db35682d89bf36f2ac0c51b6f9ccb20ce2fa543 100644 (file)
@@ -29,6 +29,7 @@ Contributors:
 $LOAD_PATH.unshift File.dirname(__FILE__)
 require "JobLog.rb"
 require "BuildComm.rb"
+require "BuildServerException.rb"
 
 
 class SocketJobRequestListener
@@ -121,13 +122,9 @@ class SocketJobRequestListener
 
                case  cmd
                when "BUILD"
-                       @log.info "Received REQ: #{req_line}"
                        handle_cmd_build( req_line, req )
-                       @log.info "Handled REQ: #{req_line}"
                when "RESOLVE"
-                       @log.info "Received REQ: #{req_line}"
                        handle_cmd_resolve( req_line, req )
-                       @log.info "Handled REQ: #{req_line}"
                when "QUERY"
                        handle_cmd_query( req_line, req )
                when "CANCEL"
@@ -171,18 +168,33 @@ class SocketJobRequestListener
 
        end
 
+
        # "BUILD"
        def handle_cmd_build( line, req )
+               @log.info "Received REQ: #{line}"
+
+               begin
+                       handle_cmd_build_internal( line, req )
+               rescue BuildServerException => e
+                       BuildCommServer.send_begin(req)
+                       @log.error(e.message)
+                       BuildCommServer.send(req, e.err_message())
+                       BuildCommServer.send_end(req)
+               end
+
+               @log.info "Handled REQ: #{line}"
+       end
+
+
+       def handle_cmd_build_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
                if tok.count < 3 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
                # check type
                if tok[1] != "GIT" then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
                #          0  | 1 |     2      |  3   |  4    |  5  |     6    |    7    |   8      |   9   |   10   |    11   |  12  | 13 |   14
@@ -209,25 +221,17 @@ class SocketJobRequestListener
                end
 
                # check distribution
-               if not check_distribution(dist_name, req) then
-                       raise "The distribution error!!"
-               end
+               check_distribution(dist_name, req)
 
                # check supported os if not internal job
                if not is_internal then
                        os_list = check_supported_os( os_list , req )
-                       if os_list.nil? or os_list.empty? then
-                               raise "Unsupported OS name is used!"
-                       end
                end
 
                # check user email
                user_id = @parent_server.check_user_id_from_email( user_email )
                if user_id == -1 then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: Cannot find the user with \"#{user_email}\"!"
-                       BuildCommServer.send_end(req)
-                       raise "No user information!"
+                       raise BuildServerException.new("ERR004"), user_email
                end
 
 
@@ -240,11 +244,7 @@ class SocketJobRequestListener
                                else passwd = passwd_list[0] end
                                check_build_project(pname,passwd,dist_name,req)
                                if not check_project_user_id(pname,dist_name,user_id) then
-                                       BuildCommServer.send_begin(req)
-                                       req.puts "Error: \"#{user_email}\" can't access \"#{pname}\" project!"
-                                       req.puts "You are not in project control group"
-                                       BuildCommServer.send_end(req)
-                                       raise "#{user_email} can't accesse #{pname} project!"
+                                       raise BuildServerException.new("ERR005"), "#{user_email} -> #{pname}"
                                end
                                os_list.each do |os|
                                        new_job = create_new_job( pname, os, dist_name )
@@ -263,14 +263,14 @@ class SocketJobRequestListener
                        if new_job_list.count > 1 then
                                new_job = @parent_server.prjmgr.create_new_multi_build_job( new_job_list )
                                if new_job.nil? then
-                                       raise "Multi-Build Job creation failed!"
+                                       raise BuildServerException.new("ERR006"),"Multi-Build job"
                                else
                                        new_job.user_id = user_id
                                end
                        elsif new_job_list.count == 1 then
                                new_job = new_job_list[0]
                        else
-                               raise "Multi-Build Job creation failed!"
+                               raise BuildServerException.new("ERR006"),"No valid sub jobs in Multi-Build job"
                        end
 
                        # transfered job
@@ -280,7 +280,7 @@ class SocketJobRequestListener
 
                        new_job = create_new_internal_job(git_repos, os, git_commit, pkg_files, dock_num, dist_name )
                        if new_job.nil? then
-                               raise "Internal-Build Job creation failed!"
+                               raise BuildServerException.new("ERR006"),"Transfered-Build job"
                        else
                                new_job.user_id = user_id
                        end
@@ -293,30 +293,16 @@ class SocketJobRequestListener
 
                        check_build_project(pname,passwd,dist_name,req)
                        if not check_project_user_id(pname,dist_name,user_id) then
-                               BuildCommServer.send_begin(req)
-                               req.puts "Error: \"#{user_email}\" can't access \"#{pname}\" project!"
-                               req.puts "You are not in project control group"
-                               BuildCommServer.send_end(req)
-                               raise "#{user_email} can't accesse #{pname} project!"
+                               raise BuildServerException.new("ERR005"), "#{user_email} -> #{pname}"
                        end
                        new_job = create_new_job( pname, os, dist_name )
                        if new_job.nil? then
-                               raise "\"#{pname}\" does not support #{os} in #{dist_name}"
+                               raise BuildServerException.new("ERR006"), "\"#{pname}\" does not support #{os} in #{dist_name}"
                        else
                                new_job.user_id = user_id
                        end
                else
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: There is no valid job to build!"
-                       BuildCommServer.send_end(req)
-                       raise "No valid jobs!"
-               end
-
-               if new_job.nil? then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: Creating job failed! (project may not exist)"
-                       BuildCommServer.send_end(req)
-                       raise "Internal Error!"
+                       raise BuildServerException.new("ERR006"), "Cannot find your project to build!"
                end
 
                # check reverse build
@@ -351,31 +337,38 @@ class SocketJobRequestListener
        def check_build_project(prj_name, passwd, dist_name, req)
                # check project
                prj = check_project_exist(prj_name, dist_name, req)
-               if prj.nil? then
-                       raise "Requested project \"#{prj_name}\" does not exist!"
-               end
 
                # check passwd
-               if not check_project_password(prj, passwd, req) then
-                       raise "Project's password is not matched!!"
-               end
+               check_project_password(prj, passwd, req)
 
                # check project type
                if prj.type == "BINARY" then
+                       raise BuildServerException.new("ERR010"), prj.type
+               end
+       end
+
+
+       # "RESOLVE"
+       def handle_cmd_resolve( line, req )
+               @log.info "Received REQ: #{line}"
+
+               begin
+                       handle_cmd_resolve_internal( line, req )
+               rescue BuildServerException => e
                        BuildCommServer.send_begin(req)
-                       req.puts "Can't build about Binary type package."
+                       @log.error(e.message)
+                       BuildCommServer.send(req, e.err_message())
                        BuildCommServer.send_end(req)
-                       raise "Can't build about Binary type package."
                end
+
+               @log.info "Handled REQ: #{line}"
        end
 
 
-       # "RESOLVE"
-       def handle_cmd_resolve( line ,req)
+       def handle_cmd_resolve_internal( line ,req)
                tok = line.split("|").map { |x| x.strip }
                if tok.count < 3 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
                case tok[1]
@@ -395,50 +388,33 @@ class SocketJobRequestListener
                        end
 
                        # check distribution
-                       if not check_distribution(dist_name, req) then
-                               raise "The distribution error!!"
-                       end
+                       check_distribution(dist_name, req)
 
                        # check project
                        prj = check_project_exist(project_name, dist_name, req)
-                       if prj.nil? then
-                               raise "Requested project does not exist!"
-                       end
 
                        # check passwd
-                       if not check_project_password(prj, passwd, req) then
-                               raise "Project's password is not matched!!"
-                       end
+                       check_project_password(prj, passwd, req)
 
                        # check os
                        os_list = check_supported_os( [os] , req )
-                       if os_list.nil? or os_list.empty? then
-                               raise "Unsupported OS name is used!"
-                       end
                        os = os_list[0]
 
                        # check user email
                        user_id = @parent_server.check_user_id_from_email( user_email )
                        if user_id == -1 then
-                               BuildCommServer.send_begin(req)
-                               req.puts "Error: Cannot find the user with \"#{user_email}\"!"
-                               BuildCommServer.send_end(req)
-                               raise "No user information!"
+                               raise BuildServerException.new("ERR004"), user_email
                        end
 
                        # check user accessable
                        if not check_project_user_id(project_name,dist_name,user_id) then
-                               BuildCommServer.send_begin(req)
-                               req.puts "Error: \"#{user_email}\" can't access \"#{project_name}\" project!"
-                               req.puts "You are not in project control group"
-                               BuildCommServer.send_end(req)
-                               raise "#{user_email} can't accesse #{project_name} project!"
+                               raise BuildServerException.new("ERR005"), "#{user_email} -> #{project_name}"
                        end
 
                        # create new job
                        new_job = create_new_job( project_name, os, dist_name )
                        if new_job.nil? then
-                               raise "Creating build job failed : #{project_name}, #{os}"
+                               raise BuildServerException.new("ERR006"), "Resolve job #{project_name} #{os}"
                        end
                        @log.info "Received a request for resolving this project : #{project_name}, #{os}"
 
@@ -466,18 +442,28 @@ class SocketJobRequestListener
 
                        @parent_server.jobmgr.add_job( new_job )
                else
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
        end
 
 
        # "QUERY"
        def handle_cmd_query( line, req )
+               begin
+                       handle_cmd_query_internal( line, req )
+               rescue BuildServerException => e
+                       BuildCommServer.send_begin(req)
+                       @log.error(e.message)
+                       BuildCommServer.send(req, e.err_message())
+                       BuildCommServer.send_end(req)
+               end
+       end
+
+
+       def handle_cmd_query_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
                if tok.count < 2 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
                case tok[1]
@@ -581,28 +567,39 @@ class SocketJobRequestListener
                        BuildCommServer.disconnect(req)
 
                else
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
        end
 
 
        # "CANCEL"
        def handle_cmd_cancel( line, req )
+               @log.info "Received REQ: #{line}"
+
+               begin
+                       handle_cmd_cancel_internal( line, req )
+               rescue BuildServerException => e
+                       BuildCommServer.send_begin(req)
+                       @log.error(e.message)
+                       BuildCommServer.send(req, e.err_message())
+                       BuildCommServer.send_end(req)
+               end
+
+               @log.info "Handled REQ: #{line}"
+       end
+
+
+       def handle_cmd_cancel_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
                if tok.count < 2 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
                cancel_job = nil
 
                # check user email
                user_id = @parent_server.check_user_id_from_email( tok[3] )
                if user_id == -1 then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: Cannot find the user with \"#{tok[3]}\"!"
-                       BuildCommServer.send_end(req)
-                       raise "No user information!"
+                       raise BuildServerException.new("ERR004"), tok[3]
                end
 
                #CANCEL, JOB
@@ -613,69 +610,76 @@ class SocketJobRequestListener
                        end
                end
 
-               BuildCommServer.send_begin(req)
                if cancel_job.nil? then
-                       BuildCommServer.send(req, "There is no job \"#{tok[1]}\"")
-                       raise "There is no job \"#{tok[1]}\""
+                       raise BuildServerException.new("ERR014"), "Job #{tok[1]} not found."
                else
                        if cancel_job.cancel_state == "NONE" then
                                # check passwd
                                if not @parent_server.jobmgr.is_user_accessable(cancel_job,user_id) then
-                                       BuildCommServer.send_begin(req)
-                                       req.puts "Error: \"#{tok[3]}\" can't access \"#{cancel_job.get_project.name}\" project!"
-                                       req.puts "You are not in project control group"
-                                       BuildCommServer.send_end(req)
-                                       raise "#{tok[3]} can't accesse #{cancel_job.get_project.name} project!"
+                                       raise BuildServerException.new("ERR014"), "Access denied #{tok[3]}"
                                end
                                if cancel_job.type == "MULTIBUILD" then
                                        cancel_job.get_sub_jobs().select{|x| x.cancel_state == "NONE" }.each do |sub|
-                                               if not check_project_password( sub.get_project, tok[2], req) then
-                                                       BuildCommServer.send(req, "Project's password is not matched!!")
-                                                       raise "Project's password is not matched!!"
-                                               end
+                                               check_project_password( sub.get_project, tok[2], req)
                                        end
 
+                                       BuildCommServer.send_begin(req)
                                        BuildCommServer.send(req, "\"#{cancel_job.id}, #{cancel_job.get_sub_jobs().map{|x| x.id}.join(", ")}\" will be canceled")
                                        cancel_job.cancel_state = "INIT"
+                                       BuildCommServer.send_end(req)
+                                       BuildCommServer.disconnect(req)
                                else
                                        prj = cancel_job.get_project()
                                        if not prj.nil? then
-                                               if not check_project_password( prj, tok[2], req) then
-                                                       BuildCommServer.send(req, "Project's password is not matched!!")
-                                                       raise "Project's password is not matched!!"
-                                               else
-                                                       BuildCommServer.send(req, "\"#{cancel_job.id}\" will be canceled")
-                                                       cancel_job.cancel_state = "INIT"
-                                               end
+                                               check_project_password( prj, tok[2], req)
+
+                                               BuildCommServer.send_begin(req)
+                                               BuildCommServer.send(req, "\"#{cancel_job.id}\" will be canceled")
+                                               cancel_job.cancel_state = "INIT"
+                                               BuildCommServer.send_end(req)
+                                               BuildCommServer.disconnect(req)
                                        else
-                                               BuildCommServer.send(req, "Cannot cancel the job \"#{cancel_job.id}\"")
+                                               raise BuildServerException.new("ERR014"), "No project infomation"
                                        end
                                end
                        else
-                               BuildCommServer.send(req, "\"#{cancel_job.id}\" is already canceled")
+                               raise BuildServerException.new("ERR014"), "Job already canceled."
                        end
                end
-               BuildCommServer.send_end(req)
-               BuildCommServer.disconnect(req)
        end
 
 
        # "STOP"
        def handle_cmd_stop( line, req )
+               @log.info "Received REQ: #{line}"
+
+               begin
+                       handle_cmd_stop_internal( line, req )
+               rescue BuildServerException => e
+                       BuildCommServer.send_begin(req)
+                       @log.error(e.message)
+                       BuildCommServer.send(req, e.err_message())
+                       BuildCommServer.send_end(req)
+               end
+
+               @log.info "Handled REQ: #{line}"
+       end
+
+
+       def handle_cmd_stop_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
                if tok.count < 2 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
-               BuildCommServer.send_begin(req)
                if tok[1] != @parent_server.password then
-                       BuildCommServer.send(req,"Password mismatched!")
+                       raise BuildServerException.new("ERR015"), ""
                else
+                       BuildCommServer.send_begin(req)
                        BuildCommServer.send(req,"Server will be down!")
+                       BuildCommServer.send_end(req)
+                       BuildCommServer.disconnect(req)
                end
-               BuildCommServer.send_end(req)
-               BuildCommServer.disconnect(req)
                if tok[1] == @parent_server.password then
                        @parent_server.finish = true
                end
@@ -684,20 +688,35 @@ class SocketJobRequestListener
 
        # "UPGRADE"
        def handle_cmd_upgrade( line, req )
+               @log.info "Received REQ: #{line}"
+
+               begin
+                       handle_cmd_upgrade_internal( line, req )
+               rescue BuildServerException => e
+                       BuildCommServer.send_begin(req)
+                       @log.error(e.message)
+                       BuildCommServer.send(req, e.err_message())
+                       BuildCommServer.send_end(req)
+               end
+
+               @log.info "Handled REQ: #{line}"
+       end
+
+
+       def handle_cmd_upgrade_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
                if tok.count < 2 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
-               BuildCommServer.send_begin(req)
                if tok[1] != @parent_server.password then
-                       BuildCommServer.send(req,"Password mismatched!")
+                       raise BuildServerException.new("ERR015"), ""
                else
-                       BuildCommServer.send(req,"Server will be down!")
+                       BuildCommServer.send_begin(req)
+                       BuildCommServer.send(req,"Server will be upgraded!")
+                       BuildCommServer.send_end(req)
+                       BuildCommServer.disconnect(req)
                end
-               BuildCommServer.send_end(req)
-               BuildCommServer.disconnect(req)
                if tok[1] == @parent_server.password then
                        @parent_server.finish = true
                        @parent_server.upgrade = true
@@ -707,10 +726,25 @@ class SocketJobRequestListener
 
        # "FULLBUILD"
        def handle_cmd_fullbuild( line, req )
+               @log.info "Received REQ: #{line}"
+
+               begin
+                       handle_cmd_fullbuild_internal( line, req )
+               rescue BuildServerException => e
+                       BuildCommServer.send_begin(req)
+                       @log.error(e.message)
+                       BuildCommServer.send(req, e.err_message())
+                       BuildCommServer.send_end(req)
+               end
+
+               @log.info "Handled REQ: #{line}"
+       end
+
+
+       def handle_cmd_fullbuild_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
                if tok.count < 2 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
                server_passwd = tok[1]
@@ -720,17 +754,11 @@ class SocketJobRequestListener
                end
 
                # check distribution
-               if not check_distribution(dist_name, req, true) then
-                       raise "The distribution error!!"
-               end
+               check_distribution(dist_name, req, true)
 
                # check server password
                if server_passwd != @parent_server.password then
-                       BuildCommServer.send_begin(req)
-                       BuildCommServer.send(req,"Password mismatched!")
-                       BuildCommServer.send_end(req)
-                       BuildCommServer.disconnect(req)
-                       return
+                       raise BuildServerException.new("ERR015"), ""
                end
 
                # create full build job
@@ -748,10 +776,25 @@ class SocketJobRequestListener
 
        # "REGISTER"
        def handle_cmd_register( line, req )
+               @log.info "Received REQ: #{line}"
+
+               begin
+                       handle_cmd_register_internal( line, req )
+               rescue BuildServerException => e
+                       BuildCommServer.send_begin(req)
+                       @log.error(e.message)
+                       BuildCommServer.send(req, e.err_message())
+                       BuildCommServer.send_end(req)
+               end
+
+               @log.info "Handled REQ: #{line}"
+       end
+
+
+       def handle_cmd_register_internal( line, req )
                tok = line.split("|").map { |x| x.strip }
                if tok.count < 4 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
                type = tok[1]
@@ -767,9 +810,7 @@ class SocketJobRequestListener
                        end
 
                        # check distribution
-                       if not check_distribution(dist_name, req) then
-                               raise "The distribution error!!"
-                       end
+                       check_distribution(dist_name, req)
 
                        new_job = @parent_server.jobmgr.create_new_register_job( file_path, dist_name )
                        logger = JobLog.new( new_job, req )
@@ -794,43 +835,29 @@ class SocketJobRequestListener
                        end
 
                        # check distribution
-                       if not check_distribution(dist_name, req) then
-                               raise "The distribution error!!"
-                       end
+                       check_distribution(dist_name, req)
 
                        # check project
                        prj = check_project_for_package_file_name(filename, dist_name, req)
-                       if prj.nil? then
-                               raise "No project is defined for this binary : #{filename}!"
-                       end
 
                        # check user email
                        user_id = @parent_server.check_user_id_from_email( user_email )
                        if user_id == -1 then
-                               BuildCommServer.send_begin(req)
-                               req.puts "Error: Cannot find the user with \"#{user_email}\"!"
-                               BuildCommServer.send_end(req)
-                               raise "No user information!"
+                               raise BuildServerException.new("ERR004"), user_email
                        end
 
                        if not check_project_pkg_name_user_id(filename, dist_name, user_id) then
-                               BuildCommServer.send_begin(req)
-                               req.puts "Error: \"#{user_email}\" can't regist \"#{filename}\"!"
-                               req.puts "You are not in project control group"
-                               BuildCommServer.send_end(req)
-                               raise "#{user_email} can't regist #{filename}!"
+                               raise BuildServerException.new("ERR005"), "#{user_email} -> #{prj.name}"
                        end
 
                        # check passwd
-                       if not check_project_password(prj, passwd, req) then
-                               raise "Project's password is not matched!!"
-                       end
+                       check_project_password(prj, passwd, req)
 
                        # create new job
                        @log.info "Received a request for uploading binaries : #{filename}"
                        new_job = create_new_upload_job( prj.name, filename, dock, dist_name, req )
                        if new_job.nil? then
-                               raise "Creating build job failed : #{prj.name}, #{filename}"
+                               raise BuildServerException.new("ERR006"), "Register-job #{filename}, #{prj.name}, #{dist_name}"
                        end
 
                        new_job.user_id = user_id
@@ -852,8 +879,7 @@ class SocketJobRequestListener
                        # add
                        @parent_server.jobmgr.add_job( new_job )
                else
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
+                       raise BuildServerException.new("ERR001"), line
                end
 
        end
@@ -864,11 +890,6 @@ class SocketJobRequestListener
                @log.info "Received File transfer REQ : #{line}"
 
                tok = line.split("|").map { |x| x.strip }
-               if tok.count < 2 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
-               end
-
                dock_num = (tok[1].nil? or tok[1].empty?) ? "0" : tok[1].strip
 
                BuildCommServer.send_begin(req)
@@ -884,11 +905,6 @@ class SocketJobRequestListener
        def handle_cmd_download( line, req )
                @log.info "Received File transfer REQ : #{line}"
                tok = line.split("|").map { |x| x.strip }
-               if tok.count < 3 then
-                       @log.info "Received Wrong REQ: #{line}"
-                       raise "Invalid request format is used: #{line}"
-               end
-
                dock_num = (tok[1].nil? or tok[1].empty?) ? "0" : tok[1].strip
                file_name = tok[2]
 
@@ -919,11 +935,7 @@ class SocketJobRequestListener
        def check_project_exist(project_name, dist_name, req)
                prj = @parent_server.prjmgr.get_project(project_name, dist_name)
                if prj.nil? then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: Requested project \"#{project_name}\" does not exist!"
-                       req.puts "Info: Check project name using \"query\" command option !"
-                       BuildCommServer.send_end(req)
-                       return nil
+                       raise BuildServerException.new("ERR009"), "#{project_name} on #{dist_name}"
                end
 
                return prj
@@ -945,28 +957,25 @@ class SocketJobRequestListener
 
                prj = @parent_server.prjmgr.get_project_from_package_name(pkg_name, dist_name)
                if prj.nil? then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: Requested project does not exist!"
-                       req.puts "Info: Check project name using \"query\" command option !"
-                       BuildCommServer.send_end(req)
-                       return nil
+                       raise BuildServerException.new("ERR013"), "#{pkg_name} #{dist_name}"
                end
 
                return prj
        end
 
+
        private
        def check_project_password(prj, passwd, req)
 
-               if prj.is_passwd_set? and not prj.passwd_match?(passwd) then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: Project's password is not matched!"
-                       req.puts "Error: Use -w option to input your project password"
-                       BuildCommServer.send_end(req)
-                       return false
-               end
+               if prj.is_passwd_set?  then
+                       if passwd.nil? or passwd.empty? then
+                               raise BuildServerException.new("ERR011"), "Use -w option to input your project password"
+                       end
 
-               return true
+                       if not prj.passwd_match?(passwd) then
+                               raise BuildServerException.new("ERR012"), ""
+                       end
+               end
        end
 
 
@@ -974,17 +983,10 @@ class SocketJobRequestListener
        def check_distribution(dist_name, req, only_exist = false)
                dist = @parent_server.distmgr.get_distribution(dist_name)
                if dist.nil? then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: The distribution \"#{dist_name}\" does not exist!"
-                       BuildCommServer.send_end(req)
+                       raise BuildServerException.new("ERR002"), dist_name
                elsif dist.status != "OPEN" and not only_exist then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: The distribution \"#{dist_name}\" is locked!"
-                       BuildCommServer.send_end(req)
-                       return false
+                       raise BuildServerException.new("ERR008"), dist_name
                end
-
-               return true
        end
 
 
@@ -993,10 +995,7 @@ class SocketJobRequestListener
 
                # check if supported os list contain at least one OS
                if @parent_server.supported_os_list.empty? then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: There is no OS supported by the build server."
-                       BuildCommServer.send_end(req)
-                       return nil
+                       raise BuildServerException.new("ERR007"), ""
                end
 
                result = []
@@ -1021,26 +1020,19 @@ class SocketJobRequestListener
                        elsif @parent_server.supported_os_list.include?(os) then
                                result.push os
                        else
-                               BuildCommServer.send_begin(req)
-                               req.puts "Error: Unsupported OS name \"#{os}\" is used!"
-                               req.puts "Error: Check the following supported OS list. "
+                               msgs = "#{os}\n\tSupported OS list.\n"
                                @parent_server.supported_os_list.each do |os_name|
-                                       req.puts " * #{os_name}"
+                                       msgs += "\t * #{os_name}\n"
                                end
-                               BuildCommServer.send_end(req)
-                               return nil
+                               raise BuildServerException.new("ERR003"),msgs
                        end
                end
 
+               result.uniq!
                if result.empty? then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: There is no OS supported by the build server."
-                       BuildCommServer.send_end(req)
-                       return nil
+                       raise BuildServerException.new("ERR003"), "There is no OS name matched."
                end
 
-               result.uniq!
-
                return result
        end
 
@@ -1054,16 +1046,7 @@ class SocketJobRequestListener
        private
        def create_new_upload_job( project_name, filename, dock, dist_name, req)
 
-               new_job = @parent_server.prjmgr.get_project(project_name, dist_name).create_new_job(filename, dock)
-
-               if new_job.nil?  then
-                       BuildCommServer.send_begin(req)
-                       req.puts "Error: Creating job failed: #{project_name} #{filename} #{dist_name}"
-                       BuildCommServer.send_end(req)
-                       return nil
-               end
-
-               return new_job
+               return @parent_server.prjmgr.get_project(project_name, dist_name).create_new_job(filename, dock)
        end
 
 
index 0ab12086c4bc459a49bfd86bb6c8101e2279caf3..977d486fbdb9dace7921a72105c8334ab1a330fa 100644 (file)
@@ -3,5 +3,4 @@
 ../../build-cli build -N non_exist_project -d 127.0.0.1:2223 -o ubuntu-32
 #POST-EXEC
 #EXPECT
-Error: Requested project "non_exist_project" does not exist!
-Info: Check project name using "query" command option !
+Error: Project not found!: non_exist_project on BASE
index d1a9353f0fe55b79d08221ab33fe4d4aa993726a..a0b9e6f6204de40a6f323a1275be3f6295c3978b 100644 (file)
@@ -5,7 +5,7 @@ echo "wrong os name in build command"
 ../../build-cli build -N testa -d 127.0.0.1:2223 -o wrong_os_name
 #POST-EXEC
 #EXPECT
-Error: Unsupported OS name "wrong_os_name" is used!
-Error: Check the following supported OS list.
+Error: Unsupported OS name used!: wrong_os_name
+Supported OS list.
 * ubuntu-32
 * windows-32
index f53b6f5ef44125418b59f9c69f5712c71357f862..cccfe9f0895933154c4406e4555c1789114f923f 100644 (file)
@@ -4,7 +4,7 @@ echo "wrong os name in resolve command"
 ../../build-cli resolve -N testa -d 127.0.0.1:2223 -o wrong_os_name
 #POST-EXEC
 #EXPECT
-Error: Unsupported OS name "wrong_os_name" is used!
-Error: Check the following supported OS list.
+Error: Unsupported OS name used!: wrong_os_name
+Supported OS list.
 * ubuntu-32
 * windows-32
index 3a7107ba95e367dc0eb513426cf307bdd2df4bc4..df9fff2687427649efe5ebbda5d43c73301122d6 100644 (file)
@@ -5,5 +5,4 @@ echo "Assume that testa,testb which are depended by testc are built and uploaded
 ../../build-cli build -N testc -d 127.0.0.1:2223 -o ubuntu-32
 #POST-EXEC
 #EXPECT
-Error: Project's password is not matched!
-Error: Use -w option to input your project password
+Error: Project password required!: Use -w option to input your project password
index dd8305c6d211e7f47339b1d479bb8b94dea912e6..9b7cd98aa166763f2752cebeaac6abc72e3ce16e 100644 (file)
@@ -5,5 +5,4 @@ echo "Assume that testa,testb which are depended by testc are built and uploaded
 ../../build-cli build -N testc -d 127.0.0.1:2223 -w 2222 -o ubuntu-32
 #POST-EXEC
 #EXPECT
-Error: Project's password is not matched!
-Error: Use -w option to input your project password
+Error: Project password not matched!
index 60c88893a27382fbcd48b1a8ecd04a9cecc569df..66eb1cf51da6f5b5205696730ed42717bec7c8ff 100644 (file)
@@ -4,4 +4,4 @@ cd git01;tar xf c_v5.tar.gz
 ../../build-cli build -N testc -d 127.0.0.1:2223 -o li_* -w 1111
 #POST-EXEC
 #EXPECT
-Error: There is no OS supported by the build server.
+Error: Unsupported OS name used!: There is no OS name matched.
index 33a5460df735341c4451c13a83fa1df77abdeed8..2fe774ea946fcc9e647b487efde0f16a7ce21115 100644 (file)
@@ -4,4 +4,4 @@ echo "user check"
 ../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -U xxuser@user
 #POST-EXEC
 #EXPECT
-Error: Cannot find the user with "xxuser@user"!
+Error: User account not found!: xxuser@user
index 05095f5453aaadf81170a69a89c8db2c1a732496..f71a53f3bc39c6c9f0f9f74fa7ab14e368d45df8 100644 (file)
@@ -19,4 +19,5 @@ I, [
 I, [
 I, [
 I, [
+I, [
 bin  (0.0.1)
index a2b86606303f02057dd9fd54f16de5a4186a4a28..68365154946893d3a2b840b103f94dfa4417b998 100644 (file)
@@ -14,7 +14,7 @@ echo "=="
 ==
 Distribution is locked!
 ==
-Error: The distribution "unstable2" is locked!
+Error: Distribution locked!: unstable2
 ==
 Distribution is unlocked!
 ==