Skip to content

Commit d1c6d8a

Browse files
committed
CleanCache BAC now created by portal
The old code used to send a message to each Bourreau with a bunch of params to identify which files to clean. Then the bourreau would create a BAC object. In this new code, the portal no longer contacts the Bourreau, it just creates the BAC directly. Lots of old code was cleaned.
1 parent e2ef602 commit d1c6d8a

File tree

3 files changed

+36
-104
lines changed

3 files changed

+36
-104
lines changed

BrainPortal/app/controllers/bourreaux_controller.rb

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ def cache_disk_usage
573573
def cleanup_caches
574574
flash[:notice] ||= ""
575575

576+
# Time: Present ............................................................ Past
577+
# In Words: now .......... older_limit ..... younger_limit ................. long ago
578+
# Num Secs: 0 secs ago ................. < ........................ infinite secs ago
579+
# Vars: ............. cleanup_older < cleanup_younger ..........................
580+
#
581+
# |---- files to be deleted ----|
582+
576583
# First param is cleanup_older, which is the number
577584
# of second before NOW at which point files OLDER than
578585
# that become eligible for elimination
@@ -630,17 +637,37 @@ def cleanup_caches
630637
rrid_to_userids[remote_resource_id][user_id] = true
631638
end
632639

633-
# Send the cleanup message
640+
# Loop through each remote resource, and create the BACs for cleanup
634641
rrid_to_userids.each_key do |rrid|
635642
remote_resource = RemoteResource.find(rrid)
636643
userlist = rrid_to_userids[rrid] # uid => true, uid => true ...
637-
userids = userlist.keys.each { |uid| uid.to_s }.join(",") # "uid,uid,uid"
638-
flash[:notice] += "\n" unless flash[:notice].blank?
639-
begin
640-
remote_resource.send_command_clean_cache(current_user.id,userids,typeslist,cleanup_older.seconds.ago,cleanup_younger.seconds.ago)
641-
flash[:notice] += "Sending cleanup command to #{remote_resource.name}."
642-
rescue
643-
flash[:notice] += "Could not contact #{remote_resource.name}."
644+
userids = userlist.keys
645+
646+
# Identify what to clean
647+
syncs = SyncStatus.where( :remote_resource_id => rrid)
648+
syncs = syncs.where([ "sync_status.accessed_at < ?", cleanup_older.seconds.ago])
649+
syncs = syncs.where([ "sync_status.accessed_at > ?", cleanup_younger.seconds.ago])
650+
syncs = syncs.joins(:userfile) if userids.present? || typeslist.present?
651+
syncs = syncs.where( 'userfiles.user_id' => userids ) if userids.present?
652+
syncs = syncs.where( 'userfiles.type' => typeslist ) if typeslist.present?
653+
userfile_ids = syncs.pluck(:userfile_id)
654+
655+
col = BacItemsCollector.new(
656+
BackgroundActivity::CleanCache.new(
657+
:user_id => current_user.id,
658+
:remote_resource_id => rrid,
659+
:status => 'InProgress',
660+
),
661+
500,
662+
)
663+
664+
# Let the collector create one or several BACs
665+
col.add_items(userfile_ids)
666+
col.flush
667+
668+
if col.submitted_bac_ids.present?
669+
flash[:notice] += "\n" unless flash[:notice].blank?
670+
flash[:notice] += "Creating CleanCache background operation request for #{remote_resource.name}."
644671
end
645672
end
646673

BrainPortal/app/models/remote_command.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class RemoteCommand < RestrictedHash
4343
# An ID, usually assigned by the receiver.
4444
:id,
4545

46-
# Command keyword, one of 'clean_cache', 'stop_workers', 'start_workers',
46+
# Command keyword, one of 'stop_workers', 'start_workers',
4747
# etc. On the receiving end, the method "process_command_#{:command}"
4848
# will be executed with the current command object.
4949
:command,
@@ -69,23 +69,6 @@ class RemoteCommand < RestrictedHash
6969
:script_text, # filled by receiver
7070
:runtime_info, # filled by receiver
7171

72-
# -------- CLEAN CACHE PARAMETERS --------
73-
74-
# Which users are 'involved' in the command; only used for clean_cache
75-
# right now. Numeric ids as string. "3,4,5" or "all".
76-
:user_ids,
77-
78-
# Not really used right now
79-
:group_ids,
80-
81-
# Userfile types, single string with commas.
82-
:types,
83-
84-
# Date of effect; for clean_cache it means cleans files older than this..
85-
:before_date, # Time object
86-
# ... but younger than this are erased.
87-
:after_date, # Time object
88-
8972
# -------- CHECK DATA PROVIDERS PARAMETERS --------
9073

