Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove file copy endpoint #1413 #1424

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
23 changes: 0 additions & 23 deletions BrainPortal/app/controllers/bourreaux_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions BrainPortal/app/models/remote_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------

Expand Down
59 changes: 0 additions & 59 deletions BrainPortal/app/models/remote_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion BrainPortal/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
member do
post 'start'
post 'stop'
post 'file_copy'
get 'row_data'
get 'info'
get 'cache_disk_usage'
Expand Down
Loading