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