3 SocketJobRequestListener.rb
5 Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
8 Taejun Ha <taejun.ha@samsung.com>
9 Jiil Hyoun <jiil.hyoun@samsung.com>
10 Donghyuk Yang <donghyuk.yang@samsung.com>
11 DongHee Yang <donghee.yang@samsung.com>
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
29 $LOAD_PATH.unshift File.dirname(__FILE__)
30 require "GitBuildJob.rb"
31 require "LocalBuildJob.rb"
33 require "BuildComm.rb"
36 class SocketJobRequestListener
39 def initialize (parent)
40 @parent_server = parent
43 @log = @parent_server.log
48 @thread = Thread.new {
66 server = BuildCommServer.new(@parent_server.port, @log)
68 @log.info "Server creation failed"
73 @log.info "Entering Control Listening Loop ... "
75 server.wait_for_connection(@finish_loop) do |req|
76 handle_job_request( req )
84 # wait for job requests
85 def wait_for_job_requests
87 req_list.push @tcp_server.accept
94 def handle_job_request( req )
98 if req_line.nil? then return end
102 if req_line.split(",").count > 0 then
103 cmd = req_line.split(",")[0].strip
108 handle_cmd_build( req_line, req )
110 handle_cmd_resolve( req_line, req )
112 handle_cmd_query( req_line, req )
114 @log.info "Received Unknown REQ: #{req_line}"
115 raise "Unknown request: #{req_line}"
122 def handle_cmd_build( line, req )
123 tok = line.split(",").map { |x| x.strip }
124 if tok.count < 4 then
125 @log.info "Received Wrong REQ: #{line}"
126 raise "Invalid request format is used: #{line}"
130 # BUILD,GIT,repos,commit,os,url,async
132 @log.info "Received BUILD GIT => #{tok[2]}"
134 # check asynchronous job
135 async = (not tok[6].nil? and tok[6]=="YES" ? true:false)
137 new_job = GitBuildJob.new( tok[2], tok[3], tok[4], tok[5], [], @parent_server, nil, nil, false)
139 new_job = GitBuildJob.new( tok[2], tok[3], tok[4], tok[5], [], @parent_server, nil, req, false)
141 BuildCommServer.send_begin(req)
143 # start job. If log url is supported, show it
144 if not @parent_server.job_log_url.empty? then
145 new_job.log.info( "Added new job \"#{new_job.id}\"! Check following URL", Log::LV_USER)
146 new_job.log.info( " * Log URL : #{@parent_server.job_log_url}/#{new_job.id}/log", Log::LV_USER)
148 new_job.log.info( "Added new job \"#{new_job.id}\"!", Log::LV_USER)
151 # if asynchronouse, quit connection
153 if not @parent_server.job_log_url.empty? then
154 req.puts ( "Info: Added new job \"#{new_job.id}\"! Check following URL")
155 req.puts ( "Info: * Log URL : #{@parent_server.job_log_url}/#{new_job.id}/log")
157 req.puts( "Info: Added new job \"#{new_job.id}\"!")
160 BuildCommServer.send_end(req)
161 BuildCommServer.disconnect(req)
165 @parent_server.add_job( new_job )
167 # BUILD,LOCAL,path,os,url
169 @log.info "Received BUILD LOCAL => #{tok[2]}"
171 BuildCommServer.send_begin(req)
172 @parent_server.add_job(
173 LocalBuildJob.new( tok[2], tok[3], tok[4], [], @parent_server, nil, req, false))
175 @log.info "Received Wrong REQ: #{line}"
176 raise "Invalid request format is used: #{line}"
182 def handle_cmd_resolve( line ,req)
183 tok = line.split(",").map { |x| x.strip }
184 if tok.count < 4 then
185 @log.info "Received Wrong REQ: #{line}"
186 raise "Invalid request format is used: #{line}"
190 # RESOLVE,GIT,repos,commit,os,url
192 @log.info "Received RESOLVE GIT => #{tok[2]}"
194 BuildCommServer.send_begin(req)
195 @parent_server.add_job(
196 GitBuildJob.new( tok[2], tok[3], tok[4], tok[5], [], @parent_server, nil, req, true))
197 # RESOLVE,LOCAL,path,os,url
199 @log.info "Received RESOLVE LOCAL => #{tok[2]}"
201 BuildCommServer.send_begin(req)
202 @parent_server.add_job(
203 LocalBuildJob.new( tok[2], tok[3], tok[4], [], @parent_server, nil, req, true))
205 @log.info "Received Wrong REQ: #{line}"
206 raise "Invalid request format is used: #{line}"
212 def handle_cmd_query( line, req )
213 tok = line.split(",").map { |x| x.strip }
214 if tok.count < 2 then
215 @log.info "Received Wrong REQ: #{line}"
216 raise "Invalid request format is used: #{line}"
222 #puts "Received QUERY JOB"
224 BuildCommServer.send_begin(req)
225 for job in @parent_server.working_jobs
226 BuildCommServer.send(req,"WORKING,#{job.id},#{job.pkginfo.packages[0].source}")
228 for job in @parent_server.waiting_jobs
229 BuildCommServer.send(req,"WAITING,#{job.id},#{job.pkginfo.packages[0].source}")
231 for job in @parent_server.remote_jobs
232 BuildCommServer.send(req,"REMOTE ,#{job.id},#{job.pkginfo.packages[0].source}")
234 BuildCommServer.send_end(req)
235 BuildCommServer.disconnect(req)
239 #puts "Received QUERY SYSTEM"
241 BuildCommServer.send_begin(req)
242 BuildCommServer.send(req,"#{@parent_server.host_os},#{@parent_server.max_working_jobs}")
243 BuildCommServer.send_end(req)
244 BuildCommServer.disconnect(req)
246 @log.info "Received Wrong REQ: #{line}"
247 raise "Invalid request format is used: #{line}"