Commit 63bd7b54 authored by Leigh Stoller's avatar Leigh Stoller

Reorg the environment variable stuff a bit so that the DP variables are

inserted for regular experiments as well as template instances.
parent c451b779
......@@ -26,6 +26,7 @@ use overload ('""' => 'Stringify');
# Configure variables
my $TB = "@prefix@";
my $BOSSNODE = "@BOSSNODE@";
my $CONTROL = "@USERNODE@";
my $EVENTSYS = @EVENTSYS@;
my $TEVC = "$TB/bin/tevc";
my $DBCONTROL = "$TB/sbin/opsdb_control";
......@@ -600,11 +601,33 @@ sub AddEnvVariable($$$;$)
$value = "''";
}
DBQueryWarn("replace into virt_user_environment set ".
" name='$name', value=$value, ".
(defined($index) ? "idx=$index, " : "") .
" pid='$pid', eid='$eid'")
or return -1;
#
# Look to see if the variable exists, since a replace will actually
# create a new row cause there is an auto_increment in the table that
# is used to maintain order of the variables as specified in the NS file.
#
my $query_result =
DBQueryWarn("select idx from virt_user_environment ".
"where name='$name' and pid='$pid' and eid='$eid'");
return -1
if (!$query_result);
if ($query_result->numrows) {
my $idx = (defined($index) ? $index :
($query_result->fetchrow_array())[0]);
DBQueryWarn("replace into virt_user_environment set ".
" name='$name', value=$value, idx=$idx, ".
" pid='$pid', eid='$eid'")
or return -1;
}
else {
DBQueryWarn("insert into virt_user_environment set ".
" name='$name', value=$value, idx=NULL, ".
" pid='$pid', eid='$eid'")
or return -1;
}
return 0;
}
......@@ -1431,5 +1454,39 @@ sub NodeStatusList($$)
return 0;
}
#
# Setup the environment variables for a swapin.
#
sub InitializeEnvVariables($)
{
my ($self) = @_;
# Must be a real reference.
return -1
if (! ref($self));
$self->Refresh() == 0
or return -1;
if ($self->dpdb() && $self->dpdbname() && $self->dpdbname() ne "") {
my $dpdbname = $self->dpdbname();
my $dpdbpassword = $self->dpdbpassword();
$self->AddEnvVariable("DP_DBNAME", $dpdbname) == 0
or return -1;
$self->AddEnvVariable("DP_HOST", $CONTROL) == 0
or return -1;
$self->AddEnvVariable("DP_USER", $dpdbname) == 0
or return -1;
$self->AddEnvVariable("DP_PASSWORD", $dpdbpassword) == 0
or return -1;
}
return 0;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -2908,23 +2908,7 @@ sub InitializeEnvVariables($;$)
"$instance_path/archive", 2)
== 0 or return -1;
if ($experiment->dpdb() && $experiment->dpdbname() ne "") {
my $dpdbname = $experiment->dpdbname();
my $dpdbpassword = $experiment->dpdbpassword();
$experiment->AddEnvVariable("DP_DBNAME", $dpdbname) == 0
or return -1;
$experiment->AddEnvVariable("DP_HOST", $CONTROL) == 0
or return -1;
$experiment->AddEnvVariable("DP_USER", $dpdbname) == 0
or return -1;
$experiment->AddEnvVariable("DP_PASSWORD", $dpdbpassword) == 0
or return -1;
}
# Now safe to do the rest.
#
# Before we actually swapin, copy the parameters to the environment
# table so that they are available to the program agent when it starts up
......
......@@ -474,6 +474,10 @@ if (! $TESTMODE) {
}
}
# Setup env variables.
$experiment->InitializeEnvVariables() == 0
or fatal("Could not initialize environment strings variables");
print "Writing environment strings ...\n";
$experiment->WriteEnvVariables() == 0
or fatal("Could not write environment strings for program agents");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment