Commit 2ebc2a91 authored by Leigh Stoller's avatar Leigh Stoller

Some fixes to how the environment strings are setup for a new run so that

if a swapmod is done, the new program agents see the right strings.
parent 3e66d147
......@@ -2753,11 +2753,6 @@ sub NewRunBinding($$$)
" name='$name', value=$value")
or return -1;
DBQueryWarn("replace into virt_user_environment set ".
" name='$name', value=$value, ".
" exptidx='$exptidx', pid='$pid', eid='$eid'")
or return -1;
return 0;
}
......@@ -3373,9 +3368,9 @@ sub WriteProgramAgents($)
#
# Setup the environment variables for a template swapin.
#
sub InitializeEnvVariables($;$)
sub InitializeEnvVariables($)
{
my ($self, $parameters) = @_;
my ($self) = @_;
# Must be a real reference.
return -1
......@@ -3429,10 +3424,23 @@ sub InitializeEnvVariables($;$)
# table so that they are available to the program agent when it starts up
# on the nodes.
#
if (defined($parameters)) {
foreach my $name (keys(%{ $parameters })) {
my $value = $parameters->{$name};
# Have to watch for the initial swapin since there will not be a current
# run yet. In this case, grab the environment variables from the instance.
#
my %parameters;
if (defined($self->runidx())) {
$self->RunBindingList(\%parameters) == 0 or return -1;
}
else {
$self->BindingList(\%parameters) == 0 or return -1;
}
if (%parameters) {
foreach my $name (keys(%parameters)) {
my $value = $parameters{$name};
# This actually replaces.
$experiment->AddEnvVariable($name, $value) == 0
or return -1;
}
......
......@@ -52,6 +52,7 @@ use libdb;
use libtestbed;
use libtblog;
use Experiment;
use Template;
#
# Turn off line buffering on output
......@@ -88,7 +89,7 @@ if (! -r $nsfile) {
# Slowly convert to using Experiment module.
my $experiment = Experiment->Lookup($pideid);
if (!defined($experiment)) {
tbdie("Could not lookup experiment object for $pideid!")
tbdie("Could not lookup experiment object for $pideid!");
}
# Need these below.
my $pid = $experiment->pid();
......@@ -96,6 +97,14 @@ my $eid = $experiment->eid();
my $state = $experiment->state();
my $gid = $experiment->gid();
my $exptidx = $experiment->idx();
my $instance;
if ($experiment->IsInstance()) {
$instance = Template::Instance->LookupByExptidx($experiment->idx());
if (!defined($instance)) {
tbdie("Could not lookup instance object for $exptidx!");
}
}
print "Beginning pre run for $pid/$eid. " . TBTimeStamp() . "\n";
TBDebugTimeStamp("tbprerun started");
......@@ -395,8 +404,14 @@ if (! $TESTMODE) {
}
# Setup env variables.
$experiment->InitializeEnvVariables() == 0
or fatal("Could not initialize environment strings variables");
if ($experiment->IsInstance()) {
$instance->InitializeEnvVariables() == 0
or fatal("Could not initialize environment strings variables");
}
else {
$experiment->InitializeEnvVariables() == 0
or fatal("Could not initialize environment strings variables");
}
print "Writing environment strings ...\n";
$experiment->WriteEnvVariables() == 0
......
......@@ -630,6 +630,18 @@ if ($action eq "modify") {
$instance->WriteProgramAgents() == 0
or fatal(-1, "Could not write program agent info");
}
else {
#
# The swapmod would have rewritten the environment strings, but otherwise
# it has to be done by hand.
#
$instance->InitializeEnvVariables() == 0
or fatal(-1, "Could not update environment variables for $instance");
print "Writing new environment strings ...\n";
$instance->WriteEnvVariables() == 0
or fatal(-1, "Could not rewrite environment strings for $instance");
}
#
# Now we stash the parameter file for the next version of the archive.
......@@ -645,17 +657,6 @@ if (defined($paramfile)) {
or fatal(-1, "Could not copy $source to $target");
}
#
# We munge the environment variables *AFTER* the potential swapmod since
# it will have scrogged the user env.
#
$instance->InitializeEnvVariables(\%parameters) == 0
or fatal(-1, "Could not add new environment variables to instance");
print "Writing environment strings ...\n";
$instance->WriteEnvVariables() == 0
or fatal(-1, "Could not write environment strings for program agents");
if ($experiment->HaveProgramAgents()) {
print "Asking program agents to reload ... this will take a moment.\n";
SignalProgAgents("RELOAD") == 0
......
......@@ -564,19 +564,6 @@ $instance->CopyDataStore($datastore_tag,
$instance->CopyTemplateEvents() == 0
or fatal(-1, "Could not copy template events to instance");
# We munge the environment variables.
$instance->InitializeEnvVariables(\%parameters) == 0
or fatal(-1, "Could not add new environment variables to instance");
print "Writing environment strings ...\n";
$instance->WriteEnvVariables() == 0
or fatal(-1, "Could not write environment strings for program agents");
# This has to be redone since the batchexp will have written incomplete data.
print "Writing program agent info ...\n";
$instance->WriteProgramAgents() == 0
or fatal(-1, "Could not write program agent info");
if (! $preload) {
if ($STAMPS) {
$instance->Stamp("template_instantiate", "swapin starting");
......
......@@ -293,6 +293,24 @@ if (! ($foreground || $experiment->batchmode())) {
}
}
#
# All instances currently start with a default run.
#
$run = $instance->NewRun($eid, $this_user, $instance->description());
if (!defined($run)) {
fatal(-1, "Could not create new experiment run for $instance!");
}
#
# And the bindings for the default run ...
#
foreach my $name (keys(%parameters)) {
my $value = $parameters{$name};
$instance->NewRunBinding($name, $value) == 0
or fatal(-1, "Error inserting run binding into DB!");
}
# Event connect before starting swapin so we catch all the states.
SetupEventHandler()
if ($experiment->batchmode());
......@@ -373,34 +391,6 @@ if ($?) {
fatal(-1, "Could not commit archive!");
}
#
# All instances currently start with a default run.
#
$run = $instance->NewRun($eid, $this_user, $instance->description());
if (!defined($run)) {
fatal(-1, "Could not create new experiment run for $instance!");
}
#
# And create a tag (and subdir) for this run. This is primarily a convenience
# function for the web interface. The tag is simply an alias to the current
# trunk and does not cause a savepoint or a commit.
#
system("$archcontrol -u -s runs/$eid tag $pid $eid startrun");
if ($?) {
fatal(-1, "Could not commit archive!");
}
#
# And the bindings for the default run ...
#
foreach my $name (keys(%parameters)) {
my $value = $parameters{$name};
$instance->NewRunBinding($name, $value) == 0
or fatal(-1, "Error inserting run binding into DB!");
}
$instance->StartRun(Template::STARTRUN_FLAGS_FIRSTRUN()) == 0
or fatal(-1, "Could not update start time in instance record!");
......
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