summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPreston Cody <codeman@gentoo.org>2007-07-21 02:09:06 +0000
committerPreston Cody <codeman@gentoo.org>2007-07-21 02:09:06 +0000
commitd910131787280767ac8c5c3a14b4ec58bdd719ec (patch)
treed16badf950066310b280b78b946d93e610d6f65d
parentcommitting code from Rodrigo Lazo (rlazo) for Google SoC (diff)
downloadscire-d910131787280767ac8c5c3a14b4ec58bdd719ec.tar.gz
scire-d910131787280767ac8c5c3a14b4ec58bdd719ec.tar.bz2
scire-d910131787280767ac8c5c3a14b4ec58bdd719ec.zip
adding changes from Rodrigo Lazo (rlazo) for Google SoC:
modified add_job.php to make use of the new scheduling logic, plus other minor changes svn path=/; revision=233
-rwxr-xr-xclient/scirec.py3
-rw-r--r--docs/scire.sql4
-rw-r--r--docs/scire2.sql4
-rwxr-xr-xscire/.lib/DB_functions.php12
-rwxr-xr-xscire/.smarty/templates/add_job.tpl5
-rw-r--r--scire/add_job.php25
6 files changed, 40 insertions, 13 deletions
diff --git a/client/scirec.py b/client/scirec.py
index 032ec54..437f3f4 100755
--- a/client/scirec.py
+++ b/client/scirec.py
@@ -54,7 +54,7 @@ def run_jobs(client,jobs):
for jobid in jobs:
job=client.get_job(jobid,True)
- if sim or debug:
+ if sim or debug or verbose:
print "Job %s:" % job['jobid']
print job
#for key in job.keys():
@@ -218,7 +218,6 @@ def generate_cert_and_key(keytype="RSA", keylength=1024):
print "done"
def scirec_main(client,known_jobs):
-
summary = client.gen_summary(known_jobs)
print 'Summary: ' + str(summary)
diff --git a/docs/scire.sql b/docs/scire.sql
index 49021eb..8b4e14f 100644
--- a/docs/scire.sql
+++ b/docs/scire.sql
@@ -121,7 +121,7 @@ CREATE TABLE job_conditions (
# might also include data (partition full?)
PRIMARY KEY (jobid),
- FOREIGN KEY (jobid) REFERENCES jobs.jobid,
+ FOREIGN KEY (jobid) REFERENCES jobs.jobid
) ENGINE = MyISAM;
DROP TABLE IF EXISTS scripts;
@@ -231,7 +231,7 @@ CREATE TABLE dyn_tags (
tag VARCHAR(30) NOT NULL,
tag_value VARCHAR(255),
PRIMARY KEY (jobid, tag),
- FOREIGN KEY (jobid) REFERENCES jobs.jobid,
+ FOREIGN KEY (jobid) REFERENCES jobs.jobid
) ENGINE = MyISAM;
drop table if exists modules;
diff --git a/docs/scire2.sql b/docs/scire2.sql
index 3085ac0..c2ae47a 100644
--- a/docs/scire2.sql
+++ b/docs/scire2.sql
@@ -25,10 +25,12 @@ INSERT INTO os (osid, osname, update_script, install_script, uninstall_script, r
INSERT INTO GLI_profiles (profileid, profile_name, location, description) values (1, 'printerserver', '/scire/gli_profiles/printerserver.xml', 'A typical printer server install profile. has like cups and shit.');
INSERT INTO GLI_profiles (profileid, profile_name, location, description) values (2, 'mta', '/scire/gli_profiles/mta.xml', 'A typical MTA install profile. has like very little except mailers.');
-INSERT INTO `clients` VALUES (3,'ASSET02',NULL,'testclient','00:01:02:03:04:0A','1.2.3.4',1,1,2,2,'0000-00-00 00:00:00',''),(5,'ASSET05',NULL,'testclient2','00:01:02:03:04:05','192.168.1.11',1,1,2,1,'0000-00-00 00:00:00','sampledigest');
+INSERT INTO `clients` VALUES (3,'ASSET02','sampledigest',NULL,'testclient','00:01:02:03:04:0A','1.2.3.4',1,1,2,2,'0000-00-00 00:00:00'),(5,'ASSET05','testdigest',NULL,'testclient2','00:01:02:03:04:05','192.168.1.11',1,1,2,1,'0000-00-00 00:00:00');
INSERT INTO jobs (jobid, priority, created, creator, permission, script, description, pending, failed) values (1, 1, NOW(), 2, 1, 100, 'Upgrading a package on mtalead', 1,0);
INSERT INTO jobs_clients (jobid, clientid) values (1, 3);
+INSERT INTO job_conditions (jobid, job_dependency, run_schedule, validity_period) values (1, 0, '*/15 * * * *', 4);
+
INSERT INTO settings (userid, setting_name, setting_value) values (1, 'start_page', 'users.php');
INSERT INTO settings (userid, setting_name, setting_value) values (1, 'theme', 'light_blue');
diff --git a/scire/.lib/DB_functions.php b/scire/.lib/DB_functions.php
index 3d806bb..b8eca73 100755
--- a/scire/.lib/DB_functions.php
+++ b/scire/.lib/DB_functions.php
@@ -334,7 +334,7 @@ function scire_reject_client($clientid) {
}
}
-function scire_add_job($script, $priority, $creator, $permission, $description, $pending, $clients, $clientgroups) {
+function scire_add_job($script, $priority, $creator, $permission, $description, $pending, $clients, $clientgroups, $job_dependency, $run_schedule, $validity_period) {
global $db;
#First make the job
$db->query('LOCK TABLES jobs WRITE'); #LOCK TABLE
@@ -352,7 +352,12 @@ function scire_add_job($script, $priority, $creator, $permission, $description,
}
$db->query('UNLOCK TABLES'); #UNLOCK
#Now add the conditions and recurrance
-
+
+ $result = $db->insert('job_conditions', array('jobid' => $jobid, 'job_dependency' => $job_dependency, 'run_schedule' => $run_schedule, 'validity_period' => $validity_period));
+ if (!$result) {
+ return $db->error;
+ }
+
#Now add the clients.
foreach ($clients as $client) {
$result = $db->query('INSERT INTO `jobs_clients` (jobid, clientid) '.
@@ -408,7 +413,8 @@ function get_scire_job($jobid) {
'FROM jobs AS j '.
'JOIN users AS u ON (j.creator=u.userid) '.
'LEFT JOIN job_conditions AS jc ON (j.jobid=jc.jobid) '.
- 'LEFT JOIN permissions AS p ON (j.permission=p.permid)');
+ 'LEFT JOIN permissions AS p ON (j.permission=p.permid) '.
+ ' WHERE j.jobid=\'' . (int) $jobid . '\'');
if ($result && count($result) > 0) {
return $result[0];
} else {
diff --git a/scire/.smarty/templates/add_job.tpl b/scire/.smarty/templates/add_job.tpl
index bf4a997..d352b8a 100755
--- a/scire/.smarty/templates/add_job.tpl
+++ b/scire/.smarty/templates/add_job.tpl
@@ -36,7 +36,7 @@
</tr>
{if !isset($get.scriptid)}
<tr>
- <td colspan="2">Or just type in the ID of the script: <input type="text" name="script" ></td>
+ <td colspan="2">Or just type in the ID of the script: <input type="text" name="scriptID" ></td>
</tr>
{/if}
<tr>
@@ -301,6 +301,9 @@ Recurring stuff here.<br>
<option value=6> Saturday
</select>
</td></tr>
+<tr><td>
+<label for="validity_period">Validity Period: </label><input type="text" name="validity_period" />
+</td></tr>
</table>
<hr>
Job dependency stuff here.<br>
diff --git a/scire/add_job.php b/scire/add_job.php
index 29d9905..afc9494 100644
--- a/scire/add_job.php
+++ b/scire/add_job.php
@@ -1,5 +1,6 @@
<?php
include('.lib/common.php');
+include('cron2.php');
$smarty->assign('leftbar', "on");
$leftbar_menu = array();
@@ -34,12 +35,28 @@ if ($_POST['ADD']) {
}
$pending = sizeof($_POST['clients']);
if (!$status and ($pending or $_POST['clientgroups'])) { #We have a script and clients;
- $result = scire_add_job($_POST['script'], $priority, $_SESSION['userid'], $permission, $description, $pending, $_POST['clients'], $_POST['clientgroups']);
- if (!$result) {
- $status .= "Job successfully added.";
+ # Get the schedule!
+ $scheduleComplete = $_POST["minute1"] and $_POST["hour1"] and
+ $_POST["day1"] and $_POST["month1"] and $_POST["weekday1"];
+ if ($scheduleComplete) {
+ $str = implode(" ", array($_POST["minute1"], $_POST["hour1"],$_POST["day1"], $_POST["month1"], $_POST["weekday1"]));
} else {
- $status .= "Error occurred during job addition. $result";
+ $str = "";
}
+
+ $dependency = 1;
+
+ try {
+ $cron = new CronParser($str);
+ $result = scire_add_job($_POST['script'], $priority, $_SESSION['userid'], $permission, $description, $pending, $_POST['clients'], $_POST['clientgroups'], $dependency, $str, $_POST['validity_period']);
+
+ if (!$result) {
+ $status .= "Job successfully added.";
+ } else {
+ $status .= "Error occurred during job addition. $result";
+ }
+ } catch (CronException $e) {}
+
}
}