commit
3b1afa0d92
11 changed files with 812 additions and 189 deletions
@ -0,0 +1,183 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# This prints JSON formated data reporting the status of an file systems on nodes and DR hosts. |
||||
# |
||||
|
||||
use strict; |
||||
use warnings; |
||||
use Anvil::Tools; |
||||
use Data::Dumper; |
||||
use JSON; |
||||
|
||||
$| = 1; |
||||
|
||||
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
||||
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
||||
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
||||
{ |
||||
$running_directory =~ s/^\./$ENV{PWD}/; |
||||
} |
||||
|
||||
my $anvil = Anvil::Tools->new(); |
||||
|
||||
$anvil->Get->switches; |
||||
|
||||
$anvil->Database->connect; |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); |
||||
if (not $anvil->data->{sys}{database}{connections}) |
||||
{ |
||||
# No databases, exit. |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"}); |
||||
$anvil->nice_exit({exit_code => 1}); |
||||
} |
||||
|
||||
# Read in any CGI variables, if needed. |
||||
$anvil->Get->cgi(); |
||||
|
||||
$anvil->Database->get_hosts(); |
||||
$anvil->Database->get_anvils(); |
||||
|
||||
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n"; |
||||
|
||||
my $hash = { file_systems => [] }; |
||||
my $anvil_uuid = ""; |
||||
if ($anvil->data->{cgi}{anvil_uuid}{value}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
elsif ($anvil->data->{switches}{'anvil-uuid'}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{switches}{'anvil-uuid'}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})) |
||||
{ |
||||
$anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'anvil_status::anvil_name' => $anvil->data->{anvil_status}{anvil_name} }}); |
||||
} |
||||
else |
||||
{ |
||||
my $node1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; |
||||
my $node2_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid}; |
||||
my $dr1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
node1_uuid => $node1_uuid, |
||||
node2_uuid => $node2_uuid, |
||||
dr1_uuid => $dr1_uuid, |
||||
}}); |
||||
|
||||
my $query = " |
||||
SELECT |
||||
a.host_uuid, |
||||
a.host_name, |
||||
b.scan_filesystem_mount_point, |
||||
b.scan_filesystem_size, |
||||
b.scan_filesystem_used |
||||
FROM |
||||
hosts a, |
||||
scan_filesystems b |
||||
WHERE |
||||
a.host_uuid = b.scan_filesystem_host_uuid |
||||
AND |
||||
( |
||||
a.host_uuid = ".$anvil->Database->quote($node1_uuid)." |
||||
OR |
||||
a.host_uuid = ".$anvil->Database->quote($node2_uuid); |
||||
if ($dr1_uuid) |
||||
{ |
||||
$query .= " |
||||
OR |
||||
a.host_uuid = ".$anvil->Database->quote($dr1_uuid); |
||||
} |
||||
$query .= " |
||||
) |
||||
ORDER BY |
||||
a.host_name ASC, |
||||
b.scan_filesystem_mount_point DESC |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $host_uuid = $row->[0]; |
||||
my $host_name = $row->[1]; |
||||
my $mount_point = $row->[2]; |
||||
my $size = $row->[3]; |
||||
my $used = $row->[4]; |
||||
my $free = $size - $used; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
host_uuid => $host_uuid, |
||||
host_name => $host_name, |
||||
mount_point => $mount_point, |
||||
size => $anvil->Convert->add_commas({number => $size})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $size}).")",, |
||||
used => $anvil->Convert->add_commas({number => $used})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $used}).")",, |
||||
free => $anvil->Convert->add_commas({number => $free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $free}).")",, |
||||
}}); |
||||
|
||||
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name} = $host_name; |
||||
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total} = $size; |
||||
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free} = $free; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
"raw::file_systems::${mount_point}::nodes::${host_uuid}::host_name" => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name}, |
||||
"raw::file_systems::${mount_point}::nodes::${host_uuid}::total" => $anvil->Convert->add_commas({number => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}}).")",, |
||||
"raw::file_systems::${mount_point}::nodes::${host_uuid}::free" => $anvil->Convert->add_commas({number => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}}).")",, |
||||
}}); |
||||
} |
||||
|
||||
foreach my $mount_point (sort {$a cmp $b} keys %{$anvil->data->{raw}{file_systems}}) |
||||
{ |
||||
# Make a FS hash, which will be pushed into the file_systems array in the response body. |
||||
my $file_system = {}; |
||||
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mount_point => $mount_point }}); |
||||
$file_system->{mount_point} = $mount_point; |
||||
$file_system->{hosts} = []; |
||||
my $nodes = [$node1_uuid, $node2_uuid]; |
||||
if ($dr1_uuid) |
||||
{ |
||||
push @{$nodes}, $dr1_uuid; |
||||
} |
||||
foreach my $host_uuid (@{$nodes}) |
||||
{ |
||||
my $host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
host_uuid => $host_uuid, |
||||
host_name => $host_name, |
||||
}}); |
||||
if (exists $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}) |
||||
{ |
||||
push @{$file_system->{hosts}}, { |
||||
host_uuid => $host_uuid, |
||||
host_name => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name}, |
||||
# \1 will be transformed to the JSON boolean "true" by the JSON module. |
||||
is_mounted => \1, |
||||
# FS total size is required by the spec to be an JSON number rather than string. |
||||
total => int($anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}), |
||||
free => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}, |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
push @{$file_system->{hosts}}, { |
||||
host_uuid => $host_uuid, |
||||
host_name => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name}, |
||||
# \0 will be transformed to the JSON boolean "false" by the JSON module. |
||||
is_mounted => \0, |
||||
total => 0, |
||||
free => 0, |
||||
} |
||||
} |
||||
} |
||||
|
||||
# Push the filled FS has into the response body's file_systems array. |
||||
push(@{$hash->{file_systems}}, $file_system); |
||||
} |
||||
} |
||||
|
||||
print JSON->new->utf8->encode($hash)."\n"; |
@ -0,0 +1,236 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# This prints JSON formatted data about all networks within a specified anvil. |
||||
# |
||||
|
||||
use strict; |
||||
use warnings; |
||||
use Anvil::Tools; |
||||
use Data::Dumper; |
||||
use JSON; |
||||
|
||||
$| = 1; |
||||
|
||||
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
||||
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
||||
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
||||
{ |
||||
$running_directory =~ s/^\./$ENV{PWD}/; |
||||
} |
||||
|
||||
my $anvil = Anvil::Tools->new(); |
||||
|
||||
sub handle_invalid_uuid |
||||
{ |
||||
my $parameters = shift; |
||||
my $name = $parameters->{name}; |
||||
my $uuid = $parameters->{uuid}; |
||||
|
||||
$anvil->Log->entry({ |
||||
source => $THIS_FILE, |
||||
line => __LINE__, |
||||
level => 0, |
||||
'print' => 1, |
||||
priority => "err", |
||||
key => "error_0160", |
||||
variables => { name => $name, uuid => $uuid } |
||||
}); |
||||
$anvil->nice_exit({ exit_code => 1 }); |
||||
} |
||||
|
||||
sub get_anvil_networks |
||||
{ |
||||
my $parameters = shift; |
||||
my $anvil_uuid = $parameters->{anvil_uuid}; |
||||
|
||||
my @host_uuids = ( |
||||
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}, |
||||
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid} |
||||
); |
||||
my $anvil_networks = []; |
||||
|
||||
foreach (@host_uuids) |
||||
{ |
||||
my $host_networks = get_host_networks({ host_uuid => $_ }); |
||||
|
||||
push(@$anvil_networks, $host_networks); |
||||
} |
||||
|
||||
return $anvil_networks; |
||||
} |
||||
|
||||
sub get_host_networks |
||||
{ |
||||
my $parameters = shift; |
||||
my $host_uuid = $parameters->{host_uuid}; |
||||
my $host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name}; |
||||
|
||||
# Note: the subprocess name matches its definition; there is a typo though. |
||||
$anvil->Network->load_interfces({ host_uuid => $host_uuid, host => $host_name }); |
||||
|
||||
my $host_networks_data = $anvil->data->{network}{$host_name}; |
||||
my $interfaces = $host_networks_data->{interface}; |
||||
my $bond_uuids = $host_networks_data->{bond_uuid}; |
||||
my $bond_uuid_index_map = {}; |
||||
my $host_networks = { |
||||
host_uuid => $host_uuid, |
||||
host_name => $host_name, |
||||
bonds => [] |
||||
}; |
||||
|
||||
my $build_bond_link_hash = sub { |
||||
my $parameters = shift; |
||||
my $bond_data = $parameters->{bond_data}; |
||||
my $link_name = $parameters->{link_name}; |
||||
my $link_data = $parameters->{link_data}; |
||||
my $known_links = $parameters->{known_links}; |
||||
|
||||
my $link_speed = $link_data->{speed}; |
||||
my $link_state = $link_data->{operational} eq "up" ? "optimal" : "down"; |
||||
|
||||
my $degrade_link_state = sub { |
||||
my $current_link_state = shift; |
||||
|
||||
return $current_link_state eq "optimal" ? "degraded" : $current_link_state; |
||||
}; |
||||
|
||||
# When at lease 1 link has already been processed, check this link against them. |
||||
if ($known_links) |
||||
{ |
||||
my $known_links_index = 0; |
||||
my $known_links_length = scalar(@$known_links); |
||||
|
||||
foreach (@$known_links) |
||||
{ |
||||
# Degrade the link with lower speed. |
||||
if ($_->{link_speed} < $link_speed) |
||||
{ |
||||
$_->{link_state} = &$degrade_link_state($_->{link_state}); |
||||
} |
||||
elsif ($_->{link_state} > $link_speed) |
||||
{ |
||||
$link_state = &$degrade_link_state($link_state); |
||||
} |
||||
|
||||
$anvil->Log->variables({ |
||||
source => $THIS_FILE, |
||||
line => __LINE__, |
||||
level => 2, |
||||
list => { |
||||
known_link_name => $_->{link_name}, |
||||
known_link_speed => $_->{link_speed}, |
||||
known_link_state => $_->{link_state}, |
||||
link_speed => $link_speed, |
||||
link_name => $link_name, |
||||
link_state => $link_state |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
return { |
||||
link_name => $link_name, |
||||
link_uuid => $link_data->{uuid}, |
||||
link_speed => $link_speed, |
||||
link_state => $link_state, |
||||
is_active => $link_name eq $bond_data->{active_interface} ? \1 : \0 |
||||
}; |
||||
}; |
||||
|
||||
foreach my $interface_name (sort { $a cmp $b } keys %$interfaces) |
||||
{ |
||||
my $interface = $interfaces->{$interface_name}; |
||||
# Only a bond's link will have the bond_uuid entry. |
||||
my $bond_uuid = $interface->{bond_uuid}; |
||||
|
||||
if ($bond_uuid) |
||||
{ |
||||
my $bond_name = $bond_uuids->{$bond_uuid}{name}; |
||||
my $bond_index = $bond_uuid_index_map->{$bond_uuid}; |
||||
|
||||
$anvil->Log->variables({ |
||||
source => $THIS_FILE, |
||||
line => __LINE__, |
||||
level => 2, |
||||
list => { |
||||
bond_name => $bond_name, |
||||
bond_index => $bond_index |
||||
} |
||||
}); |
||||
|
||||
if (defined $bond_index) |
||||
{ |
||||
my $bond = @{$host_networks->{bonds}}[$bond_index]; |
||||
|
||||
push(@{$bond->{links}}, &$build_bond_link_hash({ |
||||
bond_data => $interfaces->{$bond_name}, |
||||
link_name => $interface_name, |
||||
link_data => $interface, |
||||
known_links => $bond->{links} |
||||
})); |
||||
} |
||||
else |
||||
{ |
||||
my $bond = { bond_name => $bond_name, bond_uuid => $bond_uuid, links => [] }; |
||||
my $link = &$build_bond_link_hash({ |
||||
bond_data => $interfaces->{$bond_name}, |
||||
link_name => $interface_name, |
||||
link_data => $interface |
||||
}); |
||||
|
||||
push(@{$bond->{links}}, $link); |
||||
|
||||
push(@{$host_networks->{bonds}}, $bond); |
||||
|
||||
# Get the index of the most recently inserted item and map it to the bond's UUID. |
||||
$bond_uuid_index_map->{$bond_uuid} = $#{$host_networks->{bonds}}; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return $host_networks; |
||||
} |
||||
|
||||
$anvil->Get->switches; |
||||
|
||||
$anvil->Database->connect; |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); |
||||
if (not $anvil->data->{sys}{database}{connections}) |
||||
{ |
||||
# No databases, exit. |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"}); |
||||
$anvil->nice_exit({exit_code => 1}); |
||||
} |
||||
|
||||
# Read in any CGI variables, if needed. |
||||
$anvil->Get->cgi(); |
||||
|
||||
$anvil->Database->get_hosts(); |
||||
$anvil->Database->get_anvils(); |
||||
|
||||
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n"; |
||||
|
||||
my $anvil_uuid = exists $anvil->data->{cgi}{anvil_uuid}{value} ? $anvil->data->{cgi}{anvil_uuid}{value} : $anvil->data->{switches}{'anvil-uuid'}; |
||||
my $anvil_uuid_variable_name = "anvil UUID"; |
||||
|
||||
my $response_body = {}; |
||||
|
||||
if ($anvil_uuid) |
||||
{ |
||||
if (exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}) |
||||
{ |
||||
my $anvil_networks = get_anvil_networks({ anvil_uuid => $anvil_uuid }); |
||||
|
||||
$response_body->{hosts} = $anvil_networks; |
||||
} |
||||
else |
||||
{ |
||||
handle_invalid_uuid({ name => $anvil_uuid_variable_name, uuid => $anvil_uuid }); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
handle_invalid_uuid({ name => $anvil_uuid_variable_name, uuid => $anvil_uuid }); |
||||
} |
||||
|
||||
print JSON->new->utf8->encode($response_body)."\n"; |
@ -0,0 +1,215 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# Accepts a HTTP PUT request to set the cluster membership of a host. |
||||
# |
||||
|
||||
use strict; |
||||
use warnings; |
||||
use Anvil::Tools; |
||||
use Data::Dumper; |
||||
use JSON |
||||
|
||||
$| = 1; |
||||
|
||||
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
||||
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
||||
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
||||
{ |
||||
$running_directory =~ s/^\./$ENV{PWD}/; |
||||
} |
||||
|
||||
my $anvil = Anvil::Tools->new(); |
||||
|
||||
sub handle_invalid_uuid |
||||
{ |
||||
my $parameters = shift; |
||||
my $name = $parameters->{name}; |
||||
my $uuid = $parameters->{uuid}; |
||||
|
||||
$anvil->Log->entry({ |
||||
source => $THIS_FILE, |
||||
line => __LINE__, |
||||
level => 0, |
||||
'print' => 1, |
||||
priority => "err", |
||||
key => "error_0160", |
||||
variables => { name => $name, uuid => $uuid } |
||||
}); |
||||
$anvil->nice_exit({ exit_code => 1 }); |
||||
} |
||||
|
||||
sub get_active_member |
||||
{ |
||||
my $parameters = shift; |
||||
my $host_uuid = $parameters->{host_uuid}; |
||||
|
||||
my $query = " |
||||
SELECT |
||||
scan_cluster_node_in_ccm, |
||||
scan_cluster_node_crmd_member, |
||||
scan_cluster_node_cluster_member |
||||
FROM |
||||
scan_cluster_nodes |
||||
WHERE |
||||
scan_cluster_node_host_uuid = ".$anvil->Database->quote($host_uuid)." |
||||
"; |
||||
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query } }); |
||||
my $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ }); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count |
||||
} }); |
||||
|
||||
if ($count == 1) |
||||
{ |
||||
my $row = $results->[0]; |
||||
my $is_in_ccm = $row->[0]; |
||||
my $is_crmd_member = $row->[1]; |
||||
my $is_cluster_member = $row->[2]; |
||||
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
is_in_ccm => $is_in_ccm, |
||||
is_crmd_member => $is_crmd_member, |
||||
is_cluster_member => $is_cluster_member |
||||
} }); |
||||
|
||||
return $is_in_ccm && $is_crmd_member && $is_cluster_member; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
sub alter_host_membership |
||||
{ |
||||
# Expects the first of positional parameters to be a hash. |
||||
my $parameters = shift; |
||||
my $host_uuid = $parameters->{host_uuid}; |
||||
my $is_join_cluster = $parameters->{is_join_cluster}; |
||||
|
||||
if ($is_join_cluster) |
||||
{ |
||||
join_cluster({ host_uuid => $host_uuid }); |
||||
} |
||||
else |
||||
{ |
||||
leave_cluster({ host_uuid => $host_uuid }); |
||||
} |
||||
} |
||||
|
||||
# Re-adds a host to its anvil cluster. |
||||
# |
||||
# Note: not to be confused wtih adding a new host the an anvil. |
||||
sub join_cluster |
||||
{ |
||||
my $parameters = shift; |
||||
my $host_uuid = $parameters->{host_uuid}; |
||||
|
||||
# Determine whether host is already a cluster member. |
||||
my $is_active_member = get_active_member({ host_uuid => $host_uuid }); |
||||
# Find out whether the host is online before trying to make it join the cluster. |
||||
my $is_online = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_status} eq "online" ? 1 : 0; |
||||
|
||||
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
is_active_member => $is_active_member, |
||||
is_online => $is_online |
||||
} }); |
||||
|
||||
if (not $is_active_member && $is_online) |
||||
{ |
||||
$anvil->Database->insert_or_update_jobs({ |
||||
job_command => $anvil->data->{path}{exe}{'anvil-safe-start'}, |
||||
job_host_uuid => $host_uuid, |
||||
job_description => "job_0337", |
||||
job_name => "cgi-bin::set_membership::join", |
||||
job_progress => 0, |
||||
job_title => "job_0336" |
||||
}); |
||||
} |
||||
} |
||||
|
||||
# Removes a host from its anvil cluster. |
||||
# |
||||
# Note: does not permanently remove the host; can be re-added. |
||||
sub leave_cluster |
||||
{ |
||||
my $parameters = shift; |
||||
my $host_uuid = $parameters->{host_uuid}; |
||||
|
||||
# Determine whether host is already a cluster member. |
||||
my $is_active_member = get_active_member({ host_uuid => $host_uuid }); |
||||
|
||||
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
is_active_member => $is_active_member |
||||
} }); |
||||
|
||||
if ($is_active_member) |
||||
{ |
||||
$anvil->Database->insert_or_update_jobs({ |
||||
job_command => $anvil->data->{path}{exe}{'anvil-safe-stop'}, |
||||
job_host_uuid => $host_uuid, |
||||
job_description => "job_0339", |
||||
job_name => "cgi-bin::set_membership::leave", |
||||
job_progress => 0, |
||||
job_title => "job_0338" |
||||
}); |
||||
} |
||||
} |
||||
|
||||
$anvil->Get->switches; |
||||
|
||||
$anvil->Database->connect; |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); |
||||
if (not $anvil->data->{sys}{database}{connections}) |
||||
{ |
||||
# No databases, exit. |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"}); |
||||
$anvil->nice_exit({exit_code => 1}); |
||||
} |
||||
|
||||
# Read in any CGI variables, if needed. |
||||
$anvil->Get->cgi(); |
||||
|
||||
$anvil->Database->get_hosts(); |
||||
$anvil->Database->get_anvils(); |
||||
|
||||
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n"; |
||||
|
||||
my $response_body = {}; |
||||
|
||||
my $request_body; |
||||
|
||||
my $is_decode_json_success = eval { |
||||
$request_body = decode_json($anvil->data->{cgi}{PUTDATA}{value}); |
||||
}; |
||||
|
||||
if (not $is_decode_json_success) |
||||
{ |
||||
$anvil->Log->entry({ |
||||
source => $THIS_FILE, |
||||
line => __LINE__, |
||||
level => 0, |
||||
'print' => 1, |
||||
priority => "err", |
||||
key => "error_0304", |
||||
variables => { request_body_string => $anvil->data->{cgi}{PUTDATA}{value}, json_decode_error => $_ } |
||||
}); |
||||
} |
||||
|
||||
my $host_uuid = exists $request_body->{host_uuid} ? $request_body->{host_uuid} : $anvil->data->{switches}{'host-uuid'}; |
||||
# Defaults to join; will check whether host is already part of its anvil cluster. |
||||
my $is_member = exists $request_body->{is_member} ? $request_body->{is_member} : $anvil->data->{switches}{'is-member'}; |
||||
my $host_uuid_variable_name = "host UUID"; |
||||
|
||||
if ($host_uuid) |
||||
{ |
||||
if (exists $anvil->data->{hosts}{host_uuid}{$host_uuid}) |
||||
{ |
||||
alter_host_membership({ host_uuid => $host_uuid, is_join_cluster => $is_member }); |
||||
} |
||||
else |
||||
{ |
||||
handle_invalid_uuid({ name => $host_uuid_variable_name, uuid => $host_uuid }); |
||||
} |
||||
} |
||||
|
||||
print JSON->new->utf8->encode($response_body)."\n"; |
Loading…
Reference in new issue