Added some logs

This commit is contained in:
Jan Renz
2015-04-23 09:54:30 +02:00
parent edbf74b4b9
commit 431b18b526
2 changed files with 13 additions and 2 deletions

View File

@ -80,6 +80,7 @@ class DockerClient
private :create_workspace_file private :create_workspace_file
def self.destroy_container(container) def self.destroy_container(container)
Rails.logger.info('destroying container ' + container.to_s)
container.stop.kill container.stop.kill
container.port_bindings.values.each { |port| PortPool.release(port) } container.port_bindings.values.each { |port| PortPool.release(port) }
FileUtils.rm_rf(local_workspace_path(container)) if local_workspace_path(container) FileUtils.rm_rf(local_workspace_path(container)) if local_workspace_path(container)
@ -188,6 +189,7 @@ class DockerClient
{status: :ok, stderr: stderr.join, stdout: stdout.join} {status: :ok, stderr: stderr.join, stdout: stdout.join}
end end
rescue Timeout::Error rescue Timeout::Error
Rails.logger.info('got timeout error for container ' + container.to_s)
#container.restart if RECYCLE_CONTAINERS #container.restart if RECYCLE_CONTAINERS
DockerContainerPool.remove_from_all_containers(container, @execution_environment) DockerContainerPool.remove_from_all_containers(container, @execution_environment)
@ -201,6 +203,7 @@ class DockerClient
end end
{status: :timeout} {status: :timeout}
ensure ensure
Rails.logger.info('after timeout error ensuring for' + container.to_s)
RECYCLE_CONTAINERS ? return_container(container) : self.class.destroy_container(container) RECYCLE_CONTAINERS ? return_container(container) : self.class.destroy_container(container)
end end
private :send_command private :send_command

View File

@ -30,6 +30,8 @@ class DockerContainerPool
@all_containers[execution_environment.id]+=[container] @all_containers[execution_environment.id]+=[container]
if(!@containers[execution_environment.id].include?(container)) if(!@containers[execution_environment.id].include?(container))
@containers[execution_environment.id]+=[container] @containers[execution_environment.id]+=[container]
else
Rails.logger.info('failed trying to add existing container ' + container.to_s)
end end
end end
@ -43,16 +45,18 @@ class DockerContainerPool
container.status = 'available' container.status = 'available'
unless(@containers[execution_environment.id].include?(container)) unless(@containers[execution_environment.id].include?(container))
@containers[execution_environment.id].push(container) @containers[execution_environment.id].push(container)
else
Rails.logger.info('trying to return existing container ' + container.to_s)
end end
end end
def self.get_container(execution_environment) def self.get_container(execution_environment)
if config[:active] if config[:active]
container = @containers[execution_environment.id].try(:shift) || nil container = @containers[execution_environment.id].try(:shift) || nil
if(!container.nil?) if(!container.nil?)
if ((Time.now - container.start_time).to_i.abs > TIME_TILL_RESTART) if ((Time.now - container.start_time).to_i.abs > TIME_TILL_RESTART)
# remove container from @all_containers # remove container from @all_containers
Rails.logger.info('reinit container after time of life max ' + container.to_s)
remove_from_all_containers(container, execution_environment) remove_from_all_containers(container, execution_environment)
# destroy container # destroy container
@ -61,11 +65,14 @@ class DockerContainerPool
# create new container and add it to @all_containers. will be added to @containers on return_container # create new container and add it to @all_containers. will be added to @containers on return_container
container = create_container(execution_environment) container = create_container(execution_environment)
add_to_all_containers(container, execution_environment) add_to_all_containers(container, execution_environment)
Rails.logger.info('new container is ' + container.to_s)
end end
#container.status = 'used' #container.status = 'used'
end end
Rails.logger.info('fetched container ' + container.to_s)
Rails.logger.info('remaining avail. container ' + @containers[execution_environment.id].size)
Rails.logger.info('all container count' + @all_containers[execution_environment.id].size)
container container
else else
create_container(execution_environment) create_container(execution_environment)
end end
@ -87,6 +94,7 @@ class DockerContainerPool
def self.refill_for_execution_environment(execution_environment) def self.refill_for_execution_environment(execution_environment)
refill_count = [execution_environment.pool_size - @all_containers[execution_environment.id].length, config[:refill][:batch_size]].min refill_count = [execution_environment.pool_size - @all_containers[execution_environment.id].length, config[:refill][:batch_size]].min
Rails.logger.info('adding' + refill_count.to_s + ' containers for ' + execution_environment.name )
c = refill_count.times.map { create_container(execution_environment) } c = refill_count.times.map { create_container(execution_environment) }
@containers[execution_environment.id] += c @containers[execution_environment.id] += c
@all_containers[execution_environment.id] += c @all_containers[execution_environment.id] += c