Commit 6fe3979f authored by Leigh Stoller's avatar Leigh Stoller

Database changes for deferred/scheduled experiments.

parent cd89db19
......@@ -321,8 +321,15 @@ sub Create($$$)
$$perrmsg = "Instance name already in use!";
return undef;
}
my $query = "insert into apt_instances set created=now(),uuid='$uuid', ".
my $sets = "created=now(),uuid='$uuid'";
if (exists($argref->{"start_at"}) && defined($argref->{"start_at"})) {
$sets .= ", start_at=FROM_UNIXTIME(" . $argref->{"start_at"} . ")";
delete($argref->{"start_at"});
}
else {
$sets .= ", started=created";
}
my $query = "insert into apt_instances set ${sets}, ".
join(",", map("$_=" .
DBQuoteSpecial($argref->{$_}), keys(%{$argref})));
......@@ -661,7 +668,7 @@ sub RecordHistory($$)
" creator,creator_idx,creator_uuid,pid,pid_idx, ".
" gid,gid_idx, ".
" aggregate_urn,public_url,logfileid, ".
" created,now(),$expired, ".
" created,start_at,started,stop_at,now(),$expired, ".
" extension_count,extension_days,extension_hours, ".
" physnode_count,virtnode_count, ".
" servername,repourl,reponame,reporef,repohash, ".
......@@ -682,8 +689,8 @@ sub RecordError($$$)
"select uuid,name,profile_id,profile_version,slice_uuid, ".
" creator,creator_idx,creator_uuid,pid,pid_idx, ".
" gid,gid_idx, ".
" created,'$exitcode',$safe_message,public_url, ".
" logfileid ".
" created,start_at,started,stop_at,'$exitcode', ".
" $safe_message,public_url,logfileid ".
" from apt_instances where uuid='$uuid'")
or return -1;
......
......@@ -183,6 +183,7 @@ DROP TABLE IF EXISTS `apt_deferred_instances`;
CREATE TABLE `apt_deferred_instances` (
`uuid` varchar(40) NOT NULL default '',
`name` varchar(16) default NULL,
`start_at` datetime default NULL,
`last_retry` datetime default NULL,
`retry_until` datetime default NULL,
PRIMARY KEY (`uuid`)
......@@ -237,6 +238,7 @@ CREATE TABLE `apt_instance_aggregate_history` (
`name` varchar(16) default NULL,
`aggregate_urn` varchar(128) NOT NULL default '',
`status` varchar(32) default NULL,
`started` datetime default NULL,
`physnode_count` smallint(5) unsigned NOT NULL default '0',
`virtnode_count` smallint(5) unsigned NOT NULL default '0',
`retry_count` smallint(5) unsigned NOT NULL default '0',
......@@ -257,6 +259,7 @@ CREATE TABLE `apt_instance_aggregates` (
`name` varchar(16) default NULL,
`aggregate_urn` varchar(128) NOT NULL default '',
`status` varchar(32) default NULL,
`started` datetime default NULL,
`physnode_count` smallint(5) unsigned NOT NULL default '0',
`virtnode_count` smallint(5) unsigned NOT NULL default '0',
`retry_count` smallint(5) unsigned NOT NULL default '0',
......@@ -313,6 +316,9 @@ CREATE TABLE `apt_instance_failures` (
`gid` varchar(32) NOT NULL default '',
`gid_idx` mediumint(8) unsigned NOT NULL default '0',
`created` datetime default NULL,
`start_at` datetime default NULL,
`started` datetime default NULL,
`stop_at` datetime default NULL,
`exitcode` int(10) default '0',
`exitmessage` mediumtext,
`public_url` tinytext,
......@@ -342,6 +348,9 @@ CREATE TABLE `apt_instance_history` (
`public_url` tinytext,
`logfileid` varchar(40) default NULL,
`created` datetime default NULL,
`start_at` datetime default NULL,
`started` datetime default NULL,
`stop_at` datetime default NULL,
`destroyed` datetime default NULL,
`expired` tinyint(1) NOT NULL default '0',
`extension_count` smallint(5) unsigned NOT NULL default '0',
......@@ -421,6 +430,9 @@ CREATE TABLE `apt_instances` (
`public_url` tinytext,
`webtask_id` varchar(128) default NULL,
`created` datetime default NULL,
`start_at` datetime default NULL,
`started` datetime default NULL,
`stop_at` datetime default NULL,
`status` varchar(32) default NULL,
`status_timestamp` datetime default NULL,
`canceled` tinyint(2) NOT NULL default '0',
......
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("apt_deferred_instances", "start_at")) {
DBQueryFatal("alter table apt_deferred_instances add " .
" `start_at` datetime default NULL after name");
}
if (!DBSlotExists("apt_instances", "start_at")) {
DBQueryFatal("alter table apt_instances add " .
" `start_at` datetime default NULL after created");
}
if (!DBSlotExists("apt_instances", "started")) {
DBQueryFatal("alter table apt_instances add " .
" `started` datetime default NULL after start_at");
DBQueryFatal("update apt_instances set started=created");
}
if (!DBSlotExists("apt_instances", "stop_at")) {
DBQueryFatal("alter table apt_instances add " .
" `stop_at` datetime default NULL after started");
}
if (!DBSlotExists("apt_instance_history", "start_at")) {
DBQueryFatal("alter table apt_instance_history add " .
" `start_at` datetime default NULL after created");
}
if (!DBSlotExists("apt_instance_history", "started")) {
DBQueryFatal("alter table apt_instance_history add " .
" `started` datetime default NULL after start_at");
DBQueryFatal("update apt_instance_history set started=created");
}
if (!DBSlotExists("apt_instance_history", "stop_at")) {
DBQueryFatal("alter table apt_instance_history add " .
" `stop_at` datetime default NULL after started");
}
if (!DBSlotExists("apt_instance_aggregates", "started")) {
DBQueryFatal("alter table apt_instance_aggregates add " .
" `started` datetime default NULL after status");
}
if (!DBSlotExists("apt_instance_aggregate_history", "started")) {
DBQueryFatal("alter table apt_instance_aggregate_history add " .
" `started` datetime default NULL after status");
}
if (!DBSlotExists("apt_instance_failures", "start_at")) {
DBQueryFatal("alter table apt_instance_failures add " .
" `start_at` datetime default NULL after created");
}
if (!DBSlotExists("apt_instance_failures", "started")) {
DBQueryFatal("alter table apt_instance_failures add " .
" `started` datetime default NULL after start_at");
DBQueryFatal("update apt_instance_failures set started=created");
}
if (!DBSlotExists("apt_instance_failures", "stop_at")) {
DBQueryFatal("alter table apt_instance_failures add " .
" `stop_at` datetime default NULL after started");
}
return 0;
}
# Local Variables:
# mode:perl
# End:
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