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.
30 $LOAD_PATH.unshift File.dirname(__FILE__)
31 require "RemoteBuildJob.rb"
32 require "BuildComm.rb"
35 class RemoteBuildServer
36 attr_accessor :ip, :port, :status, :host_os
37 attr_accessor :max_working_jobs, :working_jobs, :waiting_jobs
38 attr_accessor :pkgserver_url, :path
41 def initialize(ip, port, parent)
44 @status = "DISCONNECTED"
45 @host_os = Utils::HOST_OS
49 @pkgserver_url = parent.pkgserver_url
51 @file_transfer_cnt_mutex = Mutex.new
52 @file_transfer_cnt = 0
56 # check the job can be built on this server
60 if job.can_be_built_on? @host_os then
68 # query remote server info & update server state
72 #@status = "DISCONNECTED"
73 client = BuildCommClient.create( @ip, @port )
74 if client.nil? then return end
75 if client.send("QUERY|SYSTEM") then
76 result = client.read_lines do |l|
77 tok = l.split(",").map { |x| x.strip }
79 @max_working_jobs = tok[1].to_i
82 if not result then @status = "DISCONNECTED" end
85 if @status == "DISCONNECTED" then return end
90 client = BuildCommClient.create( @ip, @port )
91 if client.nil? then return end
92 if client.send("QUERY|JOB") then
93 result = client.read_lines do |l|
94 tok = l.split(",").map { |x| x.strip }
98 new_job = RemoteBuildJob.new(job_id,self)
100 when "WAITING", "JUST_CREATED", "INITIALIZING"
101 @waiting_jobs.push new_job
103 @working_jobs.push new_job
105 #puts "Uncontrolled status"
108 if not result then @status = "DISCONNECTED" end
110 @status = "DISCONNECTED"
116 # return available working slot
117 def get_number_of_empty_room
118 return @max_working_jobs - @working_jobs.count
122 # check there are working jobs
124 return (@working_jobs.count > 0)
128 # check there are waiting jobs
130 return (@waiting_jobs.count > 0)
134 def add_file_transfer()
135 @file_transfer_cnt_mutex.synchronize {
136 @file_transfer_cnt += 1
140 def remove_file_transfer()
141 @file_transfer_cnt_mutex.synchronize {
142 @file_transfer_cnt -= 1
146 def get_file_transfer_cnt()
147 return @file_transfer_cnt