Skip to content

Commit

Permalink
Add admin option to enable/disable compression when archiving task di…
Browse files Browse the repository at this point in the history
…rectories aces#1123
  • Loading branch information
MontrealSergiy committed Aug 13, 2024
1 parent 03a77d4 commit ec6d9d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions BrainPortal/app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,14 @@ def operation
archive_dp_id = params[:archive_dp_id].presence # for 'archive as file' operation
dup_bourreau_id = nil unless dup_bourreau_id && Bourreau.find_all_accessible_by_user(current_user).where(:id => dup_bourreau_id).exists?
archive_dp_id = nil unless archive_dp_id && DataProvider.find_all_accessible_by_user(current_user).where(:id => archive_dp_id).exists?
nozip = params[:nozip].presence # for archiving without compression

# This does the actual work and returns info about the
# successes and failures.
results = apply_operation(operation, tasklist,
:dup_bourreau_id => dup_bourreau_id,
:archive_dp_id => archive_dp_id,
:nozip => nozip
)

# Prepare counters for how many tasks affected.
Expand Down Expand Up @@ -748,6 +750,7 @@ def apply_operation(operation, taskids, options = {})
# Some other parameters
dup_bourreau_id = options[:dup_bourreau_id] # for 'duplicate' operation
archive_dp_id = options[:archive_dp_id] # for 'archive as file' operation
nozip = options[:nozip] # for 'archive as file' and 'archive' operation

# Prepare counters for how many tasks affected.
skipped_list = {}
Expand Down Expand Up @@ -817,6 +820,9 @@ def apply_operation(operation, taskids, options = {})
bac_klass = operation_to_bac[operation]
if bac_klass
bac = bac_klass.local_new(current_user.id, oktasks.map(&:id), bid, {})
# an option for archive or archive to file operations
bac.options[:nozip] = nozip if operation =~ /^archive(_file)?$/
# other options and operations
bac.options[:archive_data_provider_id] = archive_dp_id if operation == 'archive_file'
bac.options[:dup_bourreau_id] = dup_bourreau_id if operation == 'duplicate'
bac.options[:atwhat] = 'Setup' if operation == 'restart_setup'
Expand Down
8 changes: 4 additions & 4 deletions BrainPortal/app/models/cluster_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,9 @@ def capture_job_out_err(run_number=nil,stdout_lim=2000,stderr_lim=2000)
# Work Directory Archiving API
##################################################################

def in_situ_workdir_archive_file #:nodoc:
def in_situ_workdir_archive_file(nozip: false) #:nodoc:
fn_id = self.fullname.gsub(/[^\w\-]+/,"_").sub(/\A_*/,"").sub(/_*$/,"")
"CbrainTask_Workdir_#{fn_id}.tar.gz" # note: also check in the TaskWorkdirArchive model
"CbrainTask_Workdir_#{fn_id}.tar#{'.gz' unless nozip}" # note: also check in the TaskWorkdirArchive model
end

# This method will create a .tar.gz file of the
Expand All @@ -1320,7 +1320,7 @@ def in_situ_workdir_archive_file #:nodoc:
# in_situ_workdir_archive_file(). Restoring the
# state of the workdir can be performed with
# unarchive_work_directory().
def archive_work_directory
def archive_work_directory(nozip: false)

# Keep updated_at value in order to reset it at the end of method
updated_at_value = self.updated_at
Expand Down Expand Up @@ -1381,7 +1381,7 @@ def archive_work_directory

system("chmod","-R","u+rwX",".") # uppercase X mode affects only directories
status = with_stdout_stderr_capture(tar_capture) do
system("tar","-czf", temp_tar_file, "--exclude", "*#{temp_tar_file}", ".")
system("tar","-c#{'z' unless nozip }f", temp_tar_file, "--exclude", "*#{temp_tar_file}", ".")
$? # a Process::Status object
end

Expand Down
3 changes: 3 additions & 0 deletions BrainPortal/app/views/tasks/_task_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@
Optional: when archiving <em>As File</em>, choose a destination Data Provider:<br/>
<%= data_provider_select :archive_dp_id, { :selector => "" }, :include_blank => "" %>
<p/>
<% if current_user.has_role?(:admin_user) %>
<%= check_box_tag :nozip, "yes", false %> no need to compress, just archive
<% end %>
<% end %>

<%= button_with_dropdown_menu("Filters", :content_id => 'tasks_filters') do %>
Expand Down

0 comments on commit ec6d9d6

Please sign in to comment.