Skip to content

Commit 4d18f11

Browse files
authored
Merge pull request #781 from ClusterLabs/beta-fixes
Added caching of subnode and DR host qemu capability caching.
2 parents b3361fd + 20b5d26 commit 4d18f11

File tree

6 files changed

+548
-21
lines changed

6 files changed

+548
-21
lines changed

Anvil/Tools.pm

+2
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ sub _set_paths
11221122
reboot_cache => "/tmp/anvil.reboot-needed",
11231123
'redhat-release' => "/etc/redhat-release",
11241124
fences_unified_metadata => "/var/www/html/fences_unified_metadata.xml",
1125+
qemu_host_capabilities => "/opt/alteeve/qemu-cache.xml",
11251126
},
11261127
devices => {
11271128
stdout => "/dev/stdout",
@@ -1308,6 +1309,7 @@ sub _set_paths
13081309
pvresize => "/usr/sbin/pvresize",
13091310
pvs => "/usr/sbin/pvs",
13101311
pvscan => "/usr/sbin/pvscan",
1312+
'qemu-kvm' => "/usr/libexec/qemu-kvm",
13111313
rm => "/usr/bin/rm",
13121314
rpm => "/usr/bin/rpm",
13131315
rsync => "/usr/bin/rsync",

Anvil/Tools/Database.pm

+186
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ my $THIS_FILE = "Database.pm";
6868
# insert_or_update_files
6969
# insert_or_update_health
7070
# insert_or_update_hosts
71+
# insert_or_update_host_variable
7172
# insert_or_update_ip_addresses
7273
# insert_or_update_jobs
7374
# insert_or_update_mail_servers
@@ -10297,6 +10298,191 @@ WHERE
1029710298
}
1029810299

1029910300

