@ -97,6 +97,7 @@ my $THIS_FILE = "Database.pm";
# refresh_timestamp
# resync_databases
# shutdown
# track_files
# update_host_status
# write
# _add_to_local_config
@ -401,8 +402,8 @@ sub check_file_locations
# Get all the Anvil! systems we know of.
$ anvil - > Database - > get_hosts ( { debug = > $ debug } ) ;
$ anvil - > Database - > get_files ( { debug = > $ debug } ) ;
$ anvil - > Database - > get_file_locations ( { debug = > $ debug } ) ;
#$anvil->Database->get_files({debug => $debug}) ;
#$anvil->Database->get_file_locations({debug => $debug}) ;
foreach my $ host_name ( sort { $ a cmp $ b } keys % { $ anvil - > data - > { hosts } { host_name } } )
{
@ -2830,135 +2831,6 @@ WHERE
} } ) ;
}
}
# Track the files on this Anvil!
foreach my $ file_location_uuid ( keys % { $ anvil - > data - > { file_locations } { file_location_uuid } } )
{
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { file_location_uuid = > $ file_location_uuid } } ) ;
# If either node is set have this file, make sure both are.
my $ file_uuid = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_file_uuid } ;
my $ anvil_needs_file = 0 ;
$ anvil - > { needs_file } { $ file_uuid } { $ anvil_node1_host_uuid } = 0 ;
$ anvil - > { needs_file } { $ file_uuid } { $ anvil_node2_host_uuid } = 0 ;
if ( ( exists $ anvil - > data - > { file_locations } { host_uuid } { $ anvil_node1_host_uuid } { file_uuid } { $ file_uuid } ) &&
( $ anvil - > data - > { file_locations } { host_uuid } { $ anvil_node1_host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ) )
{
my $ file_location_uuid = $ anvil - > data - > { file_locations } { host_uuid } { $ anvil_node1_host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ;
my $ file_location_active = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
file_location_uuid = > $ file_location_uuid ,
file_location_active = > $ file_location_active ,
} } ) ;
if ( not $ file_location_active )
{
$ anvil - > { needs_file } { $ file_uuid } { $ anvil_node1_host_uuid } = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"needs_file::${file_uuid}::${anvil_node1_host_uuid}" = > $ anvil - > { needs_file } { $ file_uuid } { $ anvil_node1_host_uuid } ,
} } ) ;
}
}
if ( ( exists $ anvil - > data - > { file_locations } { host_uuid } { $ anvil_node2_host_uuid } { file_uuid } { $ file_uuid } ) &&
( $ anvil - > data - > { file_locations } { host_uuid } { $ anvil_node2_host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ) )
{
my $ file_location_uuid = $ anvil - > data - > { file_locations } { host_uuid } { $ anvil_node2_host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ;
my $ file_location_active = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
file_location_uuid = > $ file_location_uuid ,
file_location_active = > $ file_location_active ,
} } ) ;
if ( not $ file_location_active )
{
$ anvil - > { needs_file } { $ file_uuid } { $ anvil_node2_host_uuid } = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"needs_file::${file_uuid}::${anvil_node2_host_uuid}" = > $ anvil - > { needs_file } { $ file_uuid } { $ anvil_node2_host_uuid } ,
} } ) ;
}
}
# If either node has the file, both nodes (and all DRs) need the file.
if ( ( $ anvil - > { needs_file } { $ file_uuid } { $ anvil_node1_host_uuid } ) or ( $ anvil - > { needs_file } { $ file_uuid } { $ anvil_node2_host_uuid } ) )
{
$ anvil_needs_file = 1 ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { anvil_needs_file = > $ anvil_needs_file } } ) ;
}
foreach my $ host_uuid ( $ anvil_node1_host_uuid , $ anvil_node2_host_uuid )
{
# If the Anvil! needs the file, make sure that both nodes and any connected DRs have it as well.
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
host_uuid = > $ host_uuid ,
} } ) ;
if ( $ anvil_needs_file )
{
if ( not $ anvil - > { needs_file } { $ file_uuid } { $ host_uuid } )
{
$ anvil - > Database - > insert_or_update_file_locations ( {
debug = > $ debug ,
file_location_file_uuid = > $ file_location_uuid ,
file_location_host_uuid = > $ host_uuid ,
file_location_active = > 1 ,
} ) ;
}
}
}
# If the Anvil! node needs the file, record it as being on this Anvil! node.
if ( $ anvil_needs_file )
{
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"file_locations::file_location_uuid::${file_location_uuid}::file_location_host_uuid" = > $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_host_uuid } ,
"file_locations::file_location_uuid::${file_location_uuid}::file_location_active" = > $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ,
} } ) ;
next if not exists $ anvil - > data - > { files } { file_uuid } { $ file_uuid } ;
my $ file_name = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_name } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
file_uuid = > $ file_uuid ,
file_name = > $ file_name ,
} } ) ;
# If the file was deleted, this won't exist
next if not exists $ anvil - > data - > { files } { file_uuid } { $ file_uuid } ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_name } = $ file_name ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_directory } = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_directory } ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_size } = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_size } ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_md5sum } = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_md5sum } ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_type } = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_type } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_name" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_name } ,
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_directory" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_directory } ,
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_size" = > $ anvil - > Convert - > bytes_to_human_readable ( { 'bytes' = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_size } } ) . " (" . $ anvil - > Convert - > add_commas ( { number = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_size } } ) . ")" ,
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_md5sum" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_md5sum } ,
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_type" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_type } ,
} } ) ;
# Make it so that we can list the files by name.
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_name } { $ file_name } { file_uuid } = $ file_uuid ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"anvils::anvil_uuid::${anvil_uuid}::file_name::${file_name}::file_uuid" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_name } { $ file_name } { file_uuid } ,
} } ) ;
# Make sure linked DR hosts have this file, also.
foreach my $ host_uuid ( keys % { $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { dr_host } } )
{
my $ file_location_uuid = $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ;
my $ file_location_active = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ;
if ( not $ file_location_active )
{
$ anvil - > Database - > insert_or_update_file_locations ( {
debug = > $ debug ,
file_location_file_uuid = > $ file_location_uuid ,
file_location_host_uuid = > $ host_uuid ,
file_location_active = > 1 ,
} ) ;
}
}
}
}
}
return ( 0 ) ;
@ -3372,6 +3244,18 @@ FROM
"file_locations::file_location_uuid::${file_location_uuid}::modified_date" = > $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { modified_date } ,
} } ) ;
### TODO: Remove this when the WebUI is updated.
# If this host is a node in an Anvil!, set the old 'file_location_anvil_uuid' to maintain
# backwards compatibility.
if ( ( exists $ anvil - > data - > { hosts } { host_uuid } { $ file_location_host_uuid } ) &&
( $ anvil - > data - > { hosts } { host_uuid } { $ file_location_host_uuid } { anvil_uuid } ) )
{
$ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_anvil_uuid } = $ anvil - > data - > { hosts } { host_uuid } { $ file_location_host_uuid } { anvil_uuid } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"file_locations::file_location_uuid::${file_location_uuid}::file_location_anvil_uuid" = > $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_anvil_uuid } ,
} } ) ;
}
# Make it easy to find files by anvil and file UUID.
$ anvil - > data - > { file_locations } { host_uuid } { $ file_location_host_uuid } { file_uuid } { $ file_location_file_uuid } { file_location_uuid } = $ file_location_uuid ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
@ -8002,6 +7886,12 @@ Parameters;
If not passed , a check will be made to see if an existing entry is found for C << file_location_file_uuid >> . If found , that entry will be updated . If not found , a new record will be inserted .
= head3 file_location_anvil_uuid ( required )
This is the C << anvils >> - > C << anvil_uuid >> being referenced . This works by figuring out which hosts are a member of the Anvil ! node , and which DR hosts are linked , and makes a recursive call to this method for each of their C << hosts >> - > C << host_uuid >> .
B << Note >> : When this is used , a comma - separated list of C << host_uuid = file_location_uuid >> is returned .
= head3 file_location_file_uuid ( required )
This is the C << files >> - > C << file_uuid >> being referenced .
@ -8025,21 +7915,23 @@ sub insert_or_update_file_locations
my $ debug = defined $ parameter - > { debug } ? $ parameter - > { debug } : 3 ;
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , key = > "log_0125" , variables = > { method = > "Database->insert_or_update_file_locations()" } } ) ;
my $ uuid = defined $ parameter - > { uuid } ? $ parameter - > { uuid } : "" ;
my $ file = defined $ parameter - > { file } ? $ parameter - > { file } : "" ;
my $ line = defined $ parameter - > { line } ? $ parameter - > { line } : "" ;
my $ file_location_uuid = defined $ parameter - > { file_location_uuid } ? $ parameter - > { file_location_uuid } : "" ;
my $ file_location_file_uuid = defined $ parameter - > { file_location_file_uuid } ? $ parameter - > { file_location_file_uuid } : "" ;
my $ file_location_host_uuid = defined $ parameter - > { file_location_host_uuid } ? $ parameter - > { file_location_host_uuid } : "" ;
my $ file_location_active = defined $ parameter - > { file_location_active } ? $ parameter - > { file_location_active } : "" ;
my $ uuid = defined $ parameter - > { uuid } ? $ parameter - > { uuid } : "" ;
my $ file = defined $ parameter - > { file } ? $ parameter - > { file } : "" ;
my $ line = defined $ parameter - > { line } ? $ parameter - > { line } : "" ;
my $ file_location_uuid = defined $ parameter - > { file_location_uuid } ? $ parameter - > { file_location_uuid } : "" ;
my $ file_location_anvil_uuid = defined $ parameter - > { file_location_anvil_uuid } ? $ parameter - > { file_location_anvil_uuid } : "" ;
my $ file_location_file_uuid = defined $ parameter - > { file_location_file_uuid } ? $ parameter - > { file_location_file_uuid } : "" ;
my $ file_location_host_uuid = defined $ parameter - > { file_location_host_uuid } ? $ parameter - > { file_location_host_uuid } : "" ;
my $ file_location_active = defined $ parameter - > { file_location_active } ? $ parameter - > { file_location_active } : "" ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
uuid = > $ uuid ,
file = > $ file ,
line = > $ line ,
file_location_uuid = > $ file_location_uuid ,
file_location_file_uuid = > $ file_location_file_uuid ,
file_location_host_uuid = > $ file_location_host_uuid ,
file_location_active = > $ file_location_active ,
uuid = > $ uuid ,
file = > $ file ,
line = > $ line ,
file_location_uuid = > $ file_location_uuid ,
file_location_anvil_uuid = > $ file_location_anvil_uuid ,
file_location_file_uuid = > $ file_location_file_uuid ,
file_location_host_uuid = > $ file_location_host_uuid ,
file_location_active = > $ file_location_active ,
} } ) ;
if ( not $ file_location_file_uuid )
@ -8061,6 +7953,59 @@ sub insert_or_update_file_locations
return ( "" ) ;
}
# If we've got an Anvil! uuid, find out the hosts and DR links connected to the Anvil! are found and
# this method is recursively called for each host.
if ( $ file_location_anvil_uuid )
{
$ anvil - > Database - > get_anvils ( { debug = > $ debug } ) ;
if ( not exists $ anvil - > data - > { anvils } { anvil_uuid } { $ file_location_anvil_uuid } )
{
# Bad Anvil! UUID.
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > 0 , priority = > "err" , key = > "error_0169" , variables = > { anvil_uuid = > $ file_location_anvil_uuid } } ) ;
return ( "" ) ;
}
my $ hosts = ( ) ;
push @ { $ hosts } , $ anvil - > data - > { anvils } { anvil_uuid } { $ file_location_anvil_uuid } { anvil_node1_host_uuid } ;
push @ { $ hosts } , $ anvil - > data - > { anvils } { anvil_uuid } { $ file_location_anvil_uuid } { anvil_node2_host_uuid } ;
if ( exists $ anvil - > data - > { dr_links } { by_anvil_uuid } { $ file_location_anvil_uuid } )
{
foreach my $ dr_link_host_uuid ( sort { $ a cmp $ b } keys % { $ anvil - > data - > { dr_links } { by_anvil_uuid } { $ file_location_anvil_uuid } { dr_link_host_uuid } } )
{
my $ dr_link_uuid = $ anvil - > data - > { dr_links } { by_anvil_uuid } { $ file_location_anvil_uuid } { dr_link_host_uuid } { $ dr_link_host_uuid } { dr_link_uuid } ;
my $ dr_link_note = $ anvil - > data - > { dr_links } { dr_link_uuid } { $ dr_link_uuid } { dr_link_note } ;
my $ dr_link_short_host_name = $ anvil - > data - > { hosts } { host_uuid } { $ dr_link_host_uuid } { short_host_name } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"s1:dr_link_host_uuid" = > $ dr_link_host_uuid ,
"s2:dr_link_uuid" = > $ dr_link_uuid ,
"s3:dr_link_note" = > $ dr_link_note ,
"s4:dr_link_short_host_name" = > $ dr_link_short_host_name ,
} } ) ;
next if $ dr_link_note eq "DELETED" ;
push @ { $ hosts } , $ dr_link_host_uuid ;
}
}
my $ file_location_uuids = "" ;
foreach my $ host_uuid ( @ { $ hosts } )
{
my $ file_location_uuid = $ anvil - > Database - > insert_or_update_file_locations ( {
debug = > $ debug ,
file_location_file_uuid = > $ file_location_file_uuid ,
file_location_host_uuid = > $ host_uuid ,
file_location_active = > $ file_location_active ,
} ) ;
$ file_location_uuids . = $ host_uuid . "=" . $ file_location_uuid . "," ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
file_location_uuid = > $ file_location_uuid ,
file_location_uuids = > $ file_location_uuids ,
} } ) ;
}
$ file_location_uuids =~ s/,$// ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { file_location_uuids = > $ file_location_uuids } } ) ;
return ( $ file_location_uuids ) ;
}
# If we don't have a UUID, see if we can find one for the given md5sum.
if ( not $ file_location_uuid )
{
@ -8124,7 +8069,7 @@ INSERT INTO
SELECT
file_location_file_uuid ,
file_location_host_uuid ,
file_location_active ,
file_location_active
FROM
file_locations
WHERE
@ -17575,6 +17520,237 @@ AND
}
= head2 track_file
This looks at all files in the database , and then for all Anvil ! systems and linked DR hosts , ensures that there ' s a corresponding C << file_locations >> entry .
This method takes no parameters .
= cut
sub track_files
{
my $ self = shift ;
my $ parameter = shift ;
my $ anvil = $ self - > parent ;
my $ debug = defined $ parameter - > { debug } ? $ parameter - > { debug } : 3 ;
$ anvil - > Log - > entry ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , key = > "log_0125" , variables = > { method = > "Database->track_files()" } } ) ;
my $ anvils = keys % { $ anvil - > data - > { anvils } { anvil_name } } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { anvils = > $ anvils } } ) ;
if ( not $ anvils )
{
$ anvil - > Database - > get_anvils ( { debug = > $ debug } ) ;
}
my $ files = keys % { $ anvil - > data - > { files } { file_uuid } } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { files = > $ files } } ) ;
if ( not $ files )
{
$ anvil - > Database - > get_files ( { debug = > $ debug } ) ;
}
my $ file_locations = keys % { $ anvil - > data - > { file_locations } { file_location_uuid } } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { file_locations = > $ file_locations } } ) ;
if ( not $ file_locations )
{
$ anvil - > Database - > get_file_locations ( { debug = > $ debug } ) ;
}
my $ dr_link_uuid = keys % { $ anvil - > data - > { dr_links } { dr_link_uuid } } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { dr_link_uuid = > $ dr_link_uuid } } ) ;
if ( not $ dr_link_uuid )
{
$ anvil - > Database - > get_dr_links ( { debug = > $ debug } ) ;
}
foreach my $ anvil_name ( sort { $ a cmp $ b } keys % { $ anvil - > data - > { anvils } { anvil_name } } )
{
my $ anvil_uuid = $ anvil - > data - > { anvils } { anvil_name } { $ anvil_name } { anvil_uuid } ;
my $ anvil_description = $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { anvil_description } ;
my $ anvil_node1_host_uuid = $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { anvil_node1_host_uuid } ;
my $ anvil_node2_host_uuid = $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { anvil_node2_host_uuid } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
's1:anvil_name' = > $ anvil_name ,
's2:anvil_uuid' = > $ anvil_uuid ,
's3:anvil_description' = > $ anvil_description ,
's4:anvil_node1_host_uuid' = > $ anvil_node1_host_uuid ,
's5:anvil_node2_host_uuid' = > $ anvil_node2_host_uuid ,
} } ) ;
# Loop through all files and see if there's a corresponding file_location for each sub-node.
my $ reload = 0 ;
foreach my $ file_name ( sort { $ a cmp $ b } keys % { $ anvil - > data - > { files } { file_name } } )
{
my $ file_uuid = $ anvil - > data - > { files } { file_name } { $ file_name } { file_uuid } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
's1:file_name' = > $ file_name ,
's2:file_uuid' = > $ file_uuid ,
} } ) ;
foreach my $ host_uuid ( $ anvil_node1_host_uuid , $ anvil_node2_host_uuid )
{
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { host_uuid = > $ host_uuid } } ) ;
if ( ( not exists $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } ) or
( $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ) )
{
# Add it
$ reload = 1 ;
my ( $ file_location_uuid ) = $ anvil - > Database - > insert_or_update_file_locations ( {
debug = > $ debug ,
file_location_file_uuid = > $ file_uuid ,
file_location_host_uuid = > $ host_uuid ,
file_location_active = > 1 ,
} ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
reload = > $ reload ,
file_location_uuid = > $ file_location_uuid ,
} } ) ;
}
}
}
if ( $ reload )
{
$ anvil - > Database - > get_file_locations ( { debug = > $ debug } ) ;
}
# Track the files on this Anvil!
foreach my $ file_location_uuid ( keys % { $ anvil - > data - > { file_locations } { file_location_uuid } } )
{
my $ file_uuid = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_file_uuid } ;
my $ file_type = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_type } ;
my $ file_name = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_name } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
file_location_uuid = > $ file_location_uuid ,
file_uuid = > $ file_uuid ,
file_type = > $ file_type ,
file_name = > $ file_name ,
} } ) ;
next if $ file_type eq "DELETED" ;
### TODO - Left off here, not adding DR links.
my $ anvil_needs_file = 0 ;
foreach my $ host_uuid ( $ anvil_node1_host_uuid , $ anvil_node2_host_uuid )
{
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { host_uuid = > $ host_uuid } } ) ;
if ( ( exists $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } ) &&
( $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ) )
{
my $ file_location_uuid = $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ;
my $ file_location_active = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
file_location_uuid = > $ file_location_uuid ,
file_location_active = > $ file_location_active ,
} } ) ;
if ( $ file_location_active )
{
$ anvil_needs_file = 1 ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { anvil_needs_file = > $ anvil_needs_file } } ) ;
}
}
}
# If either node wanted the file, both nodes and all linked DRs need it.
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { anvil_needs_file = > $ anvil_needs_file } } ) ;
if ( $ anvil_needs_file )
{
# Update the hosts
foreach my $ host_uuid ( $ anvil_node1_host_uuid , $ anvil_node2_host_uuid )
{
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { host_uuid = > $ host_uuid } } ) ;
my ( $ file_location_uuid ) = $ anvil - > Database - > insert_or_update_file_locations ( {
debug = > $ debug ,
file_location_file_uuid = > $ file_uuid ,
file_location_host_uuid = > $ host_uuid ,
file_location_active = > 1 ,
} ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { file_location_uuid = > $ file_location_uuid } } ) ;
}
# Make sure linked DR hosts have this file, also.
foreach my $ host_uuid ( keys % { $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { dr_host } } )
{
my $ file_location_uuid = $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ;
my $ file_location_active = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ;
if ( not $ file_location_active )
{
my ( $ file_location_uuid ) = $ anvil - > Database - > insert_or_update_file_locations ( {
debug = > $ debug ,
file_location_file_uuid = > $ file_uuid ,
file_location_host_uuid = > $ host_uuid ,
file_location_active = > 1 ,
} ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { file_location_uuid = > $ file_location_uuid } } ) ;
}
}
# If the file was deleted, this won't exist
next if not exists $ anvil - > data - > { files } { file_uuid } { $ file_uuid } ;
# Record that this Anvil! node has this file.
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_name } = $ file_name ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_directory } = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_directory } ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_size } = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_size } ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_md5sum } = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_md5sum } ;
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_type } = $ anvil - > data - > { files } { file_uuid } { $ file_uuid } { file_type } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_name" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_name } ,
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_directory" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_directory } ,
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_size" = > $ anvil - > Convert - > bytes_to_human_readable ( { 'bytes' = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_size } } ) . " (" . $ anvil - > Convert - > add_commas ( { number = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_size } } ) . ")" ,
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_md5sum" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_md5sum } ,
"anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_type" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_uuid } { $ file_uuid } { file_type } ,
} } ) ;
# Make it so that we can list the files by name.
$ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_name } { $ file_name } { file_uuid } = $ file_uuid ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
"anvils::anvil_uuid::${anvil_uuid}::file_name::${file_name}::file_uuid" = > $ anvil - > data - > { anvils } { anvil_uuid } { $ anvil_uuid } { file_name } { $ file_name } { file_uuid } ,
} } ) ;
# Make sure linked DR hosts have this file, also.
foreach my $ host_uuid ( keys % { $ anvil - > data - > { dr_links } { by_anvil_uuid } { $ anvil_uuid } { dr_link_host_uuid } } )
{
my $ host_name = $ anvil - > data - > { hosts } { host_uuid } { $ host_uuid } { host_name } ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
host_name = > $ host_name ,
host_uuid = > $ host_uuid ,
} } ) ;
my $ file_location_uuid = "" ;
my $ file_location_active = 0 ;
if ( exists $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } )
{
$ file_location_uuid = $ anvil - > data - > { file_locations } { host_uuid } { $ host_uuid } { file_uuid } { $ file_uuid } { file_location_uuid } ;
$ file_location_active = $ anvil - > data - > { file_locations } { file_location_uuid } { $ file_location_uuid } { file_location_active } ;
}
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > {
file_location_uuid = > $ file_location_uuid ,
file_location_active = > $ file_location_active ,
} } ) ;
if ( not $ file_location_active )
{
my ( $ file_location_uuid ) = $ anvil - > Database - > insert_or_update_file_locations ( {
debug = > $ debug ,
file_location_file_uuid = > $ file_uuid ,
file_location_host_uuid = > $ host_uuid ,
file_location_active = > 1 ,
} ) ;
$ anvil - > Log - > variables ( { source = > $ THIS_FILE , line = > __LINE__ , level = > $ debug , list = > { file_location_uuid = > $ file_location_uuid } } ) ;
}
}
}
}
}
return ( 0 ) ;
}
= head2 update_host_status
This is a variant on C << insert_or_update_hosts >> designed only to update the power status of a host .