From c817c96d783c521a48cb12372281c8df11d5c88d Mon Sep 17 00:00:00 2001 From: MontrealSergiy Date: Tue, 27 Aug 2024 06:41:48 -0400 Subject: [PATCH] remove file_copy API #1413 --- .../app/controllers/bourreaux_controller.rb | 23 -------- BrainPortal/app/models/remote_command.rb | 4 -- BrainPortal/app/models/remote_resource.rb | 59 ------------------- BrainPortal/config/routes.rb | 1 - 4 files changed, 87 deletions(-) diff --git a/BrainPortal/app/controllers/bourreaux_controller.rb b/BrainPortal/app/controllers/bourreaux_controller.rb index a4adfdbde..657d88b72 100644 --- a/BrainPortal/app/controllers/bourreaux_controller.rb +++ b/BrainPortal/app/controllers/bourreaux_controller.rb @@ -610,29 +610,6 @@ def rr_access_dp end - # API method to copy files from one DP to another via a bourreau - def file_copy #:nodoc: - bourreau_id = params[:id] - userfile_ids = params[:userfile_ids] - data_provider_id = params[:dataprovider_id] - - bourreau = Bourreau.find(bourreau_id) - data_provider = DataProvider.find(data_provider_id) - - # Check if the user has access to the bourreau and the data provider - if !bourreau.can_be_accessed_by?(current_user) || !data_provider.can_be_accessed_by?(current_user) - render :json => { :error => "Access denied" }, :status => :forbidden - return - end - - # Filter out userfile_ids that are not readable by the user - userfile_ids = Userfile.find_all_accessible_by_user(current_user, :access_requested => :read) - .where(:id => userfile_ids).pluck(:id) - - bourreau.send_command_copy_files(userfile_ids, data_provider_id, current_user.id) - render :json => { :status => "ok", :file_copied_count => userfile_ids.size } - end - # API method to copy files from one DP to another via a bourreau; # unlike the file_copy method, this method will select which bourreau # to use dynamically, based on the ones that have the less activity already diff --git a/BrainPortal/app/models/remote_command.rb b/BrainPortal/app/models/remote_command.rb index 4747e5319..e259ea3e4 100644 --- a/BrainPortal/app/models/remote_command.rb +++ b/BrainPortal/app/models/remote_command.rb @@ -112,10 +112,6 @@ class RemoteCommand < RestrictedHash :ssh_key_pub, :ssh_key_priv, # when installing new ssh key - # -------- COPY FILES PARAMETERS -------- - - :userfile_ids, # an input for the command, a list of userfile ids as string. "1,2,3" - :dest_data_provider_id, # destination DP id # -------- ERROR TRACES -------- diff --git a/BrainPortal/app/models/remote_resource.rb b/BrainPortal/app/models/remote_resource.rb index fc109d5ba..7bffbaa85 100644 --- a/BrainPortal/app/models/remote_resource.rb +++ b/BrainPortal/app/models/remote_resource.rb @@ -692,23 +692,6 @@ def send_command_check_data_providers(dp_ids=[]) send_command(command) end - # Utility method to send a +copy_files+ command to a - # RemoteResource, whether local or not. +userfile_ids+ - # should be an array of Userfiles to copy. - # +dest_data_provider_id+ is the ID of the DP to copy the - # the files to. - # The command does not return any useful information, it simply - # launches a background job on the RemoteResource. - def send_command_copy_files(userfile_ids, dest_data_provider_id, requester_user_id) - command = RemoteCommand.new( - :command => 'copy_files', - :userfile_ids => userfile_ids.join(","), - :dest_data_provider_id => dest_data_provider_id, - :requester_user_id => requester_user_id, - ) - send_command(command) - end - # Utility method to send a +start_workers+ command to a # RemoteResource, whether local or not. # Maybe this should be more specific to Bourreaux. @@ -926,48 +909,6 @@ def self.process_command_push_ssh_keys(command) true end - # This remote command copies a set of files to - # a destination DataProvider. At the end, a - # Message is created with a summary of the - # successes or failures. - def self.process_command_copy_files(command) - # Command params - userfile_ids = command.userfile_ids.split(",") - dest_data_provider_id = command.dest_data_provider_id - user_id = command.requester_user_id.presence || User.admin.id - user = User.find(user_id) - - dest_dp = DataProvider.find(dest_data_provider_id) - - # Loop though the files and copy them - CBRAIN.spawn_with_active_records(:admin, "Userfile Copy") do - status = {} # message => count - userfile_ids.each_with_index do |userfile_id,idx| - userfile = Userfile.where(:id => userfile_id).first - next unless userfile # doesn't exist? ignore - Process.setproctitle "CopyFiles ID=#{userfile_id} #{idx+1}/#{userfile_ids.size}" - message = "" # scope declaration - begin - copied = userfile.provider_copy_to_otherprovider(dest_dp) - message = copied ? 'Copied' : 'Not copied (already exists?)' - rescue => ex - message = "Error copying: #{ex.message}" - end - status[message] ||= 0 - status[message] += 1 - end - message_type = (status.keys.size == 1 && status.keys.first == 'Copied') ? :notice : :error - Message.send_message(user, - { :message_type => message_type, - :header => "File copying operation finished.", - :variable_text => (status.map { |m,c| "#{c} x #{m}" }.join("\n")), - } - ) - end - - true - end - # Helper method to prepend 'source cbrain_bashrc;' to shell command. # The 'cbrain_bashrc' script is the one located in # the "/script" subdirectory under the remote resource's diff --git a/BrainPortal/config/routes.rb b/BrainPortal/config/routes.rb index d8aa1c02e..e6f4e3d3d 100644 --- a/BrainPortal/config/routes.rb +++ b/BrainPortal/config/routes.rb @@ -99,7 +99,6 @@ member do post 'start' post 'stop' - post 'file_copy' get 'row_data' get 'info' get 'cache_disk_usage'