From 598de3bcff1020d3e82472d8a1ec4d615c535bd9 Mon Sep 17 00:00:00 2001 From: Konrad Hanff Date: Mon, 7 Jun 2021 16:31:15 +0200 Subject: [PATCH] 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. --- .../execution_environments_controller.rb | 13 +++++++++++++ app/policies/execution_environment_policy.rb | 4 ++++ app/views/execution_environments/index.html.slim | 7 ++++++- config/locales/de.yml | 4 ++++ config/locales/en.yml | 4 ++++ config/routes.rb | 2 ++ 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/controllers/execution_environments_controller.rb b/app/controllers/execution_environments_controller.rb index 95132b09..e9a0ba0c 100644 --- a/app/controllers/execution_environments_controller.rb +++ b/app/controllers/execution_environments_controller.rb @@ -164,6 +164,19 @@ class ExecutionEnvironmentsController < ApplicationController 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 unless RUNNER_MANAGEMENT_PRESENT && @execution_environment.copy_to_poseidon t('execution_environments.form.errors.not_synced_to_poseidon') diff --git a/app/policies/execution_environment_policy.rb b/app/policies/execution_environment_policy.rb index 9ed8522c..cf134527 100644 --- a/app/policies/execution_environment_policy.rb +++ b/app/policies/execution_environment_policy.rb @@ -8,4 +8,8 @@ class ExecutionEnvironmentPolicy < AdminOnlyPolicy [:index?].each do |action| define_method(action) { admin? || teacher? } end + + def synchronize_all_to_poseidon? + admin? + end end diff --git a/app/views/execution_environments/index.html.slim b/app/views/execution_environments/index.html.slim index 10501911..9f6d47cc 100644 --- a/app/views/execution_environments/index.html.slim +++ b/app/views/execution_environments/index.html.slim @@ -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.table diff --git a/config/locales/de.yml b/config/locales/de.yml index 344f1d58..abab5b43 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -287,6 +287,10 @@ de: not_synced_to_poseidon: Die Ausführungsumgebung wurde erstellt, aber aufgrund eines Fehlers nicht zu Poseidon synchronisiert. index: 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: command: Befehl headline: Shell diff --git a/config/locales/en.yml b/config/locales/en.yml index 183a1186..dd241006 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -287,6 +287,10 @@ en: not_synced_to_poseidon: The ExecutionEnvironment was created but not synced to Poseidon due to an error. index: 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: command: Command headline: Shell diff --git a/config/routes.rb b/config/routes.rb index 1d578a76..1608ac05 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,6 +66,8 @@ Rails.application.routes.draw do post 'shell', as: :execute_command, action: :execute_command get :statistics end + + post :synchronize_all_to_poseidon, on: :collection end post '/import_exercise' => 'exercises#import_exercise'