Commit 18e875c9 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

merge test_start/end_planned/_act as they are the same, and some cleanup

parent 741d63c2
......@@ -247,10 +247,8 @@ CREATE TABLE `tbl_serv_tests` (
`description` text COLLATE utf8_bin,
`owner_fk` int(10) unsigned NOT NULL,
`testconfig_xml` longtext COLLATE utf8_bin NOT NULL,
`time_start_wish` datetime NOT NULL,
`time_start_act` datetime DEFAULT NULL,
`time_end_wish` datetime NOT NULL,
`time_end_act` datetime DEFAULT NULL,
`time_start` datetime NOT NULL,
`time_end` datetime NOT NULL,
`setuptime` int(11) DEFAULT NULL COMMENT 'Time needed to setup the test',
`cleanuptime` int(11) DEFAULT NULL COMMENT 'Time needed to cleanup the test',
`test_status` enum('not schedulable','planned','preparing','running','cleaning up','syncing','synced','finished','aborting','failed','todelete','deleted','retention expiring') COLLATE utf8_bin NOT NULL DEFAULT 'not schedulable',
......
......@@ -112,7 +112,7 @@ def main(argv):
else:
try:
# Check for tests to delete ---
sql = """SELECT `serv_tests_key`, `time_start_wish`
sql = """SELECT `serv_tests_key`, `time_start`
FROM `tbl_serv_tests`
WHERE (`test_status` = 'todelete')
"""
......@@ -190,7 +190,7 @@ def main(argv):
# Check for tests that are stuck ---
sql = """SELECT `serv_tests_key` FROM `tbl_serv_tests`
WHERE ((`test_status` IN ('preparing', 'aborting', 'cleaning up', 'syncing', 'synced')) OR (`test_status` = 'running' AND `dispatched` = 1))
AND (TIMESTAMPDIFF(MINUTE, `time_end_wish`, '%s') > %d)
AND (TIMESTAMPDIFF(MINUTE, `time_end`, '%s') > %d)
"""
if cur.execute(sql % (now, maxtestcleanuptime)) <= 0:
logger.debug("No stuck tests found.")
......@@ -211,7 +211,7 @@ def main(argv):
# Check for tests that are still running, but should have been stopped (NOTE: needs to be AFTER the checking for stuck tests!) ---
sql = """SELECT `serv_tests_key`, `test_status` FROM `tbl_serv_tests`
WHERE (`test_status` = 'running') AND (`time_end_wish` <= '%s') AND (`dispatched` = 0)
WHERE (`test_status` = 'running') AND (`time_end` <= '%s') AND (`dispatched` = 0)
"""
cur.execute(sql % (now))
rs = cur.fetchall()
......@@ -245,7 +245,7 @@ def main(argv):
testid = int(command.split('testid=', 1)[1].split()[0])
# check stop time of this test
sql = """SELECT `serv_tests_key` FROM `tbl_serv_tests`
WHERE `serv_tests_key`=%d AND TIMESTAMPDIFF(MINUTE, `time_end_wish`, '%s') > %d
WHERE `serv_tests_key`=%d AND TIMESTAMPDIFF(MINUTE, `time_end`, '%s') > %d
"""
if cur.execute(sql % (testid, now, maxtestcleanuptime)) > 0:
# thread is stuck -> add to list and kill
......
......@@ -313,7 +313,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
flocklab.set_test_status(cur, cn, testid, 'preparing')
# Get start/stop time ---
cur.execute("SELECT `time_start_wish`, `time_end_wish`, `owner_fk` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid)
cur.execute("SELECT `time_start`, `time_end`, `owner_fk` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid)
# Times are going to be of datetime type:
ret = cur.fetchone()
starttime = ret[0]
......@@ -788,7 +788,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
# check if we're still in time ---
if len(errors) == 0:
now = time.strftime(flocklab.config.get("database", "timeformat"), time.gmtime(time.time() - 10)) # allow 10s tolerance
cur.execute("SELECT `serv_tests_key` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d AND `time_start_wish` <= '%s'" % (testid, now))
cur.execute("SELECT `serv_tests_key` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d AND `time_start` <= '%s'" % (testid, now))
if cur.fetchone() is not None:
msg = "Setup for test ID %d took too much time." % (testid)
errors.append(msg)
......@@ -798,12 +798,10 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
if len(errors) == 0:
logger.debug("Setting test status in DB to running...")
flocklab.set_test_status(cur, cn, testid, 'running')
cur.execute("UPDATE `tbl_serv_tests` SET `time_start_act` = `time_start_wish` WHERE `serv_tests_key` = %d" %testid)
cn.commit()
else:
logger.debug("Setting test status in DB to aborting...")
flocklab.set_test_status(cur, cn, testid, 'aborting')
cur.execute("UPDATE `tbl_serv_tests` SET `time_start_act` = `time_start_wish`, `time_end_act` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" %testid)
cur.execute("UPDATE `tbl_serv_tests` SET `time_end` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" % testid)
cn.commit()
logger.debug("At end of start_test(). Returning...")
......@@ -927,10 +925,6 @@ def stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort=False):
#logger.error("Error from test stop thread: %s" %(str(err[0])))
warnings.append(err[0])
# Set stop time in DB ---
cur.execute("UPDATE `tbl_serv_tests` SET `time_end_act` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" %testid)
cn.commit()
except Exception:
msg = "Unexpected error: %s: %s\n%s" % (str(sys.exc_info()[0]), str(sys.exc_info()[1]), traceback.format_exc())
errors.append(msg)
......@@ -1051,7 +1045,7 @@ def evaluate_linkmeasurement(testid, cur):
logger = flocklab.get_logger()
errors = []
# if link measurement, evaluate data
cur.execute("SELECT `username`, `time_start_act` FROM `tbl_serv_tests` LEFT JOIN `tbl_serv_users` ON (`serv_users_key`=`owner_fk`) WHERE (`serv_tests_key` = %s)" % testid)
cur.execute("SELECT `username`, `time_start` FROM `tbl_serv_tests` LEFT JOIN `tbl_serv_users` ON (`serv_users_key`=`owner_fk`) WHERE (`serv_tests_key` = %s)" % testid)
ret = cur.fetchone()
if ret and ret[0] == flocklab.config.get('linktests', 'user'):
teststarttime = ret[1]
......@@ -1415,7 +1409,7 @@ def main(argv):
flocklab.send_mail_to_admin(msg)
# Get the stop time from the database
cur.execute("SELECT `time_end_wish` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
cur.execute("SELECT `time_end` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
ret = cur.fetchone()
stoptimestamp = datetime.datetime.timestamp(ret[0]) + 1 # postpone by 1s to give services on observers time to shut down
if not stoptimestamp or stoptimestamp < time.time():
......@@ -1488,7 +1482,7 @@ def main(argv):
logger.debug("Fetcher has set test status to '%s'." % status)
# Check the actual runtime: if < 0, test failed
cur.execute("SELECT TIME_TO_SEC(TIMEDIFF(`time_end_act`, `time_start_act`)) FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
cur.execute("SELECT TIME_TO_SEC(TIMEDIFF(`time_end`, `time_start`)) FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
test_runtime = cur.fetchone()[0]
if not test_runtime or int(test_runtime) < 0:
logger.info("Negative runtime detected, marking test as 'failed'.")
......
......@@ -1068,7 +1068,7 @@ def main(argv):
serialdict = {0: 'r', 1: 'w'}
#find out the start and stoptime of the test
cur.execute("SELECT `time_start_wish`, `time_end_wish` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid)
cur.execute("SELECT `time_start`, `time_end` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
# Times are going to be of datetime type:
ret = cur.fetchone()
teststarttime = ret[0]
......@@ -1078,7 +1078,7 @@ def main(argv):
# Find out which services are used to allocate working threads later on ---
# Get the XML config from the database and check which services are used in the test.
servicesUsed_dict = {'gpiotracing': 'gpioTracingConf', 'powerprofiling': 'powerProfilingConf', 'serial': 'serialConf', 'datatrace': 'dataTraceConf'}
cur.execute("SELECT `testconfig_xml` FROM `tbl_serv_tests` WHERE (`serv_tests_key` = %s)" %testid)
cur.execute("SELECT `testconfig_xml` FROM `tbl_serv_tests` WHERE (`serv_tests_key` = %s)" % testid)
ret = cur.fetchone()
if not ret:
msg = "No XML found in database for testid %d." %testid
......
......@@ -113,7 +113,8 @@ def main(argv):
logger.debug("Expiration lead time is %s days" % expiration_leadtime)
try:
# Get all users that have ran tests:
sql = """ SELECT DISTINCT `owner_fk`
sql = """
SELECT DISTINCT `owner_fk`
FROM `tbl_serv_tests`
WHERE (`test_status` IN ('not schedulable','finished','failed', 'retention expiring'))
"""
......@@ -123,7 +124,8 @@ def main(argv):
rs = cur.fetchall()
ownerids = [str(i[0]) for i in rs]
for ownerid in ownerids:
sql = """ SELECT `retention_time`, `email`, `username`, `is_active`
sql = """
SELECT `retention_time`, `email`, `username`, `is_active`
FROM `tbl_serv_users`
WHERE (`serv_users_key` = %s)
""" % (ownerid)
......@@ -136,10 +138,11 @@ def main(argv):
logger.debug("Checking tests of user %s (users retention time is %d days)." % (ownerusername, retention_time_user))
# Check for each user (taking into account her individual retention time [-1 means saving data forever]) if there are tests to be cleaned soon and inform the user about these tests.
if retention_time_user != -1:
sql = """ SELECT `serv_tests_key`, `title`, DATE(`time_end_act`), `test_status`
sql = """
SELECT `serv_tests_key`, `title`, DATE(`time_end`), `test_status`
FROM `tbl_serv_tests`
WHERE ((`owner_fk` = %s) AND (`time_end_act` < ADDDATE(NOW(), -(%s + %s))) AND (`test_status` IN ('not schedulable','finished','failed')))
ORDER BY `time_end_act` DESC
WHERE ((`owner_fk` = %s) AND (`time_end` < ADDDATE(NOW(), -(%s + %s))) AND (`test_status` IN ('not schedulable','finished','failed')))
ORDER BY `time_end` DESC
""" % (ownerid, retention_time_user, expiration_leadtime)
if(cur.execute(sql) > 0):
rs = cur.fetchall()
......@@ -170,7 +173,8 @@ Yours faithfully,\nthe FlockLab server"""
continue
else:
# Mark the tests in the database:
sql = """ UPDATE `tbl_serv_tests`
sql = """
UPDATE `tbl_serv_tests`
SET `test_status` = 'retention expiring', `retention_expiration_warned` = NOW()
WHERE `serv_tests_key` IN (%s)
"""
......@@ -181,10 +185,11 @@ Yours faithfully,\nthe FlockLab server"""
logger.debug("Found no tests whose retention time expires soon.")
# Check for each user if there are tests which are to be marked for deletion as their retention time expired:
sql = """ SELECT `serv_tests_key`, `title`, DATE(`time_end_act`)
sql = """
SELECT `serv_tests_key`, `title`, DATE(`time_end`)
FROM `tbl_serv_tests`
WHERE ((`owner_fk` = %s) AND (`time_end_act` < ADDDATE(NOW(), -(%s))) AND (`test_status` = 'retention expiring') AND (`retention_expiration_warned` < ADDDATE(NOW(), -(%s+1))))
ORDER BY `time_end_act` DESC
WHERE ((`owner_fk` = %s) AND (`time_end` < ADDDATE(NOW(), -(%s))) AND (`test_status` = 'retention expiring') AND (`retention_expiration_warned` < ADDDATE(NOW(), -(%s+1))))
ORDER BY `time_end` DESC
"""
if(cur.execute(sql % (ownerid, retention_time_user, expiration_leadtime)) > 0):
rs = cur.fetchall()
......@@ -214,7 +219,8 @@ Yours faithfully,\nthe FlockLab server"""
continue
else:
# Mark the tests in the database:
sql = """ UPDATE `tbl_serv_tests`
sql = """
UPDATE `tbl_serv_tests`
SET `test_status` = 'todelete'
WHERE `serv_tests_key` IN (%s)
"""
......
......@@ -183,10 +183,10 @@ def main(argv):
earlieststart = (datetime.datetime.now() + datetime.timedelta(seconds=setuptime) - datetime.timedelta(seconds=schedinterval)).strftime(flocklab.config.get("database", "timeformat"))
lateststart = (datetime.datetime.now() + datetime.timedelta(seconds=setuptime) + datetime.timedelta(seconds=schedinterval)).strftime(flocklab.config.get("database", "timeformat"))
# Check if a test is going to start soon:
sql = """SELECT `serv_tests_key`,`time_start_wish`
sql = """SELECT `serv_tests_key`,`time_start`
FROM `tbl_serv_tests`
WHERE (`time_start_wish` >= '%s')
AND (`time_start_wish` <= '%s')
WHERE (`time_start` >= '%s')
AND (`time_start` <= '%s')
AND (`test_status` = 'planned')
AND (`dispatched` = 0)
""" % (earlieststart, lateststart)
......@@ -208,12 +208,12 @@ def main(argv):
# Check for test which have been missed ---
sql1 = """SELECT `serv_tests_key`
FROM `tbl_serv_tests`
WHERE (`time_start_wish` < '%s')
WHERE (`time_start` < '%s')
AND (`test_status` = 'planned')
""" % earlieststart
sql2 = """UPDATE `tbl_serv_tests`
SET `test_status` = 'failed'
WHERE (`time_start_wish` < '%s')
WHERE (`time_start` < '%s')
AND (`test_status` = 'planned')
""" % earlieststart
nmissed = cur.execute(sql1)
......
......@@ -152,7 +152,7 @@ def update_configuration_from_db():
flocklab.error_logandexit(msg, errno.EAGAIN)
try:
# Get the XML config from the database:
cur.execute("SELECT `testconfig_xml`, `serv_tests_key` FROM `tbl_serv_tests` WHERE (`test_status` IN ('preparing', 'running') AND `time_end_wish` >= NOW())")
cur.execute("SELECT `testconfig_xml`, `serv_tests_key` FROM `tbl_serv_tests` WHERE (`test_status` IN ('preparing', 'running') AND `time_end` >= NOW())")
ret = cur.fetchall()
for testconfig in ret:
logger.debug("Create proxy config for test %d" % testconfig[1])
......
......@@ -625,7 +625,7 @@ def get_obs_from_id(cursor=None, obsid=0):
return FAILED
try:
sql = " SELECT `ethernet_address`, `status` \
sql = "SELECT `ethernet_address`, `status` \
FROM `tbl_serv_observer` \
WHERE `observer_id`=%d;"
cursor.execute(sql %obsid)
......@@ -1014,7 +1014,7 @@ def is_test_running(cursor=None):
cursor.execute("""
SELECT COUNT(serv_tests_key) FROM tbl_serv_tests
WHERE test_status IN('preparing', 'running', 'aborting', 'cleaning up')
AND TIMESTAMPDIFF(MINUTE, time_end_wish, '%s') <= %d
AND TIMESTAMPDIFF(MINUTE, time_end, '%s') <= %d
""" % (now, maxcleanuptime))
rs = cursor.fetchone()
if rs[0] != 0:
......
......@@ -110,7 +110,7 @@
exit();
}
$db = db_connect();
$sql = "SELECT title, description, test_status as status, UNIX_TIMESTAMP(time_start_wish) AS start_planned, UNIX_TIMESTAMP(time_start_act) AS start_act, UNIX_TIMESTAMP(time_end_wish) AS end_planned, UNIX_TIMESTAMP(time_end_act) AS end_act
$sql = "SELECT title, description, test_status as status, UNIX_TIMESTAMP(time_start) AS start, UNIX_TIMESTAMP(time_end) AS end
FROM `flocklab`.`tbl_serv_tests`
WHERE serv_tests_key=".intval($_POST['id']);
if ($userrole != 'admin' && $userrole != 'internal') {
......@@ -123,7 +123,7 @@
else {
$row = mysqli_fetch_assoc($res);
if ($row) {
echo json_encode(array('status' => 'ok', 'output' => array('title' => $row['title'], 'description' => $row['description'], 'status' => $row['status'], 'start_planned' => $row['start_planned'], 'start' => $row['start_act'], 'end_planned' => $row['end_planned'], 'end' => $row['end_act'])));
echo json_encode(array('status' => 'ok', 'output' => array('title' => $row['title'], 'description' => $row['description'], 'status' => $row['status'], 'start' => $row['start'], 'end' => $row['end'], 'start_planned' => $row['start'], 'end_planned' => $row['end']))); // keep start_planned / end_planned for backwards compatibility (flocklab tools)
} else {
echo json_encode(array('status' => 'error', 'output' => 'test ID '.intval($_POST['id']).' not found'));
}
......
......@@ -46,15 +46,15 @@
$guard_cleanup_sec = $CONFIG['tests']['cleanuptime'];
$db = db_connect();
// planned tests
$sql = "SELECT `a`.serv_tests_key, `a`.title, `a`.description, `a`.time_start_wish, `a`.time_end_wish, `a`.owner_fk,
`b`.username, `b`.firstname, `b`.lastname, `a`.time_start_act, `a`.time_end_act, `a`.test_status,
DATE_ADD(`a`.time_start_wish, INTERVAL -".$guard_setup_sec." SECOND) as time_start_offset,
DATE_ADD(`a`.time_end_wish, INTERVAL ".$guard_cleanup_sec." SECOND) as time_end_offset
$sql = "SELECT `a`.serv_tests_key, `a`.title, `a`.description, `a`.time_start, `a`.time_end, `a`.owner_fk,
`b`.username, `b`.firstname, `b`.lastname, `a`.test_status,
DATE_ADD(`a`.time_start, INTERVAL -".$guard_setup_sec." SECOND) as time_start_offset,
DATE_ADD(`a`.time_end, INTERVAL ".$guard_cleanup_sec." SECOND) as time_end_offset
FROM `tbl_serv_tests` AS `a`
LEFT JOIN `tbl_serv_users` AS `b` ON `a`.owner_fk = `b`.serv_users_key
WHERE (`a`.test_status NOT IN ('not schedulable') OR (`a`.test_status_preserved IS NOT NULL AND `a`.test_status_preserved IN ('finished','failed')))
AND ( (`a`.time_start_wish BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') OR (`a`.time_end_wish BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') )
ORDER BY `a`.time_start_wish";
AND ( (`a`.time_start BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') OR (`a`.time_end BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') )
ORDER BY `a`.time_start";
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get calendar data from database because: ' . mysqli_error($db));
// Build the array of events:
......@@ -66,9 +66,9 @@
$events[] = array(
'id' => $row['serv_tests_key'],
'title' => 'Test ' . $row['serv_tests_key'] . ': ' . $row['title'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_act'])).' - '.date("H:i", strtotime($row['time_end_act'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start_act'],
'end' => $row['time_end_act'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start'],
'end' => $row['time_end'],
'allDay' => false,
'color' => '#eca427',
);
......@@ -80,7 +80,7 @@
'title' => 'Test setup',
'description' => $mini?'':'Time needed by FlockLab to setup your test.',
'start' => $row['time_start_offset'],
'end' => $row['time_start_wish'],
'end' => $row['time_start'],
'allDay' => false,
'color' => 'orange',
);
......@@ -88,9 +88,9 @@
$events[] = array(
'id' => $row['serv_tests_key'],
'title' => 'Test ' . $row['serv_tests_key'] . ': ' . $row['title'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_wish'])).' - '.date("H:i", strtotime($row['time_end_wish'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start_wish'],
'end' => $row['time_end_wish'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start'],
'end' => $row['time_end'],
'allDay' => false,
'color' => '#eca427',
);
......@@ -99,7 +99,7 @@
'id' => 'service',
'title' => 'Test cleanup',
'description' => $mini?'':'Time needed by FlockLab to cleanup your test.',
'start' => $row['time_end_wish'],
'start' => $row['time_end'],
'end' => $row['time_end_offset'],
'allDay' => false,
'color' => 'orange',
......@@ -110,15 +110,15 @@
$event = array(
'id' => $row['serv_tests_key'],
'title' => $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')',
'description' => $mini?'':'ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_wish'])).' - '.date("H:i", strtotime($row['time_end_wish'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'] . '<br/> User: ' . $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')' . '<br/>Status: ' . $row['test_status'],
'description' => $mini?'':'ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'] . '<br/> User: ' . $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')' . '<br/>Status: ' . $row['test_status'],
'allDay' => false,
);
if (isset($row['time_start_act']))
$event['start'] = $row['time_start_act'];
if (isset($row['time_start']))
$event['start'] = $row['time_start'];
else
$event['start'] = $row['time_start_offset'];
if (isset($row['time_end_act']))
$event['end'] = $row['time_end_act'];
if (isset($row['time_end']))
$event['end'] = $row['time_end'];
else
$event['end'] = $row['time_end_offset'];
array_push($events, $event);
......@@ -131,12 +131,12 @@
'description' => $mini?'':'Another user is running a test.',
'allDay' => false,
);
if (isset($row['time_start_act']))
$event['start'] = $row['time_start_act'];
if (isset($row['time_start']))
$event['start'] = $row['time_start'];
else
$event['start'] = $row['time_start_offset'];
if (isset($row['time_end_act']))
$event['end'] = $row['time_end_act'];
if (isset($row['time_end']))
$event['end'] = $row['time_end'];
else
$event['end'] = $row['time_end_offset'];
array_push($events, $event);
......
......@@ -53,12 +53,12 @@
// Connect to database and get the corresponding events:
$db = db_connect();
// Only get data for the last 30 days:
$sql = "SELECT serv_tests_key, title, left(description, 100) as description, ADDTIME(`a`.time_start_wish, '-00:05:00') AS time_start_w_offset, ADDTIME(`a`.time_end_wish, '00:05:00') AS time_end_w_offset,
$sql = "SELECT serv_tests_key, title, left(description, 100) as description, ADDTIME(`a`.time_start, '-00:05:00') AS time_start_w_offset, ADDTIME(`a`.time_end, '00:05:00') AS time_end_w_offset,
`b`.username
FROM `tbl_serv_tests` AS `a`
LEFT JOIN `tbl_serv_users` AS `b` ON `a`.owner_fk = `b`.serv_users_key
WHERE `a`.test_status <> 'not schedulable' AND `a`.test_status <> 'deleted' AND `a`.test_status <> 'todelete' AND (`a`.time_end_wish >= ADDTIME(NOW(), '-30 0:0:0.0'))
ORDER by `a`.time_start_wish ASC LIMIT 1000";
WHERE `a`.test_status <> 'not schedulable' AND `a`.test_status <> 'deleted' AND `a`.test_status <> 'todelete' AND (`a`.time_end >= ADDTIME(NOW(), '-30 0:0:0.0'))
ORDER by `a`.time_start ASC LIMIT 1000";
$rs = mysqli_query($db, $sql) or die("Unknown error occurred.");
mysqli_close($db);
......
......@@ -541,7 +541,7 @@ function check_quota($testconfig, $exclude_test = NULL, &$quota = NULL) {
// get scheduled tests / time for this user
$db = db_connect();
$sql = 'SELECT SUM(TIME_TO_SEC(TIMEDIFF(`time_end_wish`,`time_start_wish`)))/60 as runtime, COUNT(*) as test_num
$sql = 'SELECT SUM(TIME_TO_SEC(TIMEDIFF(`time_end`,`time_start`)))/60 as runtime, COUNT(*) as test_num
FROM `tbl_serv_tests`
WHERE `owner_fk` = ' . $_SESSION['serv_users_key']. ' AND (`test_status` IN("planned", "preparing", "running", "cleaning up", "aborting"))' .(is_null($exclude_test) ? '' : ' AND `serv_tests_key`!='.$exclude_test);
$res = mysqli_query($db, $sql) or flocklab_die('Cannot check user quota because: ' . mysqli_error($db));
......@@ -566,9 +566,9 @@ function check_quota($testconfig, $exclude_test = NULL, &$quota = NULL) {
if ($this_start >= $CONFIG['tests']['daytime_start'] && $this_start <= $CONFIG['tests']['daytime_end'] && $this_dayofweek < 6) {
// test starts during daytime (Mo-Fr)
$runtime_daytime = $this_runtime;
$sql = 'SELECT SUM(TIME_TO_SEC(TIMEDIFF(`time_end_wish`,`time_start_wish`)))/60 as runtime, COUNT(*) as test_num
$sql = 'SELECT SUM(TIME_TO_SEC(TIMEDIFF(`time_end`,`time_start`)))/60 as runtime, COUNT(*) as test_num
FROM `tbl_serv_tests`
WHERE `owner_fk` = ' . $_SESSION['serv_users_key']. ' AND (`test_status` IN("planned", "preparing", "running", "cleaning up", "aborting"))' .(is_null($exclude_test)?'':' AND `serv_tests_key`!='.$exclude_test.' AND HOUR(`time_start_wish`) > '.$CONFIG['tests']['daytime_start'].' AND HOUR(`time_start_wish`) < '.$CONFIG['tests']['daytime_end']);
WHERE `owner_fk` = ' . $_SESSION['serv_users_key']. ' AND (`test_status` IN("planned", "preparing", "running", "cleaning up", "aborting"))' .(is_null($exclude_test)?'':' AND `serv_tests_key`!='.$exclude_test.' AND HOUR(`time_start`) > '.$CONFIG['tests']['daytime_start'].' AND HOUR(`time_start`) < '.$CONFIG['tests']['daytime_end']);
$res = mysqli_query($db, $sql) or flocklab_die('Cannot check user quota because: ' . mysqli_error($db));
$row = mysqli_fetch_assoc($res);
if ($row['test_num'] != 0)
......@@ -581,7 +581,7 @@ function check_quota($testconfig, $exclude_test = NULL, &$quota = NULL) {
FROM `tbl_serv_users`
WHERE `serv_users_key` = ' . $_SESSION['serv_users_key'];
$res = mysqli_query($db, $sql) or flocklab_die('Cannot check user quota because: ' . mysqli_error($db));
if (mysqli_num_rows($res)==1) {
if (mysqli_num_rows($res) == 1) {
$row = mysqli_fetch_assoc($res);
if ($quota != NULL) {
$quota['available']=array('runtime'=>$row['quota_runtime'], 'num'=>$row['quota_tests']);
......@@ -786,8 +786,7 @@ function resource_slots($duration, $targetnodes) {
$resources = Array();
$db = db_connect();
foreach($targetnodes as $tn) {
$sql = "
SELECT ifnull(1*(`b`.`tg_adapt_types_fk`=".$tn['platform']."),0)
$sql = "SELECT ifnull(1*(`b`.`tg_adapt_types_fk`=".$tn['platform']."),0)
+ ifnull(2*(`c`.`tg_adapt_types_fk`=".$tn['platform']."),0)
+ ifnull(3*(`d`.`tg_adapt_types_fk`=".$tn['platform']."),0)
+ ifnull(4*(`e`.`tg_adapt_types_fk`=".$tn['platform']."),0) as slot
......@@ -884,8 +883,7 @@ function resource_cleanup($targetnodes) {
$resources = Array();
$db = db_connect();
foreach($targetnodes as $tn) {
$sql = "
SELECT ifnull(1*(`b`.`tg_adapt_types_fk`=".$tn['platform']."),0)
$sql = "SELECT ifnull(1*(`b`.`tg_adapt_types_fk`=".$tn['platform']."),0)
+ ifnull(2*(`c`.`tg_adapt_types_fk`=".$tn['platform']."),0)
+ ifnull(3*(`d`.`tg_adapt_types_fk`=".$tn['platform']."),0)
+ ifnull(4*(`e`.`tg_adapt_types_fk`=".$tn['platform']."),0) as slot
......@@ -906,8 +904,6 @@ function resource_cleanup($targetnodes) {
return $resources;
}
##############################################################################
#
# schedule_test
......@@ -926,9 +922,9 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
$guard_cleanup_sec = $CONFIG['tests']['cleanuptime'];
$allow_parallel_tests = $CONFIG['tests']['allowparalleltests'];
$isAsap = !isset($testconfig->generalConf->schedule->start);
$duration = $testconfig->generalConf->schedule->duration;
$now = new DateTime ();
$now->setTimeZone(new DateTimeZone("UTC"));
$duration = $testconfig->generalConf->schedule->duration;
// start is time start wish - setup time
// end is time end wish + cleanup time
if (!$isAsap) {
......@@ -940,9 +936,8 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
}
else {
$start = new DateTime(); // now
$end = clone $start;
$start->setTimeZone(new DateTimeZone("UTC"));
$end->setTimeZone(new DateTimeZone("UTC"));
$end = clone $start;
$end->modify('+'.$testconfig->generalConf->schedule->duration.' seconds');
$end->modify('+'.($guard_setup_sec + $guard_cleanup_sec).' seconds');
}
......@@ -953,9 +948,14 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
array_push($resourcesdict[$r['obskey']][$r['restype']], $r);
}
$sql = "SELECT UNIX_TIMESTAMP(`time_start`) as `utime_start`, UNIX_TIMESTAMP(`time_end`) as `utime_end`, `observer_fk`, `resource_type` FROM `tbl_serv_resource_allocation` a left join tbl_serv_tests b on (b.serv_tests_key = a.test_fk) WHERE (`time_end` >= '".$start->format(DATE_ISO8601)."' and test_status in ('planned','preparing','running','cleaning up','syncing','synced','aborting')".(isset($exclude_test)?" and `test_fk`!=".$exclude_test:"").")";
$sql = "SELECT UNIX_TIMESTAMP(`time_start`) as `utime_start`, UNIX_TIMESTAMP(`time_end`) as `utime_end`, `observer_fk`, `resource_type`
FROM `tbl_serv_resource_allocation` a left join tbl_serv_tests b on (b.serv_tests_key = a.test_fk)
WHERE (`time_end` >= '".$start->format(DATE_ISO8601)."' AND test_status in ('planned','preparing','running','cleaning up','syncing','synced','aborting')".(isset($exclude_test)?" AND `test_fk`!=".$exclude_test:"").")";
$res_usedresources = mysqli_query($db, $sql);
$sql = "SELECT UNIX_TIMESTAMP(`time_start`) as `utime_start`, UNIX_TIMESTAMP(`time_end`) as `utime_end`, max(ifnull(user_fk,-1) = ".$_SESSION['serv_users_key'].") as `reservation_match` FROM `tbl_serv_reservations` LEFT JOIN `tbl_serv_user_groups` ON `group_fk`=`group_id_fk` WHERE `time_end` >= '".$start->format(DATE_ISO8601)."' GROUP BY `serv_reservation_key` HAVING `reservation_match` = 0";
$sql = "SELECT UNIX_TIMESTAMP(`time_start`) as `utime_start`, UNIX_TIMESTAMP(`time_end`) as `utime_end`, max(ifnull(user_fk,-1) = ".$_SESSION['serv_users_key'].") as `reservation_match`
FROM `tbl_serv_reservations` LEFT JOIN `tbl_serv_user_groups` ON `group_fk`=`group_id_fk`
WHERE `time_end` >= '".$start->format(DATE_ISO8601)."'
GROUP BY `serv_reservation_key` HAVING `reservation_match` = 0";
$res_reservations = mysqli_query($db, $sql);
# Now check for all resource usage intervals if they overlap in time with an already scheduled test or reservations
......@@ -1003,7 +1003,7 @@ function schedule_test($testconfig, $resources, $exclude_test = NULL) {
# for every ret, check for collisions
if (isset($resourcesdict[$row['observer_fk']]) && isset($resourcesdict[$row['observer_fk']][$row['resource_type']])) {
foreach($resourcesdict[$row['observer_fk']][$row['resource_type']] as $r) {
// echo "<!--";print_r($row);echo "-->";
//echo "<!--";print_r($row);echo "-->";
if($row['utime_start'] <= $r['time_end'] + $testShift and $row['utime_end'] >= $r['time_start'] + $testShift) {
if (!$isAsap)
return Array('feasible'=>False, 'start_time'=>$start, 'end_time'=>$end);
......@@ -1220,7 +1220,7 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
$duration = $testconfig->generalConf->schedule->duration;
# 1a. slots
$resources = Array();
if ($abort===True) {
if ($abort === True) {
$resources = array_merge($resources, resource_cleanup($targetnodes));
if (isset($testconfig->generalConf->schedule->start)) {
unset($testconfig->generalConf->schedule);
......@@ -1261,7 +1261,8 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
mysqli_query($db, $sql) or flocklab_die('Cannot abort test: ' . mysqli_error($db));
// update test entry
$end = $r['end_time'];
$sql = 'UPDATE `tbl_serv_tests` SET `time_end_wish`="'.mysqli_real_escape_string($db, $end->format(DATE_ISO8601)).'", `test_status`="aborting" WHERE `serv_tests_key`='.$existing_test_id;
$sql = 'UPDATE `tbl_serv_tests` SET `time_end`="' . mysqli_real_escape_string($db, $end->format(DATE_ISO8601)) . '", `test_status`="aborting"
WHERE `serv_tests_key`='.$existing_test_id;
mysqli_query($db, $sql) or flocklab_die('Cannot remove resource allocation from database: ' . mysqli_error($db));
$testId = $existing_test_id;
mysqli_close($db);
......@@ -1325,8 +1326,8 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
`title`="'.mysqli_real_escape_string($db, trim($testconfig->generalConf->name)).'",
`description`="'.mysqli_real_escape_string($db, trim($testconfig->generalConf->description)).'",
`testconfig_xml`="'.mysqli_real_escape_string($db, trim($xml_config)).'",
`time_start_wish`="'.mysqli_real_escape_string($db, $start->format(DATE_ISO8601)) .'",
`time_end_wish`="'.mysqli_real_escape_string($db, $end->format(DATE_ISO8601)).'",
`time_start`="'.mysqli_real_escape_string($db, $start->format(DATE_ISO8601)) .'",
`time_end`="'.mysqli_real_escape_string($db, $end->format(DATE_ISO8601)).'",
`test_status`="planned"
WHERE `serv_tests_key`='.$existing_test_id;
mysqli_query($db, $sql) or flocklab_die('Cannot store test configuration in database table tbl_serv_tests because: ' . mysqli_error($db));
......@@ -1336,7 +1337,7 @@ function update_add_test($xml_config, &$errors, $existing_test_id = NULL, $abort
else {
// add test entry
$db = db_connect();
$sql = "INSERT INTO `tbl_serv_tests` (`title`, `description`, `owner_fk`, `testconfig_xml`, `time_start_wish`, `time_end_wish`, `test_status`)
$sql = "INSERT INTO `tbl_serv_tests` (`title`, `description`, `owner_fk`, `testconfig_xml`, `time_start`, `time_end`, `test_status`)
VALUES (
'" . mysqli_real_escape_string($db, trim($testconfig->generalConf->name)) . "',
'" . mysqli_real_escape_string($db, trim($testconfig->generalConf->description)) . "',
......
......@@ -220,7 +220,7 @@
echo '<h1>Manage Tests for '.$_SESSION['firstname'] . ' ' . $_SESSION['lastname']. '</h1>';
/* Get all test of the current user from the database and display them in the table. */
$db = db_connect();
$sql = "SELECT serv_tests_key, title, description, time_start_act, time_start_wish, time_end_act, time_end_wish, test_status, ExtractValue(testconfig_xml, 'testConf/targetConf/dbImageId') image_ids
$sql = "SELECT serv_tests_key, title, description, time_start, time_end, test_status, ExtractValue(testconfig_xml, 'testConf/targetConf/dbImageId') image_ids
FROM tbl_serv_tests
WHERE owner_fk = " . $_SESSION['serv_users_key'] . " AND test_status <> 'deleted' AND test_status <> 'todelete'
ORDER BY serv_tests_key DESC";
......@@ -337,27 +337,27 @@ echo '<h1>Manage Tests for '.$_SESSION['firstname'] . ' ' . $_SESSION['lastname'
else
echo "<td class='qtip_show' title='" . htmlentities($row['description']) . "' id='desc".$row['serv_tests_key']."' ondblclick='editDesc(".$row['serv_tests_key'].")'>" . htmlentities(substr($row['description'],0,$max_len)) . "...</td>";
// Image ID
echo "<td class='qtip_show' title='image IDs used in this test'>" . $row['image_ids'] . "</td>";
echo "<td class='qtip_show' title='Image IDs used in this test'>" . $row['image_ids'] . "</td>";
// Status
echo "<td>";
echo "<span style='display:none'>".$row['test_status']."</span>"; // needed to make cell sortable by JQuery
echo "<img src='".state_icon($row['test_status'])."' height='16px' alt='".state_short_description($row['test_status'])."' title='".state_long_description($row['test_status'])."' class='qtip_show' >";
echo "</td>";
// Start time: dependent of state of test
if ( $running || $cleaningup || $finished || $failed || $aborting || $syncing || $synced || $retentionexp) {
echo "<td title='Actual start time' class='qtip_show'>" . date_to_tzdate($row['time_start_act']). "</td>";
if ($preparing || $running || $cleaningup || $finished || $failed || $aborting || $syncing || $synced || $retentionexp) {
echo "<td title='Start time' class='qtip_show'>" . date_to_tzdate($row['time_start']). "</td>";
}
elseif ($preparing || $planned) {
echo "<td title='Planned start time' class='qtip_show'><i class='starttime'>" . date_to_tzdate($row['time_start_wish']). "</i></td>";
elseif ($planned) {
echo "<td title='Planned start time' class='qtip_show'><i class='starttime'>" . date_to_tzdate($row['time_start']). "</i></td>";
}
else
echo "<td title='Test is not schedulable' class='qtip_show'>n/a</td>";
// End time: dependent of state of test
if ($planned || $preparing || $running) {
echo "<td title='Planned end time' class='qtip_show'><i class='endtime'>" . date_to_tzdate($row['time_end_wish']). "</i></td>";
if ($planned) {
echo "<td title='Planned end time' class='qtip_show'><i class='endtime'>" . date_to_tzdate($row['time_end']). "</i></td>";
}