Changeset 16358
- Timestamp:
- Feb 7, 2008, 2:48:11 PM (18 years ago)
- Location:
- trunk/pstamp
- Files:
-
- 3 added
- 2 deleted
- 3 edited
-
scripts/dumpvars.sh (deleted)
-
scripts/ppstamp_run.pl (modified) (2 diffs)
-
scripts/pstamp_dorequest.pl (modified) (5 diffs)
-
scripts/pstamp_listjobs.pl (added)
-
scripts/pstamp_runcommand.sh (added)
-
scripts/pstamp_webrequest.pl (added)
-
scripts/pstampwebrequest.sh (deleted)
-
web/request.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/ppstamp_run.pl
r16283 r16358 15 15 my $job_id = $ARGV[0]; 16 16 17 my $verbosity = 1;17 my $verbosity = 0; 18 18 19 19 use Sys::Hostname; … … 125 125 126 126 127 exit $jobStatus; 127 if ($jobStatus eq "ok") { 128 exit 0; 129 } else { 130 exit $jobStatus; 131 } -
trunk/pstamp/scripts/pstamp_dorequest.pl
r16283 r16358 1 1 #!/bin/env perl 2 2 ### 3 ### pstamp do_req.pl3 ### pstamp_dorequest.pl 4 4 ### 5 ### Run the jobs for a given request6 ### This is intended for running outsidepantasks environment5 ### Excecute the jobs for a given request. 6 ### Note: This is intended for testing outside of pantasks environment 7 7 ### 8 8 … … 16 16 my $request_id = $ARGV[0]; 17 17 18 my $verbosity = 1;18 my $verbosity = 0; 19 19 20 20 use Sys::Hostname; … … 77 77 foreach my $job (@$jobs) { 78 78 if ($job->{req_id} == $request_id) { 79 # there must be a better way to do this 80 print STDERR "adding $job->{job_id} to the list\n"; 79 # print STDERR "adding $job->{job_id} to the list\n"; 81 80 $psjobs[@psjobs] = $job; 82 81 } … … 85 84 86 85 if (! @psjobs) { 86 # TODO: is this always an error, what if the job is no longer pending? 87 87 print STDERR "no pending postage stamp jobs for request $request_id found\n"; 88 # TODO: is this always an error, what if the job is no longer pending?89 88 exit 1; 90 89 } … … 103 102 # Update the state of the request 104 103 # 104 { 105 ## TODO: what about request status 106 my $command = "$pstamptool -processedreq -req_id $request_id -state stop"; 107 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 108 run(command => $command, verbose => $verbosity); 109 unless ($success) { 110 die("Unable to perform pstamptool -processedreq: $error_code"); 111 } 112 } 105 113 106 114 exit 0; -
trunk/pstamp/web/request.php
r16283 r16358 1 <html>2 <head>3 <title>Postage Stamp Request Form</title>4 </head>5 <form method="post">6 7 <body>8 9 <H1 align=center>10 Postage Stamp Request Form11 </h1>12 13 <!--- for dumping output from the following code for debug TODO: remove this--->14 <pre>15 1 <?php 16 2 3 // A php program that generates a postage stamp request form 4 5 // There are two modes on the form List Images simply lists the input images that match 6 // the image selection critera 7 8 // When make stamps is selected when the page is posted, a postage stamp request is queued. 9 // 10 // Then we respond to http posts by listing the status of the jobs. 11 // Once all of the jobs complete we set the page back to submission mode again 12 // The mode for the page is given by $request_id != 0 13 17 14 $COMMAND_DIR = "/export/data0/bills/src/ipp/pstamp/scripts"; 18 $STAMPS_DIR = " stamps";15 $STAMPS_DIR = "/export/data1/bills/pstamp/work/stamps"; 19 16 20 17 // Initialize variables 21 18 $output_array = array(); 19 20 $request_id = 0; 21 $last_request_id = 0; 22 22 23 23 $raw_selected = ""; … … 61 61 62 62 $rvar_cmd_mode = ""; 63 $rvar_request_id = 0; 64 $rvar_last_request_id = 0; 63 65 64 66 // now get the values from this post … … 110 112 } 111 113 112 if ($rvar_cmd_mode == "Make Stamps") { 114 // When request_id is non-zero we respond to posts by check the status of that request 115 // request_id gets set to zero when the status of all jobs for the request is 'stop' 116 $request_id = $rvar_request_id; 117 $last_request_id = $rvar_last_request_id; 118 119 120 // default to list mode, unless we are waiting for a request to finish 121 if (($rvar_cmd_mode == "Make Stamps") || ($request_id != 0)) { 113 122 $pstamp_checked = "checked"; 114 123 $list_checked = ""; … … 118 127 } 119 128 120 echo "\n\n\n"; 121 122 // If the data is from a Post run the command 123 // How do we know? Well if it's the initial get of the web page, rvar_img_type is not set 124 // TODO: find a better way to decide whether to proceed 129 130 // echo "rvar_request_id: $rvar_request_id\n"; 131 132 // HERE is the logic for running the various commands 133 134 // How do we know? Well if we aren't running the initial get of the web page? 135 // Well, in that case rvar_img_type is not set so key off of that 136 // TODO: find a better way to decide whether or not to run commands 137 125 138 if ($rvar_img_type) { 126 139 127 try { 128 $command_line = build_command_line(); 140 if ($request_id == 0) { 141 try { 142 $command_line = build_command_line(); 143 $error_line = ""; 144 run_command(); 145 if (! $list_checked) { 146 // The only output from a successful run is the request_id 147 $request_id = Array_pop($output_array); 148 $last_request_id = $request_id; 149 #echo "The request id is $request_id\n"; 150 if (count($output_array) != 0) { 151 throw new Exception("unexpected output returned by pstampwebrequest."); 152 } 153 154 $jobRunning = getRequestStatus(); 155 if (!$jobRunning) { 156 $request_id = 0; 157 } 158 159 } 160 } catch (Exception $e) { 161 $error_line = $e->getMessage(); 162 } 163 } else { 164 try { 165 // get the list of jobs for the request 166 // echo "calling getRequestStatus\n"; 167 $jobRunning = getRequestStatus(); 168 169 if (!$jobRunning) { 170 $request_id = 0; 171 } 172 173 } catch (Exception $e) { 174 $error_line = $e->getMessage(); 175 } 176 } 177 } 178 179 function build_command_line() 180 { 181 global $rvar_project, $rvar_user_tag; 182 global $sky_checked, $rsky_checked; 183 global $list_checked; 184 global $rvar_RA, $rvar_DEC; 185 global $rvar_dRA, $rvar_dDEC; 186 global $rvar_X, $rvar_Y; 187 global $rvar_W, $rvar_H; 188 global $exp_checked, $file_checked, $coord_checked; 189 global $rvar_img_type; 190 global $rvar_id, $rvar_class_id; 191 global $command_line; 192 global $STAMPS_DIR; 193 194 $cmd = "pstamp_runcommand.sh pstamp_webrequest.pl"; 195 196 if ($list_checked) { 197 $cmd .= " -list"; 198 } 199 200 if (! $rvar_project ) { 201 throw new Exception('project must be specified.'); 202 } 203 $cmd .= " -project $rvar_project"; 204 if (! $rvar_user_tag ) { 205 throw new Exception('Stamp Name must be specified.'); 206 } 207 $cmd .= " -user_tag $STAMPS_DIR/$rvar_user_tag"; 208 209 // Set up the ROI parameters 210 if ($sky_checked) { 211 if (! $rvar_RA || ! $rvar_DEC) { 212 throw new Exception('RA and DEC must be specified.'); 213 } 214 $cmd .= " -skycenter $rvar_RA $rvar_DEC"; 215 } else { 216 if (! $rvar_X || ! $rvar_Y) { 217 throw new Exception('X and Y must be specified.'); 218 } 219 $cmd .= " -pixcenter $rvar_X $rvar_Y"; 220 } 221 222 if ($rsky_checked) { 223 if (! $rvar_dRA || ! $rvar_dDEC) { 224 throw new Exception('dRA and dDEC must be specified.'); 225 } 226 $cmd .= " -arcrange $rvar_dRA $rvar_dDEC"; 227 } else { 228 if (! $rvar_W || ! $rvar_H) { 229 throw new Exception('width and height must be specified.'); 230 } 231 $cmd .= " -pixrange $rvar_W $rvar_H"; 232 } 233 234 235 // Note: in the following block we assume that image type has been 236 // which is true since it comes from the menu 237 if ($exp_checked) { 238 if (! $rvar_id ) { 239 throw new Exception('Must set Exposure ID.'); 240 } 241 $cmd .= " -byexp $rvar_img_type $rvar_id"; 242 } else if ($file_checked) { 243 if (! $rvar_id ) { 244 throw new Exception('Must set ID specified.'); 245 } 246 $cmd .= " -byid $rvar_img_type $rvar_id"; 247 } else if ($coord_checked) { 248 // $cmd .= " -bycoord $rvar_img_type"; 249 $coord_checked = ""; 250 $exp_checked = "checked"; 251 throw new Exception("Image selection by coordinate not implemented yet."); 252 } 253 254 if (($rvar_img_type == "raw") || ($rvar_img_type == "chip")) { 255 if (! $rvar_class_id ) { 256 throw new Exception("must specify Class ID with Image Type $rvar_img_type."); 257 } 258 $cmd .= " $rvar_class_id"; 259 } 260 261 return escapeshellcmd($cmd); 262 } 263 264 function run_command() 265 { 266 global $command_line; 267 global $output_array; 268 global $error_line; 269 global $command_status; 270 global $COMMAND_DIR; 271 272 273 exec ("$COMMAND_DIR/$command_line", $output_array, $command_status); 274 275 $size = sizeof($output_array); 276 // echo "output_array contains $size lines\n"; 277 if ($command_status == 0) { 278 // On success we just remember the results 279 $dump_results = 0; 280 if ($dump_results) { 281 echo "Output: $size lines\n"; 282 for ($i = 0; $i < $size; $i++) { 283 echo "$output_array[$i]\n"; 284 } 285 } 286 } else { 287 // copy the output to the error_line 129 288 $error_line = ""; 130 run_command(); 131 } catch (Exception $e) { 132 $error_line = $e->getMessage(); 289 for ($i = 0; $i < $size; $i++) { 290 $error_line .= "$output_array[$i]\n"; 291 } 292 } 293 294 } 295 296 function printURL($line) 297 { 298 global $request_id; 299 global $last_request_id; 300 301 echo "<tr><td>"; 302 $doURL = 1; 303 if ($doURL) { 304 // echo "output_line: $line\n"; 305 $elements = explode(" ", $line); 306 if (count($elements) == 3) { 307 $job_id = $elements[0]; 308 $state = $elements[1]; 309 $path = $elements[2]; 310 $fileName = basename($path); 311 if ($state == "stop") { 312 // this job is done, list the url as a link 313 echo "<a href=\"http:$path\" target=\"_blank\" type=\"image/fits\">"; 314 echo $fileName; 315 echo "</a>"; 316 echo " request_id: $last_request_id "; 317 echo "job_id: $job_id state: $state"; 318 } else { 319 // TODO: refine this output 320 echo "$fileName request_id: $request_id "; 321 echo "job_id: $job_id state: $state"; 322 } 323 } 324 } else { 325 print "$line"; 326 } 327 328 echo "</td></tr>"; 329 } 330 331 function countRunningJobs() 332 { 333 global $output_array; 334 335 $runningJobs = 0; 336 $size = sizeof($output_array); 337 for ($i = 0; $i < $size; $i++) { 338 $elements = explode(" ", $output_array[$i]); 339 if (count($elements) == 3) { 340 $state = $elements[1]; 341 if ($state != "stop") { 342 $runningJobs++; 343 } 344 } else { 345 throw new Exception ("incorrect data in job status: $output_array[$i]"); 346 } 347 } 348 return $runningJobs; 349 } 350 351 function getRequestStatus() 352 { 353 global $request_id; 354 global $command_line; 355 global $command_status; 356 357 $command_line = "pstamp_runcommand.sh pstamp_listjobs.pl $request_id"; 358 run_command(); 359 360 if ($command_status == 0) { 361 return countRunningJobs(); 362 } else { 363 return 0; 133 364 } 134 365 } 135 366 136 367 ?> 137 </pre> 138 <!-- end of preformatted area for debug printing TODO: remove this --> 139 368 369 <!-- Beginning of the HTML --------------------------------------------- --> 370 <html> 371 <head> 372 <title>Postage Stamp Request Form</title> 373 <?php 374 if ($request_id != 0) { 375 // This doesn't do what I want. It does a get not a post 376 377 // echo '<META HTTP-EQUIV="refresh" CONTENT="5">'; 378 379 } 380 ?> 381 </head> 382 <form method="post"> 383 384 <body> 385 386 <H1 align=center> 387 Postage Stamp Request Form 388 </h1> 140 389 141 390 <!-- Whole page is a single column table --> 391 142 392 143 393 <table width=90% align=center> … … 327 577 <table width=40%> 328 578 <tr> 579 580 <?php 581 if ($request_id == 0): ?> 329 582 <td><input type=submit value="Submit"></td> 330 583 <td><b>Mode:</b> … … 332 585 <input type=radio name="cmd_mode" value="List Images" <?php echo $list_checked; ?> >List Images 333 586 </td> 587 <?php 588 else: ?> 589 <td><input type=submit value="Get Status"></td> 590 <?php 591 echo "<td><b>Request Id: $request_id"; 592 endif; ?> 593 334 594 </tr> 335 595 </table> … … 361 621 </td> 362 622 </tr> 363 <!-- a blank row for space--> 364 <tr height=20><td></td></tr> 623 624 <!-- a blank row for space --> 625 <tr height=20><td> </td></tr> 365 626 366 627 <tr> … … 374 635 if ($command_status == 0) { 375 636 if ($list_checked) { 637 // in list mode the output is a list of image files, just list them 638 // later we might add links to cause a stamp to be made from a selected file 376 639 for ($i = 0; $i < $size; $i++) { 377 640 echo "<tr><td>$output_array[$i]</td></tr>"; 378 641 } 379 642 } else { 643 // output the list of urls 380 644 for ($i = 0; $i < $size; $i++) { 381 645 printURL($output_array[$i]); … … 387 651 </td> 388 652 </tr> 653 <!-- a blank row for our hidden element here--> 654 655 <!-- request_id being non-zero causes us to issue status requests instead of new requsts --> 656 <!-- 657 658 need a way to cancel a request There's probably no reason to have the value hidden, but we do 659 need to set it as the last thing that we do 660 661 --> 662 663 <tr height=20> 664 <td> 665 <input type="hidden" name="request_id" value=<?php echo $request_id ?> > 666 </td> 667 <td> 668 <input type="hidden" name="last_request_id" value=<?php echo $last_request_id ?> > 669 </td> 670 </tr> 389 671 </table> 390 672 … … 398 680 399 681 <?php 400 // dump parameters 401 402 // phpinfo(32); 403 404 ?> 405 406 <?php 407 408 function build_command_line() 409 { 410 global $rvar_project, $rvar_user_tag; 411 global $sky_checked, $rsky_checked; 412 global $list_checked; 413 global $rvar_RA, $rvar_DEC; 414 global $rvar_dRA, $rvar_dDEC; 415 global $rvar_X, $rvar_Y; 416 global $rvar_W, $rvar_H; 417 global $exp_checked, $file_checked, $coord_checked; 418 global $rvar_img_type; 419 global $rvar_id, $rvar_class_id; 420 global $command_line; 421 global $STAMPS_DIR; 422 423 $cmd = "pstampwebrequest.sh"; 424 425 if ($list_checked) { 426 $cmd .= " -list"; 427 } 428 429 if (! $rvar_project ) { 430 throw new Exception('project must be specified.'); 431 } 432 $cmd .= " -project $rvar_project"; 433 if (! $rvar_user_tag ) { 434 throw new Exception('Stamp Name must be specified.'); 435 } 436 $cmd .= " -user_tag $STAMPS_DIR/$rvar_user_tag"; 437 438 // Set up the ROI parameters 439 if ($sky_checked) { 440 if (! $rvar_RA || ! $rvar_DEC) { 441 throw new Exception('RA and DEC must be specified.'); 442 } 443 $cmd .= " -skycenter $rvar_RA $rvar_DEC"; 444 } else { 445 if (! $rvar_X || ! $rvar_Y) { 446 throw new Exception('X and Y must be specified.'); 447 } 448 $cmd .= " -pixcenter $rvar_X $rvar_Y"; 449 } 450 451 if ($rsky_checked) { 452 if (! $rvar_dRA || ! $rvar_dDEC) { 453 throw new Exception('dRA and dDEC must be specified.'); 454 } 455 $cmd .= " -arcrange $rvar_dRA $rvar_dDEC"; 456 } else { 457 if (! $rvar_W || ! $rvar_H) { 458 throw new Exception('width and height must be specified.'); 459 } 460 $cmd .= " -pixrange $rvar_W $rvar_H"; 461 } 462 463 464 // Note: in the following block we assume that image type has been 465 // which is true since it comes from the menu 466 if ($exp_checked) { 467 if (! $rvar_id ) { 468 throw new Exception('Must set Exposure ID.'); 469 } 470 $cmd .= " -byexp $rvar_img_type $rvar_id"; 471 } else if ($file_checked) { 472 if (! $rvar_id ) { 473 throw new Exception('Must set ID specified.'); 474 } 475 $cmd .= " -byid $rvar_img_type $rvar_id"; 476 } else if ($coord_checked) { 477 // $cmd .= " -bycoord $rvar_img_type"; 478 $coord_checked = ""; 479 $exp_checked = "checked"; 480 throw new Exception("Image selection by coordinate not implemented yet."); 481 } 482 483 if (($rvar_img_type == "raw") || ($rvar_img_type == "chip")) { 484 if (! $rvar_class_id ) { 485 throw new Exception("must specify Class ID with Image Type $rvar_img_type."); 486 } 487 $cmd .= " $rvar_class_id"; 488 } 489 490 return escapeshellcmd($cmd); 491 } 492 493 function run_command() 494 { 495 global $command_line; 496 global $output_array; 497 global $error_line; 498 global $command_status; 499 global $COMMAND_DIR; 500 501 502 exec ("$COMMAND_DIR/$command_line", $output_array, $command_status); 503 504 $size = sizeof($output_array); 505 // echo "output_array contains $size lines\n"; 506 if ($command_status == 0) { 507 // echo "Output: $size lines\n"; 508 for ($i = 0; $i < $size; $i++) { 509 // echo "$output_array[$i]\n"; 510 } 511 } else { 512 // copy the output to the error_line 513 $error_line = ""; 514 for ($i = 0; $i < $size; $i++) { 515 $error_line .= "$output_array[$i]\n"; 516 } 517 } 518 519 } 520 521 function printURL($path) 522 { 523 echo "<tr><td>"; 524 $doURL = 1; 525 if ($doURL) { 526 $fileName = basename($path); 527 echo "<a href=\"http:$path\" target=\"_blank\" type=\"image/fits\">"; 528 echo $fileName; 529 echo "</a>"; 530 } else { 531 print "$path"; 532 } 533 echo "</td></tr>"; 534 } 682 // dump parameters 683 684 // phpinfo(32); 535 685 536 686 ?> … … 538 688 </body> 539 689 </form> 690 540 691 </html>
Note:
See TracChangeset
for help on using the changeset viewer.
