diff --git a/app/models/submission.rb b/app/models/submission.rb index 6b8a4fd8..ead754cd 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -195,7 +195,8 @@ class Submission < ApplicationRecord def prepared_runner request_time = Time.zone.now begin - runner = Runner.for(user, exercise.execution_environment) + execution_environment = AwsStudy.get_execution_environment(user, exercise) + runner = Runner.for(user, execution_environment) files = collect_files files.reject!(&:teacher_defined_assessment?) if cause == 'run' Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Copying files to Runner #{runner.id} for #{user_type} #{user_id} and Submission #{id}." } diff --git a/lib/aws_study.rb b/lib/aws_study.rb new file mode 100644 index 00000000..48b732b1 --- /dev/null +++ b/lib/aws_study.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class AwsStudy + def self.get_for(exercise) + java20_collection = ExerciseCollection.find_by(name: 'java2020', id: 11) + java20_bonus_collection = ExerciseCollection.find_by(name: 'java2020-bonusexercise', id: 12) + + exercise.exercise_collections.any? {|ec| [java20_collection, java20_bonus_collection].include?(ec) } + end + + def self.get_execution_environment(user, exercise) + # Poseidon is disabled and thus no AWS support available + return exercise.execution_environment unless Runner::Strategy::Poseidon == Runner.strategy_class + + java20_exercise = get_for(exercise) + # Exercise is not part of the experiment + return exercise.execution_environment unless java20_exercise + + user_group = UserGroupSeparator.get_aws_group(user.id) + case user_group + when :use_aws + # AWS functions are currently identified with their name + aws_function = ExecutionEnvironment.find_by(docker_image: 'java11Exec') + # Fallback to the default execution environment if no AWS function is found + aws_function || exercise.execution_environment + else # :no_aws + exercise.execution_environment + end + end +end diff --git a/lib/user_group_separator.rb b/lib/user_group_separator.rb index c82dead0..32219ba6 100644 --- a/lib/user_group_separator.rb +++ b/lib/user_group_separator.rb @@ -32,4 +32,16 @@ class UserGroupSeparator :no_community_solution end end + + # Different user groups for using AWS lambda functions instead of Nomad based on the user_id + # This test is independent from any other A/B Test + def self.get_aws_group(user_id) + user_group = user_id % 2 # => 0, 1 + case user_group + when 0 + :no_aws + else # 1 + :use_aws + end + end end