10301+
=head2 insert_or_update_host_variables
10302+
10303+
This updates (or inserts) a record in the 'host_variabless' table. The C<< host_variable_host_uuid >> UUID will be returned.
10304+
10305+
If there is an error, an empty string is returned.
10306+
10307+
Parameters;
10308+
10309+
=head3 host_variable_uuid (optional)
10310+
10311+
If this is specified, this will be the record updated. If this is not passed, a check will be made to see if there's an existing C<< host_variable_host_uuid >> and C<< host_variable_name >>. If matches are found, the record is updated. If not, a new entry is made.
10312+
10313+
=head3 host_variable_host_uuid (required, default Get->host_uuid)
10314+
10315+
This is the C<< host_uuid >> that the variable is being stored for.
10316+
10317+
=head3 host_variable_name (required)
10318+
10319+
This is the name of the variable.
10320+
10321+
=head3 host_variable_value (optional)
10322+
10323+
This is the value of the variable.
10324+
10325+
=cut
10326+
sub insert_or_update_host_variables
10327+
{
10328+
my $self = shift;
10329+
my $parameter = shift;
10330+
my $anvil = $self->parent;
10331+
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
10332+
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->insert_or_update_host_variables()" }});
10333+
10334+
my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : "";
10335+
my $file = defined $parameter->{file} ? $parameter->{file} : "";
10336+
my $line = defined $parameter->{line} ? $parameter->{line} : "";
10337+
my $host_variable_uuid = defined $parameter->{host_variable_uuid} ? $parameter->{host_variable_uuid} : "";
10338+
my $host_variable_host_uuid = defined $parameter->{host_variable_host_uuid} ? $parameter->{host_variable_host_uuid} : "";
10339+
my $host_variable_name = defined $parameter->{host_variable_name} ? $parameter->{host_variable_name} : "";
10340+
my $host_variable_value = defined $parameter->{host_variable_value} ? $parameter->{host_variable_value} : "";
10341+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
10342+
uuid => $uuid,
10343+
file => $file,
10344+
line => $line,
10345+
host_variable_uuid => $host_variable_uuid,
10346+
host_variable_host_uuid => $host_variable_host_uuid,
10347+
host_variable_name => $host_variable_name,
10348+
host_variable_value => $host_variable_value,
10349+
}});
10350+
10351+
# Do we have what we need?
10352+
if (not $host_variable_host_uuid)
10353+
{
10354+
$host_variable_host_uuid = $anvil->Get->host_uuid();
10355+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_variable_host_uuid => $host_variable_host_uuid }});
10356+
}
10357+
if (not $host_variable_name)
10358+
{
10359+
# Throw an error and exit.
10360+
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_host_variables()", parameter => "host_variable_name" }});
10361+
return("");
10362+
}
10363+
10364+
if (not $host_variable_uuid)
10365+
{
10366+
# We'll try to find the existing interface a couple ways. First we'll look up using
10367+
# '_on_uuid' as that's as specific as it gets.
10368+
my $query = "
10369+
SELECT
10370+
host_variable_uuid
10371+
FROM
10372+
host_variables
10373+
WHERE
10374+
host_variable_host_uuid = ".$anvil->Database->quote($host_variable_host_uuid)."
10375+
AND
10376+
host_variable_name = ".$anvil->Database->quote($host_variable_name)."
10377+
;";
10378+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
10379+
10380+
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
10381+
my $count = @{$results};
10382+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
10383+
results => $results,
10384+
count => $count,
10385+
}});
10386+
if ($count)
10387+
{
10388+
$host_variable_uuid = $results->[0]->[0];
10389+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_variable_uuid => $host_variable_uuid }});
10390+
}
10391+
}
10392+
10393+
# INSERT or UPDATE?
10394+
if (not $host_variable_uuid)
10395+
{
10396+
# INSERT
10397+
$host_variable_uuid = $anvil->Get->uuid();
10398+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_variable_uuid => $host_variable_uuid }});
10399+
10400+
my $query = "
10401+
INSERT INTO
10402+
host_variables
10403+
(
10404+
host_variable_uuid,
10405+
host_variable_host_uuid,
10406+
host_variable_name,
10407+
host_variable_value,
10408+
modified_date
10409+
) VALUES (
10410+
".$anvil->Database->quote($host_variable_uuid).",
10411+
".$anvil->Database->quote($host_variable_host_uuid).",
10412+
".$anvil->Database->quote($host_variable_name).",
10413+
".$anvil->Database->quote($host_variable_value).",
10414+
".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
10415+
);
10416+
";
10417+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
10418+
$anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
10419+
}
10420+
else
10421+
{
10422+
# Query the rest of the values and see if anything changed.
10423+
my $query = "
10424+
SELECT
10425+
host_variable_host_uuid,
10426+
host_variable_name,
10427+
host_variable_value
10428+
FROM
10429+
host_variables
10430+
WHERE
10431+
host_variable_uuid = ".$anvil->Database->quote($host_variable_uuid)."
10432+
;";
10433+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
10434+
10435+
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
10436+
my $count = @{$results};
10437+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
10438+
results => $results,
10439+
count => $count,
10440+
}});
10441+
if (not $count)
10442+
{
10443+
# I have a host_variable_uuid but no matching record. Probably an error.
10444+
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0216", variables => { uuid_name => "host_variable_uuid", uuid => $host_variable_uuid }});
10445+
return("");
10446+
}
10447+
foreach my $row (@{$results})
10448+
{
10449+
my $old_host_variable_host_uuid = $row->[0];
10450+
my $old_host_variable_name = $row->[1];
10451+
my $old_host_variable_value = $row->[2];
10452+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
10453+
old_host_variable_host_uuid => $old_host_variable_host_uuid,
10454+
old_host_variable_name => $old_host_variable_name,
10455+
old_host_variable_value => $old_host_variable_value,
10456+
}});
10457+
10458+
# Anything change?
10459+
if (($old_host_variable_host_uuid ne $host_variable_host_uuid) or
10460+
($old_host_variable_name ne $host_variable_name) or
10461+
($old_host_variable_value ne $host_variable_value))
10462+
{
10463+
# Something changed, save.
10464+
my $query = "
10465+
UPDATE
10466+
host_variables
10467+
SET
10468+
host_variable_host_uuid = ".$anvil->Database->quote($host_variable_host_uuid).",
10469+
host_variable_name = ".$anvil->Database->quote($host_variable_name).",
10470+
host_variable_value = ".$anvil->Database->quote($host_variable_value).",
10471+
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
10472+
WHERE
10473+
host_variable_uuid = ".$anvil->Database->quote($host_variable_uuid)."
10474+
";
10475+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
10476+
$anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
10477+
}
10478+
}
10479+
}
10480+
10481+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_variable_host_uuid => $host_variable_host_uuid }});
10482+
return($host_variable_host_uuid);
10483+
}
10484+
10485+
1030010486
=head2 insert_or_update_ip_addresses
1030110487

