Copy execution environment to Poseidon on create and update

When creating or updating an execution environment, an API call to
Poseidon is made with the necessary information to create the
corresponding Nomad job.

If runner management is configured, his will display a warning
(currently in the same color as if it were a success) in the UI, if the
API call fails. The environment is saved even if it fails.
If runner management is not configured, this warning will not be created.
This commit is contained in:
Konrad Hanff
2021-06-01 14:07:35 +02:00
committed by Sebastian Serth
parent b762c73ddd
commit 90fac7b94c
10 changed files with 100 additions and 13 deletions

View File

@ -5,10 +5,13 @@ module CommonBehavior
@object = options[:object]
respond_to do |format|
if @object.save
yield if block_given?
notice = t('shared.object_created', model: @object.class.model_name.human)
if block_given?
result = yield
notice = result if result.present?
end
path = options[:path].try(:call) || @object
respond_with_valid_object(format, notice: t('shared.object_created', model: @object.class.model_name.human),
path: path, status: :created)
respond_with_valid_object(format, notice: notice, path: path, status: :created)
else
respond_with_invalid_object(format, template: :new)
end
@ -42,9 +45,13 @@ path: path, status: :created)
@object = options[:object]
respond_to do |format|
if @object.update(options[:params])
notice = t('shared.object_updated', model: @object.class.model_name.human)
if block_given?
result = yield
notice = result if result.present?
end
path = options[:path] || @object
respond_with_valid_object(format, notice: t('shared.object_updated', model: @object.class.model_name.human),
path: path, status: :ok)
respond_with_valid_object(format, notice: notice, path: path, status: :ok)
else
respond_with_invalid_object(format, template: :edit)
end

View File

@ -3,6 +3,8 @@
class ExecutionEnvironmentsController < ApplicationController
include CommonBehavior
RUNNER_MANAGEMENT_PRESENT = CodeOcean::Config.new(:code_ocean).read[:runner_management].present?
before_action :set_docker_images, only: %i[create edit new update]
before_action :set_execution_environment, only: MEMBER_ACTIONS + %i[execute_command shell statistics]
before_action :set_testing_framework_adapters, only: %i[create edit new update]
@ -15,7 +17,9 @@ class ExecutionEnvironmentsController < ApplicationController
def create
@execution_environment = ExecutionEnvironment.new(execution_environment_params)
authorize!
create_and_respond(object: @execution_environment)
create_and_respond(object: @execution_environment) do
copy_execution_environment_to_poseidon
end
end
def destroy
@ -105,7 +109,7 @@ class ExecutionEnvironmentsController < ApplicationController
def execution_environment_params
if params[:execution_environment].present?
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :memory_limit, :name, :network_enabled, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge(
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :memory_limit, :cpu_limit, :name, :network_enabled, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge(
user_id: current_user.id, user_type: current_user.class.name
)
end
@ -155,6 +159,15 @@ class ExecutionEnvironmentsController < ApplicationController
end
def update
update_and_respond(object: @execution_environment, params: execution_environment_params)
update_and_respond(object: @execution_environment, params: execution_environment_params) do
copy_execution_environment_to_poseidon
end
end
def copy_execution_environment_to_poseidon
unless RUNNER_MANAGEMENT_PRESENT && @execution_environment.copy_to_poseidon
t('execution_environments.form.errors.not_synced_to_poseidon')
end
end
private :copy_execution_environment_to_poseidon
end