From 6fe3f899695c85a13b86a2011c9710ae7e9768cc Mon Sep 17 00:00:00 2001 From: Joy Song Date: Sun, 30 Mar 2025 19:51:44 -0400 Subject: [PATCH 1/5] Pass potential amis from Tango over. Still need to store it properly. --- app/controllers/autograders_controller.rb | 2 ++ app/views/autograders/_ec2_settings.html.erb | 1 + 2 files changed, 3 insertions(+) diff --git a/app/controllers/autograders_controller.rb b/app/controllers/autograders_controller.rb index 51c27ff86..3082597da 100755 --- a/app/controllers/autograders_controller.rb +++ b/app/controllers/autograders_controller.rb @@ -37,6 +37,8 @@ def edit tar_path = Rails.root.join("courses", @course.name, @assessment.name, "autograde.tar") @makefile_exists = File.exist?(makefile_path) ? makefile_path : nil @tar_exists = File.exist?(tar_path) ? tar_path : nil + tango_info = TangoClient.info + @tagged_amis = tango_info["tagged_amis"] || [] end action_auth_level :update, :instructor diff --git a/app/views/autograders/_ec2_settings.html.erb b/app/views/autograders/_ec2_settings.html.erb index 9e6467ae6..5eba9582f 100755 --- a/app/views/autograders/_ec2_settings.html.erb +++ b/app/views/autograders/_ec2_settings.html.erb @@ -10,6 +10,7 @@ <%= f.text_field :access_key_id, display_name: "Access Key ID" %> <%= f.text_field :instance_type, display_name: "EC2 Instance Type", help_text: "Type of EC2 instance to be used to run the autograding job. See here for more details".html_safe %> +<%= f.select :access_key, options_for_select(@tagged_amis), {}, { display_name: "AMI" } %> <%= f.submit "Save Settings" %> <%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment), From 2710a492f3dbe8d21f97b52f08e2ca3d5f671fc4 Mon Sep 17 00:00:00 2001 From: Joy Song Date: Sun, 13 Apr 2025 14:26:16 -0400 Subject: [PATCH 2/5] Retrieve tagged AMIs and security groups from Tango. --- app/controllers/jobs_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index d763afc66..0b61f65a9 100755 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -164,6 +164,11 @@ def getjob def tango_status # Obtain overall Tango info and pool status @tango_info = TangoClient.info + + # Obtain tagged AMIs and security groups from Tango + @tagged_amis = @tango_info["tagged_amis"] || [] + @security_groups = @tango_info["security_groups"] || [] + @vm_pool_list = TangoClient.pool # Obtain Image -> Course mapping @img_to_course = {} From 83a44ba1af4213a9ea65922569c07f02899e97d0 Mon Sep 17 00:00:00 2001 From: Joy Song Date: Sun, 13 Apr 2025 14:27:34 -0400 Subject: [PATCH 3/5] Add AMI and security group selection to Autograder setting information. --- app/controllers/autograders_controller.rb | 5 ++++- app/helpers/assessment_autograde_core.rb | 3 ++- db/schema.rb | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/autograders_controller.rb b/app/controllers/autograders_controller.rb index 3082597da..54605d3f2 100755 --- a/app/controllers/autograders_controller.rb +++ b/app/controllers/autograders_controller.rb @@ -19,6 +19,8 @@ def create a.access_key_id = "" a.access_key = "" a.instance_type = "t2.micro" + a.ami = "" + a.security_group = "" end if @autograder.save flash[:success] = "Autograder created." @@ -39,6 +41,7 @@ def edit @tar_exists = File.exist?(tar_path) ? tar_path : nil tango_info = TangoClient.info @tagged_amis = tango_info["tagged_amis"] || [] + @security_groups = tango_info["security_groups"] || [] end action_auth_level :update, :instructor @@ -118,7 +121,7 @@ def set_autograder def autograder_params params[:autograder].permit(:autograde_timeout, :autograde_image, :release_score, :access_key, - :access_key_id, :instance_type) + :access_key_id, :instance_type, :ami, :security_group) end def assessment_params diff --git a/app/helpers/assessment_autograde_core.rb b/app/helpers/assessment_autograde_core.rb index ac90d2a9b..b683dbd93 100644 --- a/app/helpers/assessment_autograde_core.rb +++ b/app/helpers/assessment_autograde_core.rb @@ -177,10 +177,11 @@ def tango_add_job(course, assessment, upload_file_list, callback_url, job_name, job_properties["accessKeyId"] = "" end job_properties["instanceType"] = @autograde_prop.instance_type + job_properties["ami"] = @autograde_prop.ami + job_properties["security_group"] = @autograde_prop.security_group end job_properties = job_properties.to_json - begin response = TangoClient.addjob("#{course.name}-#{assessment.name}", job_properties) rescue TangoClient::TangoException => e diff --git a/db/schema.rb b/db/schema.rb index e6692260c..02b54c235 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2025_01_30_055238) do +ActiveRecord::Schema.define(version: 2025_04_13_141437) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -153,6 +153,8 @@ t.string "access_key", default: "" t.string "access_key_id", default: "" t.boolean "use_access_key", default: false + t.string "ami", default: "" + t.string "security_group", default: "" end create_table "course_user_data", force: :cascade do |t| @@ -384,7 +386,6 @@ t.text "missing_problems" t.index ["assessment_id"], name: "index_submissions_on_assessment_id" t.index ["course_user_datum_id"], name: "index_submissions_on_course_user_datum_id" - t.index ["created_at"], name: "index_submissions_on_created_at" end create_table "users", force: :cascade do |t| From 798df51d3e3b99cfa9b3fb3eb0b8ba09e7468be4 Mon Sep 17 00:00:00 2001 From: Joy Song Date: Sun, 13 Apr 2025 16:59:42 -0400 Subject: [PATCH 4/5] HTML for dropdowns of AMIs and security groups (included default setting in case they don't select options). --- app/views/autograders/_ec2_settings.html.erb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/autograders/_ec2_settings.html.erb b/app/views/autograders/_ec2_settings.html.erb index 5eba9582f..610366d53 100755 --- a/app/views/autograders/_ec2_settings.html.erb +++ b/app/views/autograders/_ec2_settings.html.erb @@ -10,7 +10,15 @@ <%= f.text_field :access_key_id, display_name: "Access Key ID" %> <%= f.text_field :instance_type, display_name: "EC2 Instance Type", help_text: "Type of EC2 instance to be used to run the autograding job. See here for more details".html_safe %> -<%= f.select :access_key, options_for_select(@tagged_amis), {}, { display_name: "AMI" } %> +AMI +<%= f.select :ami, + options_for_select(@tagged_amis.map { |ami| ["Name: #{ami['name']}, ID: #{ami['id']}", ami['id']] }, f.object.ami), + { include_blank: "Use Tango Default" } %> +
+Security Groups +<%= f.select :security_group, + options_for_select(@security_groups.map { |sg| ["Name: #{sg['name']}, ID: #{sg['id']}", sg['name']] }, f.object.security_group), + { include_blank: "Use Tango Default" } %> <%= f.submit "Save Settings" %> <%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment), From b75cf0e56695494d5defc80ebe796f43be50aeca Mon Sep 17 00:00:00 2001 From: Joy Song Date: Sun, 13 Apr 2025 17:02:51 -0400 Subject: [PATCH 5/5] typo fix --- app/views/autograders/_ec2_settings.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/autograders/_ec2_settings.html.erb b/app/views/autograders/_ec2_settings.html.erb index 610366d53..cad997fa4 100755 --- a/app/views/autograders/_ec2_settings.html.erb +++ b/app/views/autograders/_ec2_settings.html.erb @@ -15,7 +15,7 @@ AMI options_for_select(@tagged_amis.map { |ami| ["Name: #{ami['name']}, ID: #{ami['id']}", ami['id']] }, f.object.ami), { include_blank: "Use Tango Default" } %>
-Security Groups +Security Group <%= f.select :security_group, options_for_select(@security_groups.map { |sg| ["Name: #{sg['name']}, ID: #{sg['id']}", sg['name']] }, f.object.security_group), { include_blank: "Use Tango Default" } %>