--- /dev/null
+=begin
+
+ DistSync.rb
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require "fileutils"
+require "thread"
+$LOAD_PATH.unshift File.dirname(__FILE__)
+$LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))+"/common"
+require "packageServer.rb"
+require "Action.rb"
+require "ScheduledActionHandler.rb"
+
+class DistSyncAction < Action
+
+ def initialize(time, pkgserver, dist_name )
+ super(time, pkgserver.sync_interval)
+
+ @pkgserver = pkgserver
+ @dist_name = dist_name
+ end
+
+
+ def init
+ end
+
+
+ def execute
+
+ # Start to clean job
+ @pkgserver.log.info "Executing sync action for the #{@dist_name}"
+
+ # update pkg info
+ @pkgserver.reload_dist_package
+
+ # sync
+ @pkgserver.sync( @dist_name, false )
+ end
+end
+
+
+class DistSync
+ attr_accessor :quit
+
+ # init
+ def initialize( server )
+ @server = server
+ @handler = ScheduledActionHandler.new
+ end
+
+ # start thread
+ def start()
+ # scan all sync distribution
+ @server.distribution_list.each do |dist|
+ # if dist does not have parent server then skip sync
+ if dist.server_url.empty? then next end
+
+ time = Time.now
+ @server.log.info "Registered sync-action for dist : #{dist.name}"
+ @handler.register(DistSyncAction.new(time, @server, dist.name))
+ end
+
+ # start handler
+ @handler.start
+ end
+end
# copy package list
for os in @support_os_list
- FileUtils.copy( "#{snapshot_path}/#{PKG_LIST_FILE_PREFIX}#{os}", \
- "#{@location}/snapshots/#{name}/#{PKG_LIST_FILE_PREFIX}#{os}" )
+ FileUtils.copy_file( "#{snapshot_path}/#{PKG_LIST_FILE_PREFIX}#{os}",
+ "#{@location}/snapshots/#{name}/#{PKG_LIST_FILE_PREFIX}#{os}" )
end
# copy archive package list
- FileUtils.copy( "#{snapshot_path}/#{ARCHIVE_PKG_FILE}", \
- "#{@location}/snapshots/#{name}/#{ARCHIVE_PKG_FILE}" )
+ FileUtils.copy_file( "#{snapshot_path}/#{ARCHIVE_PKG_FILE}",
+ "#{@location}/snapshots/#{name}/#{ARCHIVE_PKG_FILE}" )
+
+ # update snapshot.info file information
+ tmp_file_name = @location + "/temp/." + Utils.create_uniq_name
+ # error check
+ if File.exist? tmp_file_name then
+ raise "snapshot temp file name already exist"
+ end
- File.open(@snapshot_info_file_path, "a") do |f|
+ FileUtils.copy_file( @snapshot_info_file_path, tmp_file_name )
+ File.open( tmp_file_name, "a" ) do |f|
f.puts "name : #{name}"
f.puts "time : #{Time.now.strftime("%Y%m%d%H%M%S")}"
if from_cmd then
f.puts "path : /snapshots/#{name}"
f.puts
end
+ FileUtils.mv( tmp_file_name, @snapshot_info_file_path, :force => true )
+ # snapshot is generated
@log.output( "snapshot is generated : #{@location}/snapshots/#{name}", Log::LV_USER)
return name
end
def sync(force)
+ pkg_list_update_flag = false
+
# check distribution's server_url
if @server_url.empty? then
@log.error("This distribution has not remote server", Log::LV_USER)
- return
+ return false
end
# generate client class
full_pkg_name_list = server_pkg_name_list + local_pkg_name_list
full_pkg_name_list.each do |pkg_name|
- sync_package( pkg_name, client, os, force )
+ ret = sync_package( pkg_name, client, os, force )
+ if ret then pkg_list_update_flag = true end
end
end
- write_all_pkg_list()
+ if pkg_list_update_flag then
+ write_all_pkg_list()
+ return true
+ else
+ return false
+ end
end
def sync_archive_pkg
client = Client.new( @server_url, "#{@location}/source", @log )
download_list = client.archive_pkg_list - @archive_pkg_list
+
+ # if update list is empty then return false
+ if download_list.empty? then return false end
+
download_list.each do |pkg|
file = client.download_dep_source(pkg)
if file.nil?
end
write_archive_pkg_list()
+
+ return true
end
def add_os(os)
version_cmp = Utils.compare_version( local_pkg.version, server_pkg.version )
if ( version_cmp.eql? 0 ) then
# version is same then skip update
- return
+ return false
end
+
if ( local_pkg.origin.eql? "local" ) then
if not force then
# local_pkg is generated from local and not force mode then skip update
- return
+ return false
end
end
sync_package2( server_pkg, client, os, force )
+ return true
# if package exist only server
elsif ( not server_pkg.nil? ) then
sync_package2( server_pkg, client, os, force )
+ return true
# if package exist only local
elsif ( not local_pkg.nil? ) then
# if local pkg is generated from local then skip
if local_pkg.origin.eql? "local" then
- next
+ return false
end
# package remove
@pkg_hash_os[os].delete(pkg_name)
+ return true
else
raise RuntimeError,"hash merge error!"
end
+
+ return false
end
def sync_package2( pkg, client, os, force )
require "client"
require "utils"
require "mail"
+require "DistSync"
class PackageServer
attr_accessor :id, :location, :log, :integrity
attr_accessor :finish, :port
attr_accessor :incoming_path
+ attr_accessor :distribution_list
+ attr_accessor :sync_interval
# initialize
def initialize (id)
@port = 3333
@test_time=0 #test time in mili-seconds
@lock_file=nil
+ @sync_interval = 3600
update_config_information(id)
# create server configure file
File.open( @config_file_path, "w" ) do |f|
f.puts "location : #{@location}"
- f.puts "integrity check : YES"
+ f.puts "integrity check : #{@integrity}"
+ f.puts "auto sync interval : #{@sync_interval}"
f.puts "server_url : #{dist_name} -> #{server_url}"
end
# move file to package server
binary_pkg_file_path_list.each do |l|
if test_flag then
- FileUtils.cp( l, "#{distribution.location}/temp/" )
+ FileUtils.copy_file( l, "#{distribution.location}/temp/#{File.basename(l)}" )
else
- FileUtils.cp( l, "#{distribution.location}/binary/" )
+ FileUtils.copy_file( l, "#{distribution.location}/binary/#{File.basename(l)}" )
end
end
end
@lock_file = Utils.file_lock(distribution.lock_file_name)
- distribution.sync(mode)
- distribution.sync_archive_pkg
- Utils.file_unlock(@lock_file)
+ ret1 = distribution.sync(mode)
+ ret2 = distribution.sync_archive_pkg
+ if ret1 or ret2 then
+ distribution.generate_snapshot("", "", false)
+ end
@log.output( "package server [#{@id}]'s distribution [#{dist_name}] has been synchronized.", Log::LV_USER )
+
+ Utils.file_unlock(@lock_file)
end
def add_distribution( dist_name, server_url, clone )
# start server daemon
def start( port )
- # set job request listener
- @log.info "Setting listener..."
-
+ @log.info "Package server Start..."
# set port number. default port is 3333
@port = port
+ # set job request listener
+ @log.info "Setting listener..."
listener = SocketRegisterListener.new(self)
listener.start
+
+ # set auto sync
+ @log.info "Setting auto sync..."
+ autosync = DistSync.new(self)
+ autosync.start
# main loop
@log.info "Entering main loop..."
@location = l.split(" :")[1].strip
elsif l.start_with?( "integrity check :") then
@integrity = l.split(" :")[1].strip.upcase
+ elsif l.start_with?( "auto sync interval :" ) then
+ @sync_interval = l.split(" :")[1].strip.to_i
elsif l.start_with?( "server_url :" ) then
info = l.split(" :")[1].split("->")
@dist_to_server_url[info[0].strip] = info[1].strip
@log.info "[#{dist_name}] distribution creation. using local server [#{server_url}]"
end
- distribution.sync(false)
- distribution.sync_archive_pkg
+ ret1 = distribution.sync(false)
+ ret2 = distribution.sync_archive_pkg
+ if ret1 or ret2 then
+ distribution.generate_snapshot("", "", false)
+ end
else
@log.info "generate package server do not using remote package server"