Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions app/assets/javascripts/autograder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;
(function() {
$(document).ready(function() {
function access_key_callback() {
const checked = $(this).prop('checked');
const $access_key_field = $('#autograder_access_key');
const $access_key_id_field = $('#autograder_access_key_id');
$access_key_field.prop('disabled', !checked);
$access_key_id_field.prop('disabled', !checked);
if (!checked) {
$access_key_field.val('', checked);
$access_key_id_field.val('', checked);
}
}

$('#autograder_use_access_key').on('change', access_key_callback);
access_key_callback.call($('#autograder_use_access_key'));

function initializeEC2Dropdown() {
if ($.fn.tooltip) {
$('.browser-default[data-tooltip]').tooltip({
enterDelay: 300,
exitDelay: 200,
position: 'top'
});
}

$('#autograder_instance_type option').hover(
function() { $(this).addClass('highlighted-option'); },
function() { $(this).removeClass('highlighted-option'); }
);

$('#autograder_instance_type').on('change.ec2-instance', function() {
const selectedInstance = $(this).val();
console.log('Selected EC2 instance type:', selectedInstance);
});
}

// Initialize the EC2 dropdown functionality
initializeEC2Dropdown();
});
})();
17 changes: 15 additions & 2 deletions app/controllers/autograders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def create
a.autograde_timeout = 180
a.autograde_image = "autograding_image"
a.release_score = true
a.access_key_id = ""
a.access_key = ""
a.instance_type = "t2.micro"
end
if @autograder.save
flash[:success] = "Autograder created."
Expand All @@ -38,7 +41,14 @@ def edit

action_auth_level :update, :instructor
def update
if @autograder.update(autograder_params) && @assessment.update(assessment_params)
# Clear secrets if use_access_key is disabled
params_to_update = autograder_params
unless params_to_update[:use_access_key]
params_to_update[:access_key] = nil
params_to_update[:access_key_id] = nil
end

if @autograder.update(params_to_update) && @assessment.update(assessment_params)
flash[:success] = "Autograder saved."
begin
upload
Expand Down Expand Up @@ -112,7 +122,10 @@ def set_autograder
end

def autograder_params
params[:autograder].permit(:autograde_timeout, :autograde_image, :release_score)
params.require(:autograder).permit(
:autograde_timeout, :autograde_image, :release_score,
:use_access_key, :access_key, :access_key_id, :instance_type
)
end

def assessment_params
Expand Down
35 changes: 25 additions & 10 deletions app/helpers/assessment_autograde_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,31 @@ def get_job_status(job_id)
# Returns the Tango response
#
def tango_add_job(course, assessment, upload_file_list, callback_url, job_name, output_file)
job_properties = { "image" => @autograde_prop.autograde_image,
"files" => upload_file_list.map do |f|
{ "localFile" => f["remoteFile"],
"destFile" => Pathname.new(f["destFile"]).basename.to_s }
end,
"output_file" => output_file,
"timeout" => @autograde_prop.autograde_timeout,
"callback_url" => callback_url,
"jobName" => job_name,
"disable_network" => assessment.disable_network }.to_json
job_properties = {
"image" => @autograde_prop.autograde_image,
"files" => upload_file_list.map do |f|
{ "localFile" => f["remoteFile"],
"destFile" => Pathname.new(f["destFile"]).basename.to_s }
end,
"output_file" => output_file,
"timeout" => @autograde_prop.autograde_timeout,
"callback_url" => callback_url,
"jobName" => job_name,
"disable_network" => assessment.disable_network
}

if Rails.configuration.x.ec2_ssh
job_properties["ec2Vmms"] = true
job_properties["instanceType"] = @autograde_prop.instance_type.presence || "t3.micro"

if @autograde_prop.use_access_key?
job_properties["accessKey"] = @autograde_prop.access_key
job_properties["accessKeyId"] = @autograde_prop.access_key_id
end
end

job_properties = job_properties.to_json

begin
response = TangoClient.addjob("#{course.name}-#{assessment.name}", job_properties)
rescue TangoClient::TangoException => e
Expand Down
14 changes: 13 additions & 1 deletion app/models/autograder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@
class Autograder < ApplicationRecord
belongs_to :assessment

# Encryption for AWS credentials
has_encrypted :access_key
has_encrypted :access_key_id

trim_field :autograde_image

