Add button to synchronize all execution environments

This adds a button to the execution environment index page that, when
clicked, causes all execution environments to be synchronized to the
runner management (Poseidon) by creating or replacing them.

CodeOcean does not synchronize it's execution environments on startup or
when a new runner management configuration is used for the first time.
The administrator has to manually start this process by pressing this
button.

The equivalent for syncing just one execution environment is updating
it.
This commit is contained in:
Konrad Hanff
2021-06-07 16:31:15 +02:00
committed by Sebastian Serth
parent 0978a3be83
commit 598de3bcff
6 changed files with 33 additions and 1 deletions

View File

@ -164,6 +164,19 @@ class ExecutionEnvironmentsController < ApplicationController
end end
end end
def synchronize_all_to_poseidon
authorize ExecutionEnvironment
return unless RUNNER_MANAGEMENT_PRESENT
success = ExecutionEnvironment.all.map(&:copy_to_poseidon).all?
if success
redirect_to ExecutionEnvironment, notice: t('execution_environments.index.synchronize_all.success')
else
redirect_to ExecutionEnvironment, alert: t('execution_environments.index.synchronize_all.failure')
end
end
def copy_execution_environment_to_poseidon def copy_execution_environment_to_poseidon
unless RUNNER_MANAGEMENT_PRESENT && @execution_environment.copy_to_poseidon unless RUNNER_MANAGEMENT_PRESENT && @execution_environment.copy_to_poseidon
t('execution_environments.form.errors.not_synced_to_poseidon') t('execution_environments.form.errors.not_synced_to_poseidon')

View File

@ -8,4 +8,8 @@ class ExecutionEnvironmentPolicy < AdminOnlyPolicy
[:index?].each do |action| [:index?].each do |action|
define_method(action) { admin? || teacher? } define_method(action) { admin? || teacher? }
end end
def synchronize_all_to_poseidon?
admin?
end
end end

View File

@ -1,4 +1,9 @@
h1 = ExecutionEnvironment.model_name.human(count: 2) h1.d-inline-block = ExecutionEnvironment.model_name.human(count: 2)
- if ExecutionEnvironment::RUNNER_MANAGEMENT_PRESENT
= button_to( { action: :synchronize_all_to_poseidon, method: :post }, { form_class: 'float-right mb-2', class: 'btn btn-success' })
i.fa.fa-upload
= t('execution_environments.index.synchronize_all.button')
.table-responsive .table-responsive
table.table table.table

View File

@ -287,6 +287,10 @@ de:
not_synced_to_poseidon: Die Ausführungsumgebung wurde erstellt, aber aufgrund eines Fehlers nicht zu Poseidon synchronisiert. not_synced_to_poseidon: Die Ausführungsumgebung wurde erstellt, aber aufgrund eines Fehlers nicht zu Poseidon synchronisiert.
index: index:
shell: Shell shell: Shell
synchronize_all:
button: Alle synchronisieren
success: Alle Ausführungsumgebungen wurden erfolgreich synchronisiert.
failure: Beim Synchronisieren mindestens einer Ausführungsumgebung ist ein Fehler aufgetreten.
shell: shell:
command: Befehl command: Befehl
headline: Shell headline: Shell

View File

@ -287,6 +287,10 @@ en:
not_synced_to_poseidon: The ExecutionEnvironment was created but not synced to Poseidon due to an error. not_synced_to_poseidon: The ExecutionEnvironment was created but not synced to Poseidon due to an error.
index: index:
shell: Shell shell: Shell
synchronize_all:
button: Synchronize all
success: All execution environemnts were synchronized successfully.
failure: At least one execution environment could not be synchronised due to an error.
shell: shell:
command: Command command: Command
headline: Shell headline: Shell

View File

@ -66,6 +66,8 @@ Rails.application.routes.draw do
post 'shell', as: :execute_command, action: :execute_command post 'shell', as: :execute_command, action: :execute_command
get :statistics get :statistics
end end
post :synchronize_all_to_poseidon, on: :collection
end end
post '/import_exercise' => 'exercises#import_exercise' post '/import_exercise' => 'exercises#import_exercise'