Merge remote-tracking branch 'origin/master' into statistics
This commit is contained in:
@ -1127,6 +1127,10 @@ $(function() {
|
||||
|
||||
var initTurtle = function() {
|
||||
// todo guard clause if turtle is not required for the current exercise
|
||||
|
||||
// clear canvas
|
||||
// turtlecanvas.getContext("2d").clearRect(0, 0, turtlecanvas.width, turtlecanvas.height);
|
||||
|
||||
turtlescreen = new Turtle(websocket, turtlecanvas);
|
||||
if ($('#run').isPresent()) {
|
||||
$('#run').bind('click', hideCanvas);
|
||||
|
@ -112,13 +112,13 @@ class SubmissionsController < ApplicationController
|
||||
end
|
||||
|
||||
tubesock.onmessage do |data|
|
||||
Rails.logger.info("Client sending: " + data)
|
||||
Rails.logger.debug("Client sending: " + data)
|
||||
# Check wether the client send a JSON command and kill container
|
||||
# if the command is 'exit', send it to docker otherwise.
|
||||
begin
|
||||
parsed = JSON.parse(data)
|
||||
if parsed['cmd'] == 'exit'
|
||||
Rails.logger.info("Client exited container.")
|
||||
Rails.logger.debug("Client exited container.")
|
||||
@docker_client.exit_container(result[:container])
|
||||
else
|
||||
socket.send data
|
||||
@ -209,6 +209,7 @@ class SubmissionsController < ApplicationController
|
||||
end
|
||||
|
||||
def stop
|
||||
Rails.logger.debug('stopping submission ' + @submission)
|
||||
container = Docker::Container.get(params[:container_id])
|
||||
DockerClient.destroy_container(container)
|
||||
rescue Docker::Error::NotFoundError
|
||||
|
@ -1,6 +1,7 @@
|
||||
Rails.application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
||||
config.web_console.whitelisted_ips = '192.168.0.0/16'
|
||||
# In the development environment your application's code is reloaded on
|
||||
# every request. This slows down response time but is perfect for development
|
||||
# since you don't have to restart the web server when you make code changes.
|
||||
|
@ -97,6 +97,7 @@ class DockerClient
|
||||
container.status = :created
|
||||
container
|
||||
rescue Docker::Error::NotFoundError => error
|
||||
Rails.logger.info('create_container: Got Docker::Error::NotFoundError: ' + error)
|
||||
destroy_container(container)
|
||||
#(tries += 1) <= RETRY_COUNT ? retry : raise(error)
|
||||
end
|
||||
@ -176,7 +177,7 @@ class DockerClient
|
||||
timeout = @execution_environment.permitted_execution_time.to_i # seconds
|
||||
sleep(timeout)
|
||||
if container.status != :returned
|
||||
Rails.logger.info("Killing container after timeout of " + timeout.to_s + " seconds.")
|
||||
Rails.logger.info('Killing container after timeout of ' + timeout.to_s + ' seconds.')
|
||||
# send timeout to the tubesock socket
|
||||
if(@tubesock)
|
||||
@tubesock.send_data JSON.dump({'cmd' => 'timeout'})
|
||||
@ -187,6 +188,7 @@ class DockerClient
|
||||
end
|
||||
|
||||
def exit_container(container)
|
||||
Rails.logger.debug('exiting container ' + container.to_s)
|
||||
# exit the timeout thread if it is still alive
|
||||
if(@thread && @thread.alive?)
|
||||
@thread.exit
|
||||
@ -196,6 +198,7 @@ class DockerClient
|
||||
end
|
||||
|
||||
def kill_container(container)
|
||||
Rails.logger.info('killing container ' + container.to_s)
|
||||
# remove container from pool, then destroy it
|
||||
if (DockerContainerPool.config[:active])
|
||||
DockerContainerPool.remove_from_all_containers(container, @execution_environment)
|
||||
@ -215,7 +218,7 @@ class DockerClient
|
||||
"""
|
||||
Run commands by attaching a websocket to Docker.
|
||||
"""
|
||||
command = submission.execution_environment.send(:"run_command") % command_substitutions(filename)
|
||||
command = submission.execution_environment.run_command % command_substitutions(filename)
|
||||
create_workspace_files = proc { create_workspace_files(container, submission) }
|
||||
execute_websocket_command(command, create_workspace_files, block)
|
||||
end
|
||||
@ -224,7 +227,7 @@ class DockerClient
|
||||
"""
|
||||
Stick to existing Docker API with exec command.
|
||||
"""
|
||||
command = submission.execution_environment.send(:"test_command") % command_substitutions(filename)
|
||||
command = submission.execution_environment.test_command % command_substitutions(filename)
|
||||
create_workspace_files = proc { create_workspace_files(container, submission) }
|
||||
execute_command(command, create_workspace_files, block)
|
||||
end
|
||||
@ -282,6 +285,7 @@ class DockerClient
|
||||
end
|
||||
|
||||
def self.return_container(container, execution_environment)
|
||||
Rails.logger.debug('returning container ' + container.to_s)
|
||||
clean_container_workspace(container)
|
||||
DockerContainerPool.return_container(container, execution_environment)
|
||||
container.status = :returned
|
||||
|
@ -30,14 +30,15 @@ class DockerContainerPool
|
||||
if(!@containers[execution_environment.id].include?(container))
|
||||
@containers[execution_environment.id]+=[container]
|
||||
else
|
||||
Rails.logger.info('failed trying to add existing container ' + container.to_s)
|
||||
Rails.logger.info('failed trying to add existing container ' + container.to_s + ' to execution_environment ' + execution_environment.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def self.create_container(execution_environment)
|
||||
container = DockerClient.create_container(execution_environment)
|
||||
container.status = 'available'
|
||||
container
|
||||
container = DockerClient.create_container(execution_environment)
|
||||
container.status = 'available'
|
||||
Rails.logger.debug('created container ' + container.to_s + ' for execution environment ' + execution_environment.to_s)
|
||||
container
|
||||
end
|
||||
|
||||
def self.return_container(container, execution_environment)
|
||||
@ -45,7 +46,7 @@ class DockerContainerPool
|
||||
if(@containers[execution_environment.id] && !@containers[execution_environment.id].include?(container))
|
||||
@containers[execution_environment.id].push(container)
|
||||
else
|
||||
Rails.logger.info('trying to return existing container ' + container.to_s)
|
||||
Rails.logger.info('trying to return existing container ' + container.to_s + ' to execution_environment ' + execution_environment.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
@ -53,11 +54,11 @@ class DockerContainerPool
|
||||
# if pooling is active, do pooling, otherwise just create an container and return it
|
||||
if config[:active]
|
||||
container = @containers[execution_environment.id].try(:shift) || nil
|
||||
Rails.logger.info('get_container fetched container ' + container.to_s)
|
||||
Rails.logger.debug('get_container fetched container ' + container.to_s + ' for execution environment ' + execution_environment.to_s)
|
||||
# just access and the following if we got a container. Otherwise, the execution_environment might be just created and not fully exist yet.
|
||||
if(container)
|
||||
Rails.logger.info('get_container remaining avail. containers: ' + @containers[execution_environment.id].size.to_s)
|
||||
Rails.logger.info('get_container all container count: ' + @all_containers[execution_environment.id].size.to_s)
|
||||
Rails.logger.debug('get_container remaining avail. containers: ' + @containers[execution_environment.id].size.to_s)
|
||||
Rails.logger.debug('get_container all container count: ' + @all_containers[execution_environment.id].size.to_s)
|
||||
end
|
||||
container
|
||||
else
|
||||
@ -82,10 +83,13 @@ class DockerContainerPool
|
||||
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
|
||||
if refill_count > 0
|
||||
Rails.logger.info('adding ' + refill_count.to_s + ' containers for ' + execution_environment.name )
|
||||
Rails.logger.info('Adding ' + refill_count.to_s + ' containers for execution_environment ' + execution_environment.name )
|
||||
c = refill_count.times.map { create_container(execution_environment) }
|
||||
Rails.logger.debug('Created containers: ' + c.to_s )
|
||||
@containers[execution_environment.id] += c
|
||||
@all_containers[execution_environment.id] += c
|
||||
Rails.logger.debug('@containers ' + @containers.object_id.to_s + ' has:'+ @containers[execution_environment.id].to_s)
|
||||
Rails.logger.debug('@all_containers ' + @containers.object_id.to_s + ' has:'+ @all_containers[execution_environment.id].to_s)
|
||||
#refill_count.times.map { create_container(execution_environment) }
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user