9174
:data_provider_ids, # an input for the command, a list of DP ids as string. "1,2,3"
@@ -118,12 +101,6 @@ def inspect #:nodoc:
118101
report += " Cluster-Stdout: #{(self.cluster_stdout || "").size} bytes\n"
119102
report += " Cluster-Stderr: #{(self.cluster_stderr || "").size} bytes\n"
120103
report += " Script-Text: #{(self.script_text || "").size} bytes\n"
121-
elsif self.command.to_s == 'clean_cache'
122-
report += " User-IDs: #{self.user_ids}\n"
123-
report += " Group-IDs: #{self.group_ids}\n"
124-
report += " Types: #{self.types}\n"
125-
report += " Before-Date: #{self.before_date}\n"
126-
report += " After-Date: #{self.after_date}\n"
127104
elsif self.command.to_s == 'check_data_providers'
128105
report += " Data-Provider-IDs: #{(self.data_provider_ids || []).join(", ")}\n"
129106
end

BrainPortal/app/models/remote_resource.rb

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -651,36 +651,6 @@ def zap_info_cache
651651
# Utility Shortcuts To Send Commands
652652
############################################################################
653653

654-
# Utility method to send a clean_cache command to a
655-
# RemoteResource, whether local or not.
656-
def send_command_clean_cache(userid,userlist,typelist,older_than,younger_than)
657-
if older_than.is_a?(Integer)
658-
time_older = older_than.seconds.ago
659-
elsif older_than.is_a?(Time)
660-
time_older = older_than
661-
else
662-
cb_error "Invalid older_than time offset for clean_cache command."
663-
end
664-
if younger_than.is_a?(Integer)
665-
time_younger = younger_than.seconds.ago
666-
elsif younger_than.is_a?(Time)
667-
time_younger = younger_than
668-
else
669-
cb_error "Invalid younger_than offset for clean_cache command."
670-
end
671-
userlist = [ userlist ] unless userlist.is_a?(Array)
672-
useridlist = userlist.map { |u| u.is_a?(User) ? u.id.to_s : u.to_s }.join(",")
673-
command = RemoteCommand.new(
674-
:requester_user_id => userid,
675-
:command => 'clean_cache',
676-
:user_ids => useridlist,
677-
:types => Array(typelist).join(","),
678-
:before_date => time_older,
679-
:after_date => time_younger
680-
)
681-
send_command(command)
682-
end
683-
684654
# Utility method to send a +check_data_providers+ command to a
685655
# RemoteResource, whether local or not. dp_ids should be
686656
# an array of Data Provider IDs. The command
@@ -873,48 +843,6 @@ def self.process_command_check_data_providers(command)
873843
true
874844
end
875845

876-
# Clean the cached files of a list of users, for files
877-
# last accessed before the +before_date+ ; the task
878-
# is started in background, as it can be long.
879-
def self.process_command_clean_cache(command)
880-
881-
myself = RemoteResource.current_resource
882-
883-
user_id = command.requester_user_id || AdminUser.first.id
884-
user_ids = command.user_ids.presence
885-
before_date = command.before_date.presence
886-
after_date = command.after_date.presence
887-
types = command.types.presence
888-
889-
user_id_list = user_ids ? user_ids.split(",") : nil
890-
types_list = types ? types.split(",") : nil
891-
892-
# Identify what to clean
893-
syncs = SyncStatus.where( :remote_resource_id => RemoteResource.current_resource.id )
894-
syncs = syncs.where([ "sync_status.accessed_at < ?", before_date]) if before_date
895-
syncs = syncs.where([ "sync_status.accessed_at > ?", after_date]) if after_date
896-
syncs = syncs.joins(:userfile) if user_id_list || types_list
897-
syncs = syncs.where( 'userfiles.user_id' => user_id_list ) if user_id_list
898-
syncs = syncs.where( 'userfiles.type' => types_list ) if types_list
899-
userfile_ids = syncs.pluck(:userfile_id)
900-
901-
# Create the collector object
902-
col = BacItemsCollector.new(
903-
BackgroundActivity::CleanCache.new(
904-
:user_id => user_id,
905-
:remote_resource_id => myself.id,
906-
:status => 'InProgress',
907-
),
908-
500,
909-
)
910-
911-
# Let the collector create one or several BACs
912-
col.add_items(userfile_ids)
913-
col.flush
914-
915-
true
916-
end
917-
918846
# This installs a pair of private/public SSH keys
919847
# for a user. The key pair has been created by another
920848
# CBRAIN app which sent this command to install a copy

0 commit comments

Comments
 (0)