[Title] Fixed a bug that "CANCEL" is not applied immediately
authordonghee yang <donghee.yang@samsung.com>
Tue, 26 Mar 2013 08:15:06 +0000 (17:15 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Tue, 26 Mar 2013 08:15:06 +0000 (17:15 +0900)
src/build_server/BuildJob.rb
src/build_server/CommonJob.rb
src/build_server/JobManager.rb
src/build_server/MultiBuildJob.rb
src/build_server/RegisterPackageJob.rb
test/build-server.basic1/build-cli-01.testcase

index c44f93949b050fa912525e14361a4cd872f74158..a440e9be88b198f430c244fa2cea1617ee93ab25 100644 (file)
@@ -45,7 +45,7 @@ require "CommonJob.rb"
 class BuildJob < CommonJob
 
        attr_accessor :pkginfo, :source_path
-       attr_accessor :pkgsvr_client, :thread
+       attr_accessor :pkgsvr_client
 #      attr_accessor :rev_fail_projects, :rev_success_jobs
 #      attr_accessor :pending_ancestor
        attr_accessor :no_reverse
@@ -75,7 +75,6 @@ class BuildJob < CommonJob
                # this item will be initialized on pre-verify
                @pkginfo = nil
                @pkgsvr_client = nil
-               @thread = nil
                @log = nil
                @parent = nil # for job hierachy
 
@@ -186,7 +185,7 @@ class BuildJob < CommonJob
                kill_sub_process()
 
                # cancel all its sub jobs
-               @sub_jobs.select{|x| x.event == "NONE"}.each do |sub|
+               @sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub|
                        sub.event = "CANCEL"
                end
 
@@ -197,13 +196,7 @@ class BuildJob < CommonJob
                        end
                end
 
-               # cancel log print
-               if not @log.nil? then
-                       @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
-               end
-
-               case @status
-               when "REMOTE_WORKING" then
+               if @status == "REMOTE_WORKING" then
                        client = BuildCommClient.create( @remote_server.ip, @remote_server.port, @log )
                        if not client.nil? then
                                client.send "CANCEL|#{@remote_id}|#{self.get_project.passwd}|admin@user"
@@ -217,40 +210,14 @@ class BuildJob < CommonJob
                                end
                                client.terminate
                        end
-               #when "PENDING" then
-               #       if @pending_ancestor.nil? then
-               #               #resolve pending job
-               #               pending_descendants = @server.jobmgr.jobs.select do |j|
-               #                       (not j.pending_ancestor.nil?) and "#{j.pending_ancestor.id}" == "#{@id}"
-               #               end
-               #               pending_descendants.each do |pd|
-               #                       pd.cancel_state = "INIT"
-               #               end
-               #       else
-               #               # remove myself from success job if exist
-               #               # and add myself into rev_fail_project list if not exist
-               #               @pending_ancestor.remove_rev_success_job(self)
-               #               @pending_ancestor.add_rev_fail_project( @project, @os )
-
-               #               # remove the project that depends on me if exist
-               #               # and add it into rev_fail_project list if not exist
-               #               p_sub_jobs = @server.jobmgr.jobs.select do |j|
-               #                       ( not j.pending_ancestor.nil? and
-               #                        "#{j.pending_ancestor.id}" == "#{@pending_ancestor.id}" and
-               #                        j.is_build_dependent_project(@project, @os) )
-               #               end
-               #               p_sub_jobs.each do |d|
-               #                       @pending_ancestor.remove_rev_success_job(d)
-               #                       @pending_ancestor.add_rev_fail_project( d.get_project, d.os )
-
-               #                       if not d.thread.nil? then d.thread.terminate end
-               #                       d.status = "WAITING"
-               #               end
-               #       end
-               when "WORKING", "WAITING" , "INITIALIZING" , "JUST_CREATED" then
-                       #just log
-               else # ERROR | FINISHED | RESOLVED
-                       #do noting
+               end
+
+               # wait for job thread to finish
+               @thread.join if not @thread.nil?
+
+               # cancel log print
+               if not @log.nil? then
+                       @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
                end
        end
 
index a3522711a7ed77c80b06f9adf55b1cce4f72a387..eeb6a645f43f6470761c5f62696287404d094c4b 100644 (file)
@@ -35,7 +35,7 @@ require "utils.rb"
 class CommonJob
 
        attr_accessor :id, :server, :log, :status, :priority
-       attr_accessor :os, :type, :pre_jobs, :user_id, :event, :sub_jobs
+       attr_accessor :os, :type, :pre_jobs, :user_id, :event, :sub_jobs, :thread
        USER_JOB_PRIORITY = 100
        AUTO_JOB_PRIORITY = 0
 
@@ -61,6 +61,7 @@ class CommonJob
 
                @start_time = Time.now
                @end_time = nil
+               @thread = nil
                @sub_pid = 0
        end
 
@@ -172,6 +173,14 @@ class CommonJob
        #cancel
        public
        def cancel()
+               kill_sub_process
+
+               @sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub|
+                       sub.event = "CANCEL"
+               end
+               # wait for job thread to finish
+               @thread.join if not @thread.nil?
+
                if not @log.nil? then
                        @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
                end
index f8d890a57b010120158e8f55ac9146b6f7b91fe9..b85e88240359fc87bd05108f0d1f3fd57d121ce1 100644 (file)
@@ -217,14 +217,7 @@ class JobManager
                @server.log.info "Creating thread for canceling the job \"#{job.id}\""
                Thread.new do
                        begin
-                               job.kill_sub_process
-
-                               job.sub_jobs.select{|x| x.event == "NONE" and x.status != "FINISHED" and x.status != "ERROR" and x.status != "CANCELED" }.each do |sub|
-                                       sub.event = "CANCEL"
-                               end
-                               job.thread.join if not job.thread.nil?
-
-                               # job cacncel
+                               # job cancel
                                job.cancel
 
                                # cancel finished
index 07a269745db58c8872ede059ebb0ade39e5c31fd..26b9c39c804ba495534380bcdca9803d0b991f3b 100644 (file)
@@ -43,7 +43,7 @@ require "CommonJob.rb"
 class MultiBuildJob < CommonJob
 
        attr_accessor :source_path
-       attr_accessor :pkgsvr_client, :thread
+       attr_accessor :pkgsvr_client
 
        # initialize
        def initialize (server)
index 7045466a1af91129110fc76e1c20acf7a54941ec..3ef38d10642f51cd775a726758cfa7f30efc1581 100644 (file)
@@ -43,7 +43,7 @@ require "CommonJob.rb"
 class RegisterPackageJob < CommonJob
 
        attr_accessor :source_path
-       attr_accessor :pkgsvr_client, :thread, :pkg_type
+       attr_accessor :pkgsvr_client, :pkg_type
        attr_accessor :pkg_name, :pkginfo
        attr_accessor :no_reverse
 
@@ -233,14 +233,6 @@ class RegisterPackageJob < CommonJob
        end
 
 
-       #cancel
-       def cancel()
-               if not @log.nil? then
-                       @log.info( "JOB is canceled by cancel operation !!", Log::LV_USER)
-               end
-       end
-
-
        # check building is possible
        def can_be_built_on?(host_os)
                return true
index 7602874a1f43f6a4c7db57e7a8b4cf8466209d0d..d1133e35e9f64bebc61c32aa13ff0acd075762a8 100644 (file)
@@ -8,36 +8,35 @@ Requiest service to build-server command-line tool.
 Usage: build-cli <SUBCOMMAND> [OPTS] or build-cli (-h|-v)
 
 Subcommands:
-build         Build and create package.
-query         Query information about build-server.
-query-system  Query system information about build-server.
-query-project Query project information about build-server.
-query-job     Query job information about build-server.
-query-log     Query log contents about job in build-server.
-cancel        Cancel a building project.
-register      Register the package to the build-server.
+       build         Build and create package.
+       query         Query information about build-server.
+       query-system  Query system information about build-server.
+       query-project Query project information about build-server.
+       query-job     Query job information about build-server.
+       query-log     Query log contents about job in build-server.
+       cancel        Cancel a building project.
+       register      Register the package to the build-server.
 
 Subcommand usage:
-build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email] [-V]
-build-cli query -d <server address>
-build-cli query-system -d <server address>
-build-cli query-project -d <server address>
-build-cli query-job -d <server address>
-build-cli query-log -d <server address> -j <job number>
-build-cli cancel -j <job number> -d <server address> [-w <password>]
-build-cli register -P <package file> -d <server address>  [-t <ftp server url>] [-w <password>] [-D <distribution name>] [-U user-email]
+       build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email]
+       build-cli query -d <server address>
+       build-cli query-system -d <server address>
+       build-cli query-project -d <server address>
+       build-cli query-job -d <server address>
+       build-cli query-log -d <server address> -j <job number>
+       build-cli cancel -j <job number> -d <server address> [-w <password>] [-U user-email]
+       build-cli register -P <package file> -d <server address>  [-t <ftp server url>] [-w <password>] [-D <distribution name>] [-U user-email]
 
 Options:
--N, --project <project name>     project name
--d, --address <server address>   build server address: 127.0.0.1:2224
--o, --os <operating system>      target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64
---async                      asynchronous job
--j, --job <job number>           job number
--w, --passwd <password>          password for managing project
--P, --pkg <package file>         package file path
--D, --dist <distribution name>   distribution name
--t, --ftp <ftp server url>       ftp server url: ftp://dibsftp:dibsftp@127.0.0.1
--U, --user <user email>          user email infomation
--V, --verbose                    verbose mode
--h, --help                       display help
--v, --version                    display version
+        -N, --project <project name>     project name
+        -d, --address <server address>   build server address: 127.0.0.1:2224
+        -o, --os <operating system>      target operating system: ubuntu-32/ubuntu-64/windows-32/windows-64/macos-64
+            --async                      asynchronous job
+        -j, --job <job number>           job number
+        -w, --passwd <password>          password for managing project
+        -P, --pkg <package file>         package file path
+        -D, --dist <distribution name>   distribution name
+        -t, --ftp <ftp server url>       ftp server url: ftp://dibsftp:dibsftp@127.0.0.1
+        -U, --user <user email>          user email infomation
+        -h, --help                       display help
+        -v, --version                    display version