1030210488
This updates (or inserts) a record in the 'ip_addresses' table. The C<< ip_address_uuid >> referencing the database row will be returned.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# This will be the repository for the third generation of the Anvil! Intelligent Availability® platform.
1+
# This is the repository for the third generation of the Anvil! Intelligent Availability® platform.
22

33
Major components;
44

5-
* The "ScanCore" decision engine and scan agents.
5+
* The "ScanCore" decision engine and scan agents providing the "Intelligent Availability" capabilities.
66
* The "Striker" Web interface
77
* Tools for Striker dashboards, Anvil! nodes and DR targets
88

share/anvil.sql

+19-19
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ CREATE TRIGGER trigger_users
237237

238238

239239
-- This stores special variables for a given host that programs may want to record.
240-
CREATE TABLE host_variable (
240+
CREATE TABLE host_variables (
241241
host_variable_uuid uuid not null primary key,
242242
host_variable_host_uuid uuid not null,
243243
host_variable_name text not null,
@@ -246,45 +246,45 @@ CREATE TABLE host_variable (
246246

247247
FOREIGN KEY(host_variable_host_uuid) REFERENCES hosts(host_uuid)
248248
);
249-
ALTER TABLE host_variable OWNER TO admin;
249+
ALTER TABLE host_variables OWNER TO admin;
250250

251-
CREATE TABLE history.host_variable (
251+
CREATE TABLE history.host_variables (
252252
history_id bigserial,
253253
host_variable_uuid uuid,
254254
host_variable_host_uuid uuid,
255255
host_variable_name text,
256256
host_variable_value text,
257257
modified_date timestamp with time zone not null
258258
);
259-
ALTER TABLE history.host_variable OWNER TO admin;
259+
ALTER TABLE history.host_variables OWNER TO admin;
260260

261-
CREATE FUNCTION history_host_variable() RETURNS trigger
261+
CREATE FUNCTION history_host_variables() RETURNS trigger
262262
AS $$
263263
DECLARE
264-
history_host_variable RECORD;
264+
history_host_variables RECORD;
265265
BEGIN
266-
SELECT INTO history_host_variable * FROM host_variable WHERE host_uuid = new.host_uuid;
267-
INSERT INTO history.host_variable
268-
(host_variable_uuid,
266+
SELECT INTO history_host_variables * FROM host_variables WHERE host_variable_uuid = new.host_variable_uuid;
267+
INSERT INTO history.host_variables
268+
(host_variable_uuid,
269269
host_variable_host_uuid,
270270
host_variable_name,
271271
host_variable_value,
272-
modified_date)
272+
modified_date)
273273
VALUES
274-
(history_host_variable.host_variable_uuid,
275-
history_host_variable.host_variable_host_uuid,
276-
history_host_variable.host_variable_name,
277-
history_host_variable.host_variable_value,
278-
history_host_variable.modified_date);
274+
(history_host_variables.host_variable_uuid,
275+
history_host_variables.host_variable_host_uuid,
276+
history_host_variables.host_variable_name,
277+
history_host_variables.host_variable_value,
278+
history_host_variables.modified_date);
279279
RETURN NULL;
280280
END;
281281
$$
282282
LANGUAGE plpgsql;
283-
ALTER FUNCTION history_host_variable() OWNER TO admin;
283+
ALTER FUNCTION history_host_variables() OWNER TO admin;
284284

285-
CREATE TRIGGER trigger_host_variable
286-
AFTER INSERT OR UPDATE ON host_variable
287-
FOR EACH ROW EXECUTE PROCEDURE history_host_variable();
285+
CREATE TRIGGER trigger_host_variables
286+
AFTER INSERT OR UPDATE ON host_variables
287+
FOR EACH ROW EXECUTE PROCEDURE history_host_variables();
288288

289289

290290
-- This stores user session information on a per-dashboard basis.

0 commit comments

Comments
 (0)