# extremely short timeout values cause the backend to throw system errors
# Validations
validates :autograde_timeout,
numericality: { greater_than_or_equal_to: 10, less_than_or_equal_to: 900 }
validates :autograde_image, :autograde_timeout, presence: true
validates :autograde_image, length: { maximum: 64 }

with_options if: :use_access_key do
validates :access_key_id, presence: true, format: {
with: /\A[A-Z0-9]{16,24}\z/,
message: "looks invalid"
}
validates :access_key, presence: true
end

after_commit -> { assessment.dump_yaml }

SERIALIZABLE = Set.new %w[autograde_image autograde_timeout release_score]
Expand Down
36 changes: 36 additions & 0 deletions app/views/autograders/_basic_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<%= f.text_field :autograde_image, display_name: "VM Image",
help_text: "VM image for autograding (e.g. <kbd>rhel.img</kbd>). #{link_to 'Click here', tango_status_course_jobs_path} to view the list of VM images and pools currently being used".html_safe +
(Rails.configuration.x.docker_image_upload_enabled.presence ? ", or #{link_to 'click here', course_dockers_path} to upload a new docker image.".html_safe : "."),
required: true, maxlength: 64 %>

<%= f.number_field :autograde_timeout, display_name: "Timeout",
help_text: "Timeout for autograding jobs (secs). Must be between 10s and 900s, inclusive.", min: 10, max: 900 %>
<%= f.check_box :release_score,
display_name: "Release Scores?",
help_text: "Check to release autograded scores to students immediately after autograding (strongly recommended)." %>

<% help_tar_text = "Tar file exists, upload a file to override." %>
<% help_makefile_text = "Makefile exists, upload a file to override." %>
<%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload, file_exists_text: help_makefile_text, class: "form-file-field", file_exists: @makefile_exists %>
<%= f.file_field :tar, label_text: "Autograder Tar", action: :upload, file_exists_text: help_tar_text, class: "form-file-field", file_exists: @tar_exists %>
<p class="help-block">
Both of the above files will be renamed upon upload.
</p>

<%= f.fields_for :assessment, @assessment do |af| %>
<%= af.check_box :disable_network, help_text: "Disable network access for autograding containers." %>
<% end %>

<%= f.submit "Save Settings" %>

<%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment),
method: :delete, class: "btn danger",
data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>

<% unless @makefile_exists.nil? %>
<%= link_to "Download Makefile", download_file_course_assessment_autograder_path(file_path: @makefile_exists, file_key: 'makefile'), class: "btn" %>
<% end %>

<% unless @tar_exists.nil? %>
<%= link_to "Download Tar", download_file_course_assessment_autograder_path(file_path: @tar_exists, file_key: 'tar'), class: "btn" %>
<% end %>
92 changes: 92 additions & 0 deletions app/views/autograders/_ec2_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<% content_for :javascripts do %>
<%= javascript_include_tag "autograder" %>
<% end %>

<h4>EC2 Settings</h4>
<%= f.check_box :use_access_key,
display_name: "Enable Access Key",
help_text: "(Optional) Use your own provided access key to authenticate to different EC2 instances than the default one on Tango" %>
<%= f.password_field :access_key,
display_name: "Access Key",
value: nil,
autocomplete: "new-password",
placeholder: "Leave blank to keep existing secret" %>
<%= f.text_field :access_key_id,
display_name: "Access Key ID",
value: nil,
autocomplete: "off",
placeholder: "Leave blank to keep existing secret" %>

