initial import from onelab svn codebase
[plewww.git] / planetlab / sirius / index.php
1 <?php
2
3 // Require login
4 require_once 'plc_login.php';
5
6 // Get session and API handles
7 require_once 'plc_session.php';
8 global $plc, $api, $adm;
9
10 // Common functions
11 require_once 'plc_functions.php';
12 require_once 'plc_sorts.php';
13
14 // find person roles
15 $_person= $plc->person;
16 $_roles= $_person['role_ids'];
17
18 //require 'sirius_func.php';
19
20 // Print header
21 require_once 'plc_drupal.php';
22 drupal_set_title('Sirius');
23 include 'plc_header.php';
24
25 ?>
26
27 <h2>Sirius Calendar Service</h2>
28
29 You can choose to run your experiment at the earliest available
30 time or give a specific time.  The number of repetitions has
31 the following meaning: if you want your job re-inserted on the
32 schedule list (in the earliest slot available) directly after it 
33 gets a priority increase, you can do so (up to 4 times).  Currently, 
34 our admission control policy is that we 
35 allow only one slice per time slot.  <p>
36
37 Currently, 
38 time slots are only allocated on the granularity
39 of an hour, and
40 only CPU is increased.
41
42 <h3>
43 Current Schedule
44 </h3>
45
46 <?php
47
48 define("SUCCESS", 0);
49 define("NO_ROOM", 1);
50 define("TOO_MANY_UNITS", 2);
51 define("NO_UNITS_LEFT", 3);
52 define("TIME_ALREADY_OCCURRED", 4);
53 define("NO_SUCH_SLICE", 5);
54 define("NOT_SLICE_OWNER", 6);
55 define("TOO_CLOSE_TO_DEADLINE", 7);
56
57 define("DELETE_THRESHOLD", 600);
58 define("MAX_JOBS", 1);
59
60 function authorizeSlice($sn) {
61         /*
62   $_api = new xmlrpc_client('/PLCAPI/', 'planet-lab.org', 443);
63
64   $username = $_SESSION['username'];
65   $password = $_SESSION['password'];
66   
67   $_api->setDebug(0);
68
69   $_api_auth = new xmlrpcval(array(
70                                    "AuthMethod" => new xmlrpcval("password"),
71                                    "Username" => new xmlrpcval($username),
72                                    "AuthString" => new xmlrpcval($password),
73                                    "Role" => new xmlrpcval("user")), "struct");
74   
75   $func = new xmlrpcmsg("SliceInfo");
76   $func->addParam($_api_auth);
77
78   $result = $_api->send($func, 15, 'https');
79
80   if( $result == 0 ) {
81     //    printf("problem: %s\n", $_api->errstring);
82     return 0;
83   }
84   else if($result->faultCode() != 0) {
85     //    printf("server problem: %s\n", $result->errstr);
86     return 0;
87   }
88   else {
89     $result_value = $result->value();
90
91     if( !$result_value ) {
92       //      printf( "didn't get value back from api\n" );
93       return 0;
94     }
95     else {
96       $arr = xmlrpc_decode($result_value);
97       //      printf( "return value success, value %s\n", $val);
98       //      print_r($val);
99       $numElements = count($arr);
100       $i = 0;
101       while ($i < $numElements) {
102         if ($sn == $arr[$i][name])
103           return 1;
104         $i++;
105       }
106       return 0;
107     }
108   }
109   */
110         
111         global $api;
112   
113   $slice_list= array();
114   $result= $api->GetSlices( $slice_list, array( "name" ) );
115   
116   foreach ( $result AS $slice )
117   {
118         if ( $slice["name"] == $sn )
119                 return 1;
120         
121   }
122   
123   return 0;
124   
125 }
126
127 //can a request be satisfied?  Currently, answer is yes unless
128 //either this time is taken or you asked for more than one unit
129 //probably will need to change this.  
130 function validateRequest ($units, $timesOccupied, $requestedTime, $currentTime) {
131   if ($units != 1)
132     return TOO_MANY_UNITS;
133
134   // buffer so we aren't too close to deadline, if your request is late
135   // OR if it's within 1 minute of deadline, it's too late
136   if ($requestedTime - 60 <= $currentTime)
137     return TIME_ALREADY_OCCURRED;
138
139   if (array_key_exists($requestedTime, $timesOccupied)) {
140     if ($timesOccupied[$requestedTime] == MAX_JOBS)
141       return NO_ROOM;
142   }
143   return SUCCESS;
144 }
145
146 //can a request be satisfied?  Currently, answer is yes unless
147 //either this time is taken or you asked for more than one unit
148 //probably will need to change this.  
149 function validateAndMarkRequest ($units, &$timesOccupied, $requestedTime, $currentTime, $sn, $jobArray) {
150   // buffer so we aren't too close to deadline, if your request is late
151   // OR if it's within 1 minute of deadline, it's too late
152   if ($requestedTime - 60 <= $currentTime)
153     return TIME_ALREADY_OCCURRED;
154
155   if (array_key_exists($requestedTime, $timesOccupied)) {
156     if ($timesOccupied[$requestedTime] == MAX_JOBS)
157       return NO_ROOM;
158     else
159       $timesOccupied[$requestedTime]++;
160   }
161   else {
162     $timesOccupied[$requestedTime] = 1;
163     if (array_key_exists($sn, $jobArray)) {
164       $ts = $jobArray[$sn]["timestamp"];
165       $timesOccupied[$ts]--;
166     }
167   }
168
169   if ($units != 1)
170     return TOO_MANY_UNITS;
171
172   return SUCCESS;
173 }
174
175 function findNextFreeSlot($units, $timesOccupied) {
176   $currYear = gmdate("y");
177   $currMonth = gmdate("m");
178   $currDate = gmdate("d");
179   $currHour = gmdate("H") + 1;
180   $currentTime = gmmktime();
181   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
182   $retVal = 1;
183   while ($retVal != SUCCESS) {
184     $retVal = validateRequest($units, $timesOccupied, $reqTime, $currentTime);
185     if ($retVal == NO_ROOM || $retVal == TIME_ALREADY_OCCURRED) { // advance timestamp one hour (3600 seconds)
186       $reqTime = $reqTime + 3600;
187     }
188   }
189   return $reqTime;
190 }
191
192 function dumpToFile($fileName, $buffer, $which, $timesOccupied) {
193   //open file, and dump newly list into it (buffer is the list)
194   //we're just currently overwriting (fopen with "w" truncates)
195
196   $fileHandle = fopen($fileName, "w");
197   //periodically, updateSliceUnits program will update the slices file
198   //this function is general, works for schedule or slices file
199
200   //lock in case of concurrent accesses
201   flock($fileHandle, LOCK_EX);
202   
203   if ($which == "schedule") {  // need to write timestamp in this case
204     $s = gettimeofday();
205     fwrite($fileHandle, $s[sec]);
206     fwrite($fileHandle, "\n");
207   }
208
209   //do the dump here
210   foreach ($buffer as $value) {
211     $t = "";
212     if ($which == "schedule") {  
213       if (strcmp($value["timestamp"], mktime()) > 0) {
214         $numReps = $value["reps"];
215         $ts = $value["timestamp"];
216         $t = $value["sliceName"]." ".$value["id"]." ".$value["timestamp"]." ".$value["units"]." ".$value["reps"]." \n";
217       }
218       else {  // job expired, does it need be run again?
219         if ($value["reps"] > 0) {
220           $ts = findNextFreeSlot($value["units"], $timesOccupied);
221         }
222         $numReps = $value["reps"] - 1;
223       }
224       if ($numReps >= 0)
225         $t = $value["sliceName"]." ".$value["id"]." ".$ts." ".$value["units"]." ".$numReps." \n";
226     }
227     else if ($which == "slices") {
228       $t = $value["sliceName"]." ".$value["units"]." \n";
229     }
230
231     if ($t != "")
232       fwrite($fileHandle, $t);
233
234   }
235
236   flock($fileHandle, LOCK_UN);
237
238   fclose($fileHandle);
239 }
240
241 //update the slice file, takes a slice name (name) and number of units
242 function updateSliceFile($name, $units) {
243   $dummyArray = array();
244
245   $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "rw");
246   if (!$sliceFile) {
247     echo "<p>Unable to open remote file.</p>"; 
248     
249   }
250
251   flock($sliceFile, LOCK_EX);
252
253   //we'll construct a new list here, will be current slice file except 
254   //the slice in question will have it's units decreased, if there are any...
255   while (!feof($sliceFile)) {
256     $num = fscanf($sliceFile, "%s %d\n", $sliceName, $unitsAvailable);
257     //for some reason feof seems to not quite work
258     //precisely, the last entry in the file is read twice (!?!), so hack here
259     if ($num == 0)
260       break;
261
262     $newArray["sliceName"] = $sliceName;
263     if ($name == $sliceName) {
264       $newUnits = $unitsAvailable - $units;
265       if ($newUnits < 0)  // error, slice has no more units
266         return -1;
267       else
268         $newArray["units"] = $newUnits;
269     }
270     else
271       $newArray["units"] = $unitsAvailable;
272     //append this tuple to the entire array
273     $sliceArray[] = $newArray;
274   }
275   flock($sliceFile, LOCK_UN);
276   fclose($sliceFile);
277   //do the dump to new file
278   dumpToFile("/var/www/html/planetlab/sirius/slices.txt", $sliceArray, "slices", dummyArray);
279   return 0;
280 }
281
282
283 //pretty obvious what this does; basically, does the slice exist in
284 //the slice file yet?  (New user of calendar service user may not have 
285 //an entry)
286 function isFirstSliceRequest($name) {
287   $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "r");
288   if (!$sliceFile) {
289     echo "<p>Unable to open remote file.</p>"; 
290     
291   }
292
293   flock($sliceFile, LOCK_EX);
294
295   while (!feof($sliceFile)) {
296     $num = fscanf($sliceFile, "%s %d\n", $sliceName, $unitsAvailable);
297     //for some reason feof seems to not quite work
298     //precisely, the last entry in the file is read twice (!?!), so hack here
299     if ($num == 0)
300       break;
301
302     if ($name == $sliceName) {
303       flock($sliceFile, LOCK_UN);
304       fclose($sliceFile);
305       return 0;
306     }
307   }
308
309   flock($sliceFile, LOCK_UN);
310   fclose($sliceFile);
311   return 1;
312 }
313
314
315 function cmp ($a, $b) {
316   if ($a["timestamp"] == $b["timestamp"])
317     return 0;
318   else
319     return ($a["timestamp"] < $b["timestamp"]) ? -1 : 1;
320 }
321
322 function checkForErrors($requestStatus) {
323   if ($requestStatus == NO_ROOM) {
324     printf("<b> Error: Cannot add your request; that time slot is currently full. </b> <p>");
325   }
326   else if ($requestStatus == TOO_MANY_UNITS) {
327     printf("<b> Error: Cannot add your request; only 1 extra unit is allowed.</b> <p>");
328   }
329   else if ($requestStatus == NO_UNITS_LEFT) {
330     printf("<b> Error: Cannot add your request; no more units remaining.</b> <p>");
331   }
332   else if ($requestStatus == TIME_ALREADY_OCCURRED) {
333     printf("<b> Error: Cannot add your request; that time has already occurred, or is too close to the current time.</b> <p>");
334   }
335   else if ($requestStatus == NO_SUCH_SLICE) {
336     printf("<b> Error: Cannot delete nonexistent slice.</b> <p>");
337   }
338   else if ($requestStatus == NOT_SLICE_OWNER) {
339     printf("<b> Error: Only authorized user can manipulate slice.</b> <p>");
340   }
341   else if ($requestStatus == TOO_CLOSE_TO_DEADLINE) {
342     printf("<b> Error: Cannot delete your request; it is too close to
343 the time that your slice will receive its priority increase.</b> <p>");
344   }
345 }
346
347 function getCurrentSchedule (&$jobArray, &$timesOccupied, &$maxId) {
348
349   $schedFile = fopen("/var/www/html/planetlab/sirius/schedule.txt", "r");
350   if (!$schedFile) {
351     echo "<p>Unable to open remote file.</p>"; 
352     
353   }
354
355   flock($schedFile, LOCK_EX);
356
357   //first line is timestamp, throw it away.
358   fscanf($schedFile, "%s\n", $str);
359
360   //read in current file into array
361   $jobArray = array();
362   $newArray = array();
363   $timesOccupied = array();
364   $maxId = 0;
365   while (!feof($schedFile)) {
366     $num = fscanf($schedFile, "%s %d %s %d %d\n", $sliceName, $id, $timestamp, $units, $reps);
367
368     if ($id > $maxId)
369       $maxId = $id;
370
371     //for some reason feof seems to not quite work
372     //precisely, the last entry in the file is read twice (!?!), so hack here
373     if ($num == 0)
374       break;
375     $newArray["sliceName"] = $sliceName;
376     $newArray["id"] = $id;
377     $newArray["units"] = $units;
378     $newArray["timestamp"] = $timestamp;
379     $newArray["reps"] = $reps;
380     $jobArray[$sliceName] = $newArray;
381
382     if (array_key_exists($timestamp, $timesOccupied)) {
383       $timesOccupied[$timestamp]++;
384     }
385     else {
386       $timesOccupied[$timestamp] = 1;
387     }
388
389   }
390
391   flock($schedFile, LOCK_UN);
392   fclose($schedFile);
393
394 }
395
396 // Reid: after below function call, you have the current schedule.
397 // It is stored in $jobArray, which is an array of arrays.  
398 // Layout: each element of $jobArray is an array with
399 //         the following fields.
400 //   "sliceName": the name of the slice that occupies the slot
401 //   "id": the id of the slice, currently not used; do not display
402 //   "units": another field that will be used eventually...but not yet
403 //   "reps": indicates how many repetitions slice has specified; for
404 //           each repetition, the slice is automatically rescheduled
405 //           after running for the earliest available slot
406 // I don't know if you want to pring the schedule out as part of the
407 // queue here, or wait to see if there was a submitted job.
408 // See my comments below for more details.
409
410 getCurrentSchedule ($jobArray, $timesOccupied, $maxId);
411
412 $changeMade = 0;
413
414 // Reid: here, we see if a new request is submitted (which would
415 //       be done now as: did the user click into the queue and
416 //       select a slice to get the next slot.  I think you can just
417 //       skip to the end of this if statement (see comment below)
418
419 // Reid: The problem here is, this is based on the current submission
420 //       procedure, which is: click the submit button (or the delete
421 //       button).  I'm not sure how to change or modularize this
422 //       function because I don't know how the queue would precisely
423 //       be implemented.  I've commented the code below to try to help.
424
425 //if form was submitted with new job, process it
426 if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
427   $sname = $_POST['sliceName'];
428
429   if (!authorizeSlice($sname)) {
430     $requestStatus = NOT_SLICE_OWNER;
431   }
432   else if ($_POST['add_delete'] == "delete") {
433     // delete request.  Make sure it exists and is early enough to delete,
434     // then delete it.
435     if (array_key_exists($sname, $jobArray)) {
436       $changeMade = 1;
437       $ts = $jobArray[$sname]["timestamp"];
438       if ($ts - mktime() < DELETE_THRESHOLD)
439         $requestStatus = TOO_CLOSE_TO_DEADLINE;
440       else {
441         $timesOccupied[$ts]--;
442         unset($jobArray[$sname]);
443       }
444     }
445     else 
446       $requestStatus = NO_SUCH_SLICE;
447   }
448
449   else {
450     // it's an add request
451     // grab all the data from the user.
452     $changeMade = 1;
453     //    $minute = $_POST['minute'];
454     $reps = $_POST['reps'];
455     //  $u = $_POST['units'];
456     $u = 1;
457     
458     $currentTime = mktime();
459
460     if ($_POST['whenToRun'] == "asap") {
461       $requestedTime = findNextFreeSlot($u, $timesOccupied);
462     }
463     else {
464       //      $requestedTime = gmmktime($hour, $minute, 0, $month, $date, $year);
465       if (!isset( $_POST['queue_time'] )) {
466         $year = $_POST['year'];
467         $month = $_POST['month'];
468         $date = $_POST['date'];
469         $hour = $_POST['hour'];
470         $requestedTime = gmmktime($hour, 0, 0, $month, $date, $year);
471       }
472       else {
473         $currYear = gmdate("y");
474         $currMonth = gmdate("m");
475         $currDate = gmdate("d");
476         $currHour = gmdate("H");
477         $hour = $_POST['queue_time'];
478         if ($hour < $currHour) {
479           $requestedTime = gmmktime($hour, 0, 0, $currMonth, $currDate+1, $currYear);
480         }
481         else
482           $requestedTime = gmmktime($hour, 0, 0, $currMonth, $currDate, $currYear);
483       }
484     }
485     
486     $id = $maxId + 1;
487     
488     $requestStatus = validateAndMarkRequest($u, $timesOccupied, $requestedTime, $currentTime, $sname, $jobArray);
489     if ($requestStatus == SUCCESS) {
490       // ignore below, it is for future work anyways.
491       if (isFirstSliceRequest($sname)) {
492         $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "a");
493         if ($sliceFile == 0) {
494           echo "<p>Unable to open file.</p>"; 
495           
496         }
497         flock($sliceFile, LOCK_EX);
498         
499         // should be max number of units, not 5
500         // why is this 6?
501         fwrite($sliceFile, $sname." "."6");
502         flock($sliceFile, LOCK_UN);
503         fclose($sliceFile);
504       }
505       // if (updateSliceFile($sname, 1) < 0)
506       // temporarily not looking at units...
507       if (0)
508         $requestStatus = NO_UNITS_LEFT;  
509       else {
510         // here, pretty simple, just stick all data into 
511         // array element, then stick array into $jobArray.
512         $newArray["sliceName"] = $sname;
513         $newArray["id"] = $id;
514         $newArray["timestamp"] = $requestedTime;
515         $newArray["units"] = $u;
516         $newArray["reps"] = $reps;
517         $jobArray[$sname] = $newArray;
518       }
519     }
520   }
521   //  header("Location: planetcal.php");
522 }
523
524 //sort job array by earliest time first ("cmp" function does this)
525 usort($jobArray, "cmp");  
526
527 // Reid: after this above line, $jobArray holds a sorted list that
528 //       you can output as the queue.
529
530 // Reid: below is the current printing of the schedule, which would
531 //       certainly be deleted when you have the better representation
532 //       of the schedule (the visual queue).  It starts here and ends
533 //       where I've marked below.
534
535 //print current job list as table on screen
536 printf("<table cellspacing=0 cellpadding=2>");
537 if (count($jobArray) > 0) {
538   printf("<tr>");
539   printf("<th style='border: 1px black solid'> Slice name </th> <th style='border: 1px black solid'> Repetitions </th><th style='border: 1px black solid'> Time of priority </th>");
540   printf("</tr>");
541 }
542 else {
543   printf("<tr>");
544   printf("<td>No jobs currently on queue </td><td></td><td></td>");
545   printf("</tr>");
546 }
547
548 $deletedExpiredJob = 0;
549
550 $arr= array();
551 $n= 0;
552 foreach ($jobArray as $value) {
553   if (strcmp($value["timestamp"], mktime()) > 0) {
554     printf("<tr>\n");
555     printf("<td> %s </td><td align=center> %d </td><td> %s </td>\n", $value["sliceName"], $value["reps"], gmdate("r", $value["timestamp"]));
556     $arr[$n]= $value["sliceName"];
557     $n++;
558     printf("</tr>\n");
559   }
560   else {
561     $deletedExpiredJob = 1;
562   }
563 }
564 printf("</table>\n");
565 echo "<br>\n";
566 // Reid: end of current printing of the schedule.
567
568 // Reid: here is where we put the data back to the schedule file.
569 //       It's already a function, 
570
571 function findNextQueue($units, $timesOccupied, $arr) {
572
573   $currYear = gmdate("y");
574   $currMonth = gmdate("m");
575   $currDate = gmdate("d");
576   $currHour = gmdate("H") + 1;
577   $currentTime = gmmktime();
578   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
579   $retVal = 1;
580   $i = 0;
581         
582
583         // DAVE
584         // outputting table to display the queue
585         // green background will mean slot is open, and red will mean the slot is used
586         // 
587   echo "<table cellspacing=\"2\" cellpadding=\"1\" border=\"0\" width=550>\n";
588   echo "<tr><td colspan=\"3\"><strong>24 hour Queue:</strong> Choose the GMT time slot you desire (<font color=\"#339933\">green</font> slots are open, <font color=\"#CC3333\">red</font> are taken) <p></td></tr>\n";
589   echo "<tr><td width=\"47%\" align=\"right\"><table cellspacing=1 cellpadding=1 border=0 width=130>\n";
590
591   // here's what this does below: it goes through each hour, and sees if the slot is occupied
592   // if so, it outputs in red, w/ slice name ($arr[$x], where $x is the number request, i.e.
593   // earlier when we dump out the list of slices on the schedule, we do $arr[$x++] = $slicename
594   $x= 0;
595   //  while ($reqTime < ( $reqTime + ( 24 * 3600 ) ) ) {
596   while ($i < 12) {
597     $retVal = validateRequest($units, $timesOccupied, $reqTime, $currentTime);
598     if ($retVal == SUCCESS) { // advance timestamp one hour (3600 seconds)
599           
600         echo "<tr bgcolor=\"#339933\"><td><input type=\"radio\" name=\"queue_time\" value=\"" . gmdate("H:i:s", $reqTime) . "\"> " . gmdate("H:i:s", $reqTime) . " &nbsp;  </td></tr>\n";
601     }
602     else {
603         echo"<tr bgcolor=\"#CC3333\"><td align=center> " . $arr[$x] . " </td></tr>\n";
604         $x++;
605     }
606
607     $reqTime = $reqTime + 3600;
608     $i++;
609   }
610   echo "</table></td><td width=\"6%\"> &nbsp; </td><td><table cellspacing=1 cellpadding=1 border=0 width=130>\n";
611
612   while ($i < 24 && $i > 11) {
613     $retVal = validateRequest($units, $timesOccupied, $reqTime, $currentTime);
614     if ($retVal == SUCCESS) { // advance timestamp one hour (3600 seconds)
615
616         echo "<tr bgcolor=\"#339933\"><td><input type=\"radio\" name=\"queue_time\" value=\"" . gmdate("H:i:s", $reqTime) . "\"> " . gmdate("H:i:s", $reqTime) . " &nbsp;  </td></tr>\n";     }
617     else {
618         echo"<tr bgcolor=\"#CC3333\"><td align=center> " . $arr[$x] . " </td></tr>\n";
619         $x++;
620     }
621
622     $reqTime = $reqTime + 3600;
623     $i++;
624   }
625   echo "</table></td></tr>\n";
626
627   echo "</table>\n";
628
629 }
630
631 function sliceDropDown() {
632   /*
633         $_api = new xmlrpc_client('/PLCAPI/', 'planet-lab.org', 443);
634
635   $username = $_SESSION['username'];
636   $password = $_SESSION['password'];
637   
638   $_api->setDebug(0);
639
640   $_api_auth = new xmlrpcval(array(
641                                    "AuthMethod" => new xmlrpcval("password"),
642                                    "Username" => new xmlrpcval($username),
643                                    "AuthString" => new xmlrpcval($password),
644                                    "Role" => new xmlrpcval("user")), "struct");
645   
646   $func = new xmlrpcmsg("SliceInfo");
647   $func->addParam($_api_auth);
648
649   $result = $_api->send($func, 15, 'https');
650   
651   if( $result == 0 ) {
652     //    printf("problem: %s\n", $_api->errstring);
653     return 0;
654   }
655   else if($result->faultCode() != 0) {
656     //    printf("server problem: %s\n", $result->errstr);
657     return 0;
658   }
659   else {
660     $result_value = $result->value();
661
662     if( !$result_value ) {
663       //      printf( "didn't get value back from api\n" );
664       return 0;
665     }
666     else {
667       $arr = xmlrpc_decode($result_value);
668       //      printf( "return value success, value %s\n", $val);
669       //      print_r($val);
670       $numElements = count($arr);
671       $i = 0;
672       while ($i < $numElements) {
673                 echo "<option value='" . $arr[$i][name] . "'>" . $arr[$i][name] . "</option>\n";
674                 
675                 $i++;
676       }
677       return 0;
678     }
679   }
680   */
681         global $api;
682   
683   $slice_list= array();
684   $result= $api->GetSlices( Null, array( "name" ) );
685   sort_slices( $result );
686   foreach ( $result AS $slice )
687   {
688         echo "<option value='" . $slice["name"] . "'>" . $slice["name"] . "\n";
689         
690   }
691   
692 }
693 //reopen schedule file, and dump newly sorted job list into it
694 //note that current timestamp is put in at beginning
695 //note also: only do this dump if a change has been made
696
697 if ($deletedExpiredJob || ($changeMade && $requestStatus == SUCCESS)) {
698   dumpToFile("/var/www/html/planetlab/sirius/schedule.txt", $jobArray, "schedule", $timesOccupied);
699
700   // hack here...the problem is that the file might not be sorted
701   // when it should, because of the stupid way it was designed.  this
702   // happens when reps is not 0, and the next entry should go after 
703   // another entry.  what does happen is that it goes before, which is
704   // fine for displaying, but the sirius service code expects it to
705   // always be sorted, "it" being the schedule file
706
707   $hackArray = array();
708   getCurrentSchedule ($hackArray, $timesOccupied, $maxId);
709   usort($hackArray, "cmp");  
710   dumpToFile("/var/www/html/planetlab/sirius/schedule.txt", $hackArray, "schedule", $timesOccupied);
711 }
712
713 checkForErrors($requestStatus);
714 ?>
715
716 <h3>
717 Priority Queue
718 </h3>
719
720 <form action="/db/sirius/index.php" method="post">
721 <p>Choose your slice name:
722 <select name="sliceName">
723 <?php sliceDropDown(); ?>
724 </select>
725
726 <p>
727 Either Add a new time slot or remove a previously taken slot:
728 <br>
729 <b>Add</b> <input type=radio name="add_delete" value="add" checked/>
730 <b>Delete</b> <input type=radio name="add_delete" value="delete" />
731 <p>
732 ASAP will just select the next availible time, choose specific time if you want to specify a slot in the queue:
733 <br>
734 <b>ASAP</b> <input type=radio name="whenToRun" value="asap" checked/>
735 <b>Specific Time</b> <input type=radio name="whenToRun" value="specific" />
736 <p>
737 Choose a number of times you need CPU priority:
738 <br>
739 <b>Number of Repetitions</b>:
740 0 <input type=radio name="reps" value="0" checked/>
741 1 <input type=radio name="reps" value="1"/>
742 2 <input type=radio name="reps" value="2"/>
743 3 <input type=radio name="reps" value="3"/>
744 4 <input type=radio name="reps" value="4"/>
745
746 <p>
747
748 <?php findNextQueue( 1, $timesOccupied, $arr ); ?>
749
750 <p>
751 Only enter a time/date here if your request is for a time more than 24 hours from now.<br>
752 Year (two digits) <input type=text maxlength=2 size=2 name="year"/> 
753 Month (1-12) <input type=text maxlength=2 size=2 name="month"/> 
754 Date (1-31) <input type=text maxlength=2 size=2 name="date"/> 
755 Hour (0-23) <input type=text maxlength=2 size=2 name="hour"/> 
756 <p>
757 <!--Units <input type=text maxlength=2 size=2 name="units"/>-->
758 <!--<p>-->
759 <input type="hidden" name="action" value="submitted" />
760 <input type="submit" name="submit" value="Submit" />
761 <input type="reset" name="reset" value="Reset" />
762 </form>
763
764 <p>