<%
# Group EC2 instance options by category for better organization
ec2_instance_options = [
# General Purpose - T2 (burstable)
['T2 - General Purpose (Burstable)', [
['t2.nano - 1 vCPU, 0.5 GiB RAM (minimal, lowest cost)', 't2.nano'],
['t2.micro - 1 vCPU, 1 GiB RAM (lowest cost, suitable for small jobs)', 't2.micro'],
['t2.small - 1 vCPU, 2 GiB RAM (low cost, better for memory-intensive tasks)', 't2.small'],
['t2.medium - 2 vCPU, 4 GiB RAM (balanced, good for most autograding tasks)', 't2.medium'],
['t2.large - 2 vCPU, 8 GiB RAM (better for memory-heavy workloads)', 't2.large'],
['t2.xlarge - 4 vCPU, 16 GiB RAM (good for parallel processing)', 't2.xlarge'],
['t2.2xlarge - 8 vCPU, 32 GiB RAM (high performance, burstable)', 't2.2xlarge']
]],
# General Purpose - T3 (newer generation)
['T3 - General Purpose (Newer Generation)', [
['t3.micro - 2 vCPU, 1 GiB RAM (better performance than t2.micro)', 't3.micro'],
['t3.small - 2 vCPU, 2 GiB RAM (improved over t2.small)', 't3.small'],
['t3.medium - 2 vCPU, 4 GiB RAM (better CPU performance than t2)', 't3.medium'],
['t3.large - 2 vCPU, 8 GiB RAM (improved networking)', 't3.large']
]],
# Compute Optimized
['C - Compute Optimized', [
['c5.large - 2 vCPU, 4 GiB RAM (compute-optimized, faster CPU)', 'c5.large'],
['c5.xlarge - 4 vCPU, 8 GiB RAM (high compute performance)', 'c5.xlarge'],
['c5.2xlarge - 8 vCPU, 16 GiB RAM (very high compute performance)', 'c5.2xlarge']
]],
# Memory Optimized
['R - Memory Optimized', [
['r5.large - 2 vCPU, 16 GiB RAM (memory-optimized, for large datasets)', 'r5.large'],
['r5.xlarge - 4 vCPU, 32 GiB RAM (high memory capacity)', 'r5.xlarge'],
['r5.2xlarge - 8 vCPU, 64 GiB RAM (very high memory capacity)', 'r5.2xlarge']
]]
]
%>

<div style="margin-bottom: 5px;"><strong>EC2 Instance Type</strong></div>

<%= f.select :instance_type,
grouped_options_for_select(ec2_instance_options, @autograder.instance_type),
{ include_blank: false, label: "EC2 Instance Type" },
{ class: 'browser-default',
data: { tooltip: "Select an EC2 instance type based on your autograding needs. Larger instances cost more but run faster." },
display_name: "EC2 Instance Type" } %>
<div class="help-text">
Choose an instance type based on your autograding requirements:
<ul class="browser-default" style="margin-top: 5px; margin-left: 15px;">
<li><strong>T2 instances</strong>: Burstable performance instances, good for varying workloads
<ul>
<li><strong>t2.micro</strong>: Default, lowest cost, suitable for simple autograding</li>
<li><strong>t2.medium/large</strong>: Better for more complex tests with moderate requirements</li>
</ul>
</li>
<li><strong>T3 instances</strong>: Newer generation with better baseline performance than T2</li>
<li><strong>C5 (Compute-optimized)</strong>: Best for CPU-bound tasks like compilation, testing algorithms</li>
<li><strong>R5 (Memory-optimized)</strong>: Best for memory-intensive operations with large datasets</li>
</ul>
<div class="recommendation-box" style="background-color: #f5f5f5; padding: 10px; border-left: 4px solid #2196F3; margin-top: 10px;">
<strong>Recommendations:</strong>
<ul class="browser-default" style="margin-top: 5px; margin-left: 15px;">
<li>Start with <strong>t2.micro</strong> for basic assignments with minimal resource requirements</li>
<li>Use <strong>t2.medium</strong> or <strong>t3.medium</strong> for most standard programming assignments</li>
<li>Choose <strong>c5.xlarge</strong> for computationally intensive tasks (e.g., compiler projects)</li>
<li>Select <strong>r5.large</strong> for memory-intensive workloads (e.g., large datasets, ML)</li>
</ul>
</div>
<small>Note: Larger instances incur higher AWS costs. <a href='https://aws.amazon.com/ec2/pricing/on-demand/' target='_blank'>View EC2 pricing</a></small>
</div>

<%= f.submit "Save Settings" %>

<%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment),
method: :delete, class: "btn danger",
data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>
72 changes: 33 additions & 39 deletions app/views/autograders/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
<%= form_for @autograder, url: course_assessment_autograder_path(@course, @assessment, @autograder),
builder: FormBuilderWithDateTimeInput,
html: { multipart: true } do |f| %>
<%= f.text_field :autograde_image, display_name: "VM Image",
help_text: "VM image for autograding (e.g. <kbd>rhel.img</kbd>). #{link_to 'Click here', tango_status_course_jobs_path} to view the list of VM images and pools currently being used".html_safe +
(Rails.configuration.x.docker_image_upload_enabled.presence ? ", or #{link_to 'click here', course_dockers_path} to upload a new docker image.".html_safe : "."),
required: true, maxlength: 64 %>
<div class="row">
<div class="col s12">
<ul id="tabs" class="tabs tabs-fixed-width">
<% list = ["basic"] %>
<% if Rails.configuration.x.ec2_ssh.presence %>
<% list.append("ec2") %>
<% end %>
<% list.each do |tab_name| %>
<%= if tab_name == params[:active_tab]
tag.li(link_to(tab_name.titleize, "#tab_#{tab_name}"), class: "active tab")
else
tag.li(link_to(tab_name.titleize, "#tab_#{tab_name}"), class: :tab)
end %>
<% end %>
</ul>
</div>
</div>

<%= f.number_field :autograde_timeout, display_name: "Timeout",
help_text: "Timeout for autograding jobs (secs). Must be between 10s and 900s, inclusive.", min: 10, max: 900 %>
<%= f.check_box :release_score,
display_name: "Release Scores?",
help_text: "Check to release autograded scores to students immediately after autograding (strongly recommended)." %>

<% help_tar_text = "Tar file exists, upload a file to override." %>
<% help_makefile_text = "Makefile exists, upload a file to override." %>
<%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload, file_exists_text: help_makefile_text, class: "form-file-field", file_exists: @makefile_exists %>
<%= f.file_field :tar, label_text: "Autograder Tar", action: :upload, file_exists_text: help_tar_text, class: "form-file-field", file_exists: @tar_exists %>
<p class="help-block">
Both of the above files will be renamed upon upload.
</p>

<%= f.fields_for :assessment, @assessment do |af| %>
<%= af.check_box :disable_network, help_text: "Disable network access for autograding containers." %>
<% end %>

<%= f.submit "Save Settings" %>

<%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment),
method: :delete, class: "btn danger",
data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>

<% unless @makefile_exists.nil? %>
<%= link_to "Download Makefile", download_file_course_assessment_autograder_path(file_path: @makefile_exists, file_key: 'makefile'), class: "btn" %>
<% end %>

<% unless @tar_exists.nil? %>
<%= link_to "Download Tar", download_file_course_assessment_autograder_path(file_path: @tar_exists, file_key: 'tar'), class: "btn" %>
<% end %>
<% end %>
<div class="row">
<div class="col s12">
<%= form_for @autograder, url: course_assessment_autograder_path(@course, @assessment, @autograder),
builder: FormBuilderWithDateTimeInput,
html: { multipart: true } do |f| %>
<div id="tab_basic">
<%= render "basic_settings", f: %>
</div>
<% if Rails.configuration.x.ec2_ssh.presence %>
<div id="tab_ec2">
<%= render "ec2_settings", f: %>
</div>
<% end %>
<% end %>
</div>
</div>
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
# Feature flag for docker image upload
config.x.docker_image_upload_enabled = true

# Feature flag for EC2 autograder
config.x.ec2_ssh = true

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

Expand Down
3 changes: 3 additions & 0 deletions config/environments/production.rb.template
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Autolab3::Application.configure do
# Feature flag for docker image upload
config.x.docker_image_upload_enabled = false

# Feature flag for EC2 autograder
config.x.ec2_ssh = false

# ID for Heap Analytics
config.x.analytics_id = nil

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/filter_parameter_logging.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Be sure to restart your server when you modify this file.

# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password, :session, :warden, :secret, :salt, :cookie, :csrf, :restful_key, :lockbox_master_key, :lti_tool_private_key]
Rails.application.config.filter_parameters += [:password, :session, :warden, :secret, :salt, :cookie, :csrf, :restful_key, :lockbox_master_key, :lti_tool_private_key, :access_key, :access_key_id]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddEc2SshFieldsToAutograders < ActiveRecord::Migration[6.1]
def change
add_column :autograders, :instance_type, :string, default: ""
add_column :autograders, :access_key, :string, default: ""
add_column :autograders, :access_key_id, :string, default: ""
end
end
5 changes: 5 additions & 0 deletions db/migrate/20241211042124_add_use_access_key_to_autograder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUseAccessKeyToAutograder < ActiveRecord::Migration[6.1]
def change
add_column :autograders, :use_access_key, :boolean, default: false
end
end
Loading