Changeset 28980 for branches/eam_branches/ipp-20100621/tools/czartool
- Timestamp:
- Aug 19, 2010, 6:50:13 PM (16 years ago)
- Location:
- branches/eam_branches/ipp-20100621/tools/czartool
- Files:
-
- 4 edited
- 1 copied
-
CzarDb.pm (modified) (9 diffs)
-
Czarplot.pm (modified) (7 diffs)
-
Gpc1Db.pm (modified) (6 diffs)
-
Nebulous.pm (copied) (copied from trunk/tools/czartool/Nebulous.pm )
-
Pantasks.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/tools/czartool/CzarDb.pm
r28794 r28980 16 16 17 17 # Call the constructor of the parent class, Person. 18 my $self = $class->SUPER::new( $_[1], $_[2], $_[3], $_[4], $_[5], $_[6]);18 my $self = $class->SUPER::new($_[1], $_[2], $_[3], $_[4], $_[5], $_[6]); 19 19 20 20 bless $self, $class; … … 66 66 67 67 $query->execute; 68 } 69 70 ########################################################################### 71 # 72 # Gets revert status for this stage 73 # 74 ########################################################################### 75 sub getRevertStatus { 76 my ($self, $stage, $reverting) = @_; 77 78 my $query = $self->{_db}->prepare(<<SQL); 79 SELECT reverting 80 FROM reverts 81 WHERE stage LIKE '$stage'; 82 SQL 83 84 $query->execute; 85 return scalar $query->fetchrow_array(); 86 } 87 88 ########################################################################### 89 # 90 # Updates revert status for this stage 91 # 92 ########################################################################### 93 sub updateRevertStatus { 94 my ($self, $stage, $reverting) = @_; 95 96 my $query = $self->{_db}->prepare(<<SQL); 97 UPDATE reverts 98 SET reverting = $reverting 99 WHERE stage LIKE '$stage'; 100 SQL 101 102 $query->execute; 68 103 } 69 104 … … 117 152 } 118 153 } 154 155 ########################################################################### 156 # 157 # Updates hosts table 158 # 159 ########################################################################### 160 sub updateHost { 161 my ($self, $host, $total, $available, $used, $readable, $writable) = @_; 162 163 my $query = $self->{_db}->prepare(<<SQL); 164 DELETE FROM hosts WHERE host LIKE '$host'; 165 SQL 166 167 $query->execute; 168 $query = $self->{_db}->prepare(<<SQL); 169 INSERT INTO hosts 170 (host, total, available, used, readable, writable) 171 VALUES 172 ('$host', $total, $available, $used, $readable, $writable); 173 SQL 174 $query->execute; 175 176 } 177 178 ########################################################################### 179 # 180 # Inserts new cluster space info 181 # 182 ########################################################################### 183 sub insertNewClusterSpace { 184 my ($self, $total, $available, $used, $hostsOver98) = @_; 185 186 my $query = $self->{_db}->prepare(<<SQL); 187 INSERT INTO cluster_space 188 (total, available, used, hostsOver98) 189 VALUES 190 ( $total, $available, $used, $hostsOver98); 191 SQL 192 193 $query->execute; 194 } 195 119 196 ########################################################################### 120 197 # … … 123 200 ########################################################################### 124 201 sub insertNewTimeData { 125 my ($self, $stage, $label, $pending, $processed, $faults , $reverting) = @_;202 my ($self, $stage, $label, $pending, $processed, $faults) = @_; 126 203 127 204 my $query = $self->{_db}->prepare(<<SQL); 128 205 INSERT INTO $stage 129 (label, pending, processed, faults , reverting)206 (label, pending, processed, faults) 130 207 VALUES 131 ('$label', $pending, $processed, $faults , $reverting);208 ('$label', $pending, $processed, $faults); 132 209 SQL 133 210 … … 158 235 SQL 159 236 160 161 162 237 if (!$query->execute) {return undef;} 163 238 164 my $minProcessed ;239 my $minProcessed = undef; 165 240 166 241 ($minProcessed, ${$maxY}, ${$minY}, ${$maxX}, ${$minX}, ${$timeDiff}) = $query->fetchrow_array(); 167 242 168 if (! $minProcessed) {return undef;}243 if (!defined $minProcessed) {return undef;} 169 244 170 245 $query = $self->{_db}->prepare(<<SQL); … … 273 348 ########################################################################### 274 349 # 350 # Gets host data and stores it to temp file 351 # 352 ########################################################################### 353 sub createHostsData { 354 my ($self, $limit) = @_; 355 356 my $dataFile = "/tmp/czarplot_hosts_space.dat"; 357 open (GNUDAT, ">$dataFile"); 358 359 my $query = $self->{_db}->prepare(<<SQL); 360 SELECT 361 host, used, available, writable, readable 362 FROM hosts 363 ORDER BY host; 364 SQL 365 366 $query->execute; 367 368 my $underLimit; 369 370 # loop round results 371 while (my @row = $query->fetchrow_array()) { 372 373 my ($host, $used, $available, $writable, $readable) = @row; 374 375 if (($used/($used+$available))*100 > $limit) {$underLimit = 0;} 376 else {$underLimit = 1;} 377 378 # Col 1: host 379 print GNUDAT "$host"; 380 381 # Col 2: available, readable used space under limit 382 if ($readable && $underLimit) {print GNUDAT " $used";} 383 else {print GNUDAT " 0";} 384 385 # Col 3: available, readable used space OVER limit 386 if ($readable && !$underLimit) {print GNUDAT " $used";} 387 else {print GNUDAT " 0";} 388 389 # Col 4: NOT available used space 390 if (!$readable) {print GNUDAT " $used";} 391 else {print GNUDAT " 0";} 392 393 # Col 5: available writable space 394 if($writable) {print GNUDAT " $available";} 395 else {print GNUDAT " 0";} 396 397 # Col 6: NOT available writable space 398 if(!$writable) {print GNUDAT " $available";} 399 else {print GNUDAT " 0";} 400 401 print GNUDAT "\n"; 402 } 403 close(GNUDAT); 404 405 return $dataFile; 406 } 407 408 ########################################################################### 409 # 410 # Gets total used cluster space as a percentage 411 # 412 ############################################################################ 413 sub getTotalClusterStorageAsPercentage { 414 my ($self) = @_; 415 416 my $query = $self->{_db}->prepare(<<SQL); 417 SELECT used/total*100 418 FROM cluster_space 419 ORDER BY timestamp DESC LIMIT 1; 420 SQL 421 $query->execute; 422 return scalar $query->fetchrow_array(); 423 } 424 425 ########################################################################### 426 # 427 # Gets time series data for cluster storage and saves it to file 428 # 429 ########################################################################### 430 sub createStorageTimeSeriesData { 431 my ($self, $fromTime, $toTime, $minX, $maxX, $minY, $maxY, $timeDiff) = @_; 432 433 my $dataFile = "/tmp/czarplot_gnuplot_storage_timeseries.dat"; 434 open (GNUDAT, ">$dataFile"); 435 436 my $query = $self->{_db}->prepare(<<SQL); 437 SELECT 438 MAX(available), MIN(available), 439 DATE_FORMAT(MAX(timestamp),'$self->{_dateFormat}'), 440 DATE_FORMAT(MIN(timestamp),'$self->{_dateFormat}'), 441 TIME_TO_SEC(TIMEDIFF(max(timestamp ), min(timestamp))) 442 FROM cluster_space 443 WHERE timestamp >= '$fromTime' AND timestamp <= '$toTime'; 444 SQL 445 446 447 if (!$query->execute) {return undef;} 448 449 (${$maxY}, ${$minY}, ${$maxX}, ${$minX}, ${$timeDiff}) = $query->fetchrow_array(); 450 451 452 $query = $self->{_db}->prepare(<<SQL); 453 SELECT 454 DATE_FORMAT(timestamp, '$self->{_dateFormat}'), available 455 FROM cluster_space 456 WHERE timestamp >= '$fromTime' AND timestamp <= '$toTime' 457 ORDER BY timestamp; 458 SQL 459 460 $query->execute; 461 462 # loop round results 463 while (my @row = $query->fetchrow_array()) { 464 465 my ($timestamp, $available) = @row; 466 print GNUDAT "$timestamp $available\n"; 467 } 468 close(GNUDAT); 469 470 return $dataFile; 471 } 472 ########################################################################### 473 # 275 474 # Determines how much has been processed in the provided interval of time 276 475 # (format: 1 HOUR, 1 MINUTE 1 DAY etc) … … 301 500 302 501 my $currentRevision = -1; 303 my $latestRevision = 7;502 my $latestRevision = 10; 304 503 305 504 while ($currentRevision != $latestRevision) { … … 315 514 elsif ($currentRevision == 5) {$self->createRevision_6();} 316 515 elsif ($currentRevision == 6) {$self->createRevision_7();} 317 } 516 elsif ($currentRevision == 7) {$self->createRevision_8();} 517 elsif ($currentRevision == 8) {$self->createRevision_9();} 518 elsif ($currentRevision == 9) {$self->createRevision_10();} 519 } 520 } 521 522 ####################################################################################### 523 # 524 # Sets current revision of ippToPsps database 525 # 526 ####################################################################################### 527 sub setRevision { 528 my ($self, $revision) = @_; 529 530 my $query = $self->{_db}->prepare(<<SQL); 531 INSERT INTO revision (revision) VALUES ($revision); 532 SQL 533 $query->execute; 534 } 535 536 ####################################################################################### 537 # 538 # Gets current revision of ippToPsps database 539 # 540 ####################################################################################### 541 sub getRevision { 542 my ($self) = @_; 543 544 if (!$self->SUPER::doesTableExist("revision")) {return 0;} 545 546 my $query = $self->{_db}->prepare(<<SQL); 547 SELECT revision 548 FROM revision 549 ORDER BY revision DESC LIMIT 1; 550 SQL 551 552 $query->execute; 553 my @row = $query->fetchrow_array(); 554 555 return $row[0]; 318 556 } 319 557 … … 500 738 ####################################################################################### 501 739 # 502 # Sets current revision of ippToPsps database 503 # 504 ####################################################################################### 505 sub setRevision { 506 my ($self, $revision) = @_; 507 508 my $query = $self->{_db}->prepare(<<SQL); 509 INSERT INTO revision (revision) VALUES ($revision); 510 SQL 511 $query->execute; 512 } 513 514 ####################################################################################### 515 # 516 # Gets current revision of ippToPsps database 517 # 518 ####################################################################################### 519 sub getRevision { 520 my ($self) = @_; 521 522 if (!$self->SUPER::doesTableExist("revision")) {return 0;} 523 524 my $query = $self->{_db}->prepare(<<SQL); 525 SELECT revision 526 FROM revision 527 ORDER BY revision DESC LIMIT 1; 528 SQL 529 530 $query->execute; 531 my @row = $query->fetchrow_array(); 532 533 return $row[0]; 740 # Create revision 8 of the database 741 # 742 ####################################################################################### 743 sub createRevision_8 { 744 my ($self) = @_; 745 746 print "* Creating revision 8 of '$self->{_dbName}'\n"; 747 748 # drop reverting column from all stages tables 749 my $stage = undef; 750 foreach $stage (@stages) { 751 752 my $query = $self->{_db}->prepare(<<SQL); 753 ALTER TABLE $stage 754 DROP COLUMN reverting; 755 SQL 756 757 $query->execute; 758 } 759 760 # create new 'revert' table 761 my $query = $self->{_db}->prepare(<<SQL); 762 CREATE TABLE reverts ( 763 stage VARCHAR(128), 764 reverting TINYINT); 765 SQL 766 767 $query->execute; 768 769 # insert stages into revert table 770 foreach $stage (@stages) { 771 my $query = $self->{_db}->prepare(<<SQL); 772 INSERT INTO reverts 773 (stage, reverting) 774 VALUES 775 ('$stage', 0); 776 SQL 777 $query->execute; 778 } 779 780 $self->setRevision(8); 781 } 782 783 ####################################################################################### 784 # 785 # Create revision 9 of the database 786 # 787 ####################################################################################### 788 sub createRevision_9 { 789 my ($self) = @_; 790 791 print "* Creating revision 9 of '$self->{_dbName}'\n"; 792 793 my $query = $self->{_db}->prepare(<<SQL); 794 CREATE TABLE cluster_space ( 795 timestamp TIMESTAMP DEFAULT NOW(), 796 total FLOAT, 797 available FLOAT, 798 used FLOAT, 799 hostsOver98 SMALLINT); 800 SQL 801 802 $query->execute; 803 $query = $self->{_db}->prepare(<<SQL); 804 CREATE TABLE hosts ( 805 host VARCHAR(128), 806 total FLOAT, 807 available FLOAT, 808 used FLOAT); 809 SQL 810 811 $query->execute; 812 813 $query = $self->{_db}->prepare(<<SQL); 814 CREATE INDEX clusterSpaceIndex ON cluster_space (timestamp); 815 SQL 816 817 $query->execute; 818 819 $self->setRevision(9); 820 } 821 822 ####################################################################################### 823 # 824 # Create revision 10 of the database 825 # 826 ####################################################################################### 827 sub createRevision_10 { 828 my ($self) = @_; 829 830 print "* Creating revision 10 of '$self->{_dbName}'\n"; 831 832 my $query = $self->{_db}->prepare(<<SQL); 833 ALTER TABLE hosts 834 ADD COLUMN writable TINYINT NOT NULL DEFAULT 0, 835 ADD COLUMN readable TINYINT NOT NULL DEFAULT 0; 836 SQL 837 838 $query->execute; 839 840 $self->setRevision(10); 534 841 } 535 842 -
branches/eam_branches/ipp-20100621/tools/czartool/Czarplot.pm
r28794 r28980 154 154 my ($self, $minY, $maxY) = @_; 155 155 156 ${$maxY} = ${$maxY} + (${$maxY}/10); 157 ${$minY} = ${$minY} - (${$minY}/10); 156 my $tmp; 157 if (${$maxY} < ${$minY}) { 158 159 $tmp = ${$maxY}; 160 ${$maxY} = ${$minY}; 161 ${$minY} = $tmp; 162 } 163 164 my $border = (${$maxY} - ${$minY})/10; 165 166 ${$maxY} += $border; 167 ${$minY} -= $border ; 158 168 if (${$maxY} == 0) {${$maxY} = 1;} 159 169 if (${$minY} == 0) {${$minY} = -1;} 160 170 } 161 171 172 173 ########################################################################### 174 # 175 # Figures out suitable spacing for time tics on time-series pliots 176 # 177 ########################################################################### 178 sub getTimeSpacing { 179 my ($self, $timeDiff, $divX, $timeFormat) = @_; 180 181 # if less than a couple of hour's data plotted, show 30 mins tics 182 if ($timeDiff < 7200) { 183 ${$timeFormat} = "%H:%M"; 184 ${$divX} = 1800; 185 } 186 # if less than half a day's data plotted, show hourly tics 187 elsif ($timeDiff < 43200) { 188 ${$timeFormat} = "%H:%M"; 189 ${$divX} = 3600; 190 } 191 # if less than one day's data plotted, show 2 hourly tics 192 elsif ($timeDiff < 86400) { 193 ${$timeFormat} = "%H:%M"; 194 ${$divX} = 7200; 195 } 196 # if less than 1 week's data is data plotted, show daily tics 197 elsif ($timeDiff < 604800) { 198 199 ${$timeFormat} = "%m/%d"; 200 ${$divX} = 86400; 201 } 202 else { 203 204 ${$timeFormat} = "%m/%d"; 205 ${$divX} = 172800; 206 } 207 } 208 162 209 ########################################################################### 163 210 # … … 171 218 172 219 my $timeFormat = undef; 173 174 my $divX = $timeDiff/4; 175 176 # if less than a couple of hour's data plotted, show 30 mins tics 177 if ($timeDiff < 7200) { 178 $timeFormat = "%H:%M"; 179 $divX = 1800; 180 } 181 # if less than half a day's data plotted, show hourly tics 182 elsif ($timeDiff < 43200) { 183 $timeFormat = "%H:%M"; 184 $divX = 3600; 185 } 186 # if less than one day's data plotted, show 2 hourly tics 187 elsif ($timeDiff < 86400) { 188 $timeFormat = "%H:%M"; 189 $divX = 7200; 190 } 191 # if more than one day's data plotted, show daily tics 192 else { 193 194 $timeFormat = "%m/%d %H:%M"; 195 $divX = 86400; 196 } 220 my $divX = undef; 221 222 $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat); 197 223 198 224 my $numOfPlots = keys %$gnuplotFiles; 225 my $title = undef; 226 227 # sort out plot title 228 if ($numOfPlots == 1) {foreach my $stage (keys %$gnuplotFiles) {$title = "'".$stage."'";}} 229 else {$title = "'All stages'"} 230 231 $title .= " for '$label', '$fromTime' to '$toTime'"; 199 232 200 233 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; … … 205 238 "set term $self->{_outputFormat};" . 206 239 "set output \"$outputFile\";" . 207 "set title \" All stages for '$label' since $fromTime\";" .240 "set title \"$title\";" . 208 241 "set key left top;" . 209 242 "set xdata time;" . 210 243 "set timefmt \"$self->{_dateFormat}\";" . 244 # "set yrange [\"$minY\":\"$maxY\"];" . 211 245 "set xrange [\"$minX\":\"$maxX\"];" . 212 246 "set format x \"$timeFormat\";" . … … 224 258 if ($numOfPlots == 1) { 225 259 226 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \" processed\" with lines lt 2,";227 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:2 title \" pending\" with lines lt 3,";228 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:3 title \" faults\" with lines lt 1";260 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:4 title \"Processed\" with lines lt 2,"; 261 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:2 title \"Pending\" with lines lt 4,"; 262 print GP "'" . $gnuplotFiles->{$stage} . "' using 1:3 title \"Faults\" with lines lt 7"; 229 263 } 230 264 # when plotting multiple stages, show only processed … … 241 275 ########################################################################### 242 276 # 243 # Plots a histogram of processed stuff 244 # 245 ########################################################################### 246 sub plotHistogram { 247 my ($self, $inputFile, $outputFile, $label, $fromTime, $toTime) = @_; 277 # Plots a time-series of cluster storage 278 # 279 ########################################################################### 280 sub plotStorageTimeSeries { 281 my ($self, $fromTime, $toTime) = @_; 282 283 my $prefix = $self->{_outputPath} ? $self->{_outputPath} : "."; 284 my $outputFile = "$prefix/czarplot_cluster.png"; 285 my ($minX, $maxX, $minY, $maxY, $timeDiff); 286 287 my $gnuplotFile = $self->{_czarDb}->createStorageTimeSeriesData($fromTime, $toTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff); 288 289 $self->sortOutMaxMinY(\$minY, \$maxY); 290 291 my $timeFormat = undef; 292 my $divX = undef; 293 294 $self->getTimeSpacing($timeDiff, \$divX, \$timeFormat); 248 295 249 296 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; … … 254 301 "set term $self->{_outputFormat};" . 255 302 "set output \"$outputFile\";" . 256 "set title \"Processing status for '$label' since $fromTime\";" . 303 "set title \"Total available cluster space over time\";" . 304 "set key left top;" . 305 "set xdata time;" . 306 "set timefmt \"$self->{_dateFormat}\";" . 307 "set xrange [\"$minX\":\"$maxX\"];" . 308 "set yrange [\"$minY\":\"$maxY\"];" . 309 "set format x \"$timeFormat\";" . 310 "set xtics \"$minX\", $divX, \"$maxX\";" . 311 "set grid xtics;" . 312 "set xlabel \"Time\";" . 313 "set ylabel \"Available (TB)\";" . 314 "plot " . 315 # "'$gnuplotFile' using 1:2 title \"Total\" with lines lt 1," . 316 "'$gnuplotFile' using 1:2 title \"Available\" with lines lt 2\n"; 317 318 print GP "\n"; 319 close GP; 320 } 321 322 ########################################################################### 323 # 324 # Plots a histogram of processed stuff 325 # 326 ########################################################################### 327 sub plotHistogram { 328 my ($self, $inputFile, $outputFile, $label, $fromTime, $toTime) = @_; 329 330 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; 331 use FileHandle; 332 GP->autoflush(1); 333 334 print GP 335 "set term $self->{_outputFormat};" . 336 "set output \"$outputFile\";" . 337 "set title \"'$label', '$fromTime' to '$toTime'\";" . 257 338 "set grid;" . 258 339 "set boxwidth;" . … … 262 343 "set bmargin 5;" . 263 344 "set ylabel \"Exposures\";" . 264 "plot '$inputFile' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 3, '' using 4 title \"Faults\" lt 1\n"; 345 "plot '$inputFile' using 2:xtic(1) title \"Processed\" lt 2, '' using 3 title \"Pending\" lt 4, '' using 4 title \"Faults\" lt 7;" . 346 "\n"; 265 347 266 348 close GP; 267 349 } 268 350 351 ########################################################################### 352 # 353 # Plots disk usage across cluster as a stacked histogram 354 # 355 ########################################################################### 356 sub plotDiskUsageHistogram { 357 my ($self) = @_; 358 359 my $prefix = $self->{_outputPath} ? $self->{_outputPath} : "."; # TODO should be function for this 360 my $outputFile = "$prefix/czarplot_hosts_space.png"; 361 my $limit = 97.0; 362 my $inputFile = $self->{_czarDb}->createHostsData($limit); 363 364 my $totalUsed = $self->{_czarDb}->getTotalClusterStorageAsPercentage(); 365 366 my $totalPercent = sprintf("%.1f%%", $totalUsed); 367 368 open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot"; 369 use FileHandle; 370 GP->autoflush(1); 371 372 print GP 373 "set term $self->{_outputFormat};" . 374 "set output \"$outputFile\";" . 375 "set title \"Nebulous disk use across IPP cluster ($totalPercent of total allocated)\";" . 376 "set style fill solid 1.00 border -1;" . 377 "set style histogram rowstacked;" . 378 "set style data histograms;" . 379 "set ylabel \"Space (TB)\";" . 380 "set xtic rotate by -90 scale 0;" . 381 "plot '$inputFile' " . 382 "using 2:xtic(1) t \"Used\" lt 7," . 383 "'' using 3 t \"Over $limit% used\" lt 1," . 384 "'' using 4 t \"Unavailable\" fs solid 0.50 lt -1 ," . 385 "'' using 5 t \"Free\" lt 2," . 386 "'' using 6 notitle fs solid 0.50 lt -1" . 387 ";" . 388 389 "\n"; 390 391 close GP; 392 } 269 393 1; -
branches/eam_branches/ipp-20100621/tools/czartool/Gpc1Db.pm
r28794 r28980 8 8 use czartool::MySQLDb; 9 9 our @ISA = qw(czartool::MySQLDb); # inherits from MySQLDb 10 11 ########################################################################### 12 # 13 # Returns the right join table and ID to join on for for a given stage TODO make private 14 # 15 ########################################################################### 16 sub getJoinTableAndId { 17 my ($self, $stage, $joinTable, $id) = @_; 18 19 ${$id} = $stage."_id"; 20 21 if ($stage eq "chip") {${$joinTable}="chipProcessedImfile";} 22 elsif ($stage eq "cam") {${$joinTable}="camProcessedExp";} 23 elsif ($stage eq "fake") {${$joinTable}="fakeProcessedImfile";} 24 elsif ($stage eq "warp") {${$joinTable}="warpSkyfile";} 25 elsif ($stage eq "stack") {${$joinTable}="stackSumSkyfile";} 26 elsif ($stage eq "diff") {${$joinTable}="diffSkyfile";} 27 elsif ($stage eq "magic") {${$joinTable}="magicNodeResult";} 28 elsif ($stage eq "magicDS") {${$id} = "magic_ds_id"; ${$joinTable}="magicDSFile";} 29 elsif ($stage eq "dist") {${$joinTable}="distComponent";} 30 else { 31 32 print "* ERROR: could nod find joinTable and ID for '$stage' stage\n"; 33 return 0; 34 } 35 36 return 1; 37 } 10 38 11 39 ########################################################################### … … 30 58 } 31 59 32 33 60 ########################################################################### 34 61 # … … 37 64 ########################################################################### 38 65 sub countFaults { 39 my ($self, $label, $stage ) = @_;66 my ($self, $label, $stage, $state) = @_; 40 67 41 42 my $table = getTableForStage($self, $stage); 43 my $joinTable; 44 my $id = $stage."_id"; 45 46 if ($stage eq "chip") {$joinTable="chipProcessedImfile";} 47 elsif ($stage eq "cam") {$joinTable="camProcessedExp";} 48 elsif ($stage eq "fake") {$joinTable="fakeProcessedImfile";} 49 elsif ($stage eq "warp") {$joinTable="warpSkyfile";} 50 elsif ($stage eq "stack") {$joinTable="stackSumSkyfile";} 51 elsif ($stage eq "diff") {$joinTable="diffSkyfile";} 52 elsif ($stage eq "magic") {$joinTable="magicNodeResult";} 53 elsif ($stage eq "magicDS") {$id = "magic_ds_id"; $joinTable="magicDSFile";} 54 elsif ($stage eq "dist") {$joinTable="distComponent";} 55 else {return -1;} 68 my $table = undef; 69 my $joinTable = undef; 70 my $id = undef; 71 $table = getTableForStage($self, $stage); 72 if (!getJoinTableAndId($self, $stage, \$joinTable, \$id)) {return -1;} 56 73 57 74 my $faultCol = $joinTable.".fault"; … … 64 81 WHERE label LIKE '$label' 65 82 AND $faultCol != 0 66 AND $stateCol = ' new'83 AND $stateCol = '$state' 67 84 SQL 68 85 … … 85 102 SQL 86 103 87 $query->execute;104 $query->execute; 88 105 my $priority = scalar $query->fetchrow_array(); 89 106 if (!$priority) {return 50000;} # assume labels not given priority in gpc1 Db have highest priority … … 100 117 101 118 my $table = getTableForStage($self, $stage); 102 if ($state eq "fault") {return countFaults($stage);} 119 my $query = undef; 120 121 if ($state eq "update") { 122 123 if ($stage eq "dist") {return 0;} 124 my $joinTable = undef; 125 my $id = undef; 126 if (!getJoinTableAndId($self, $stage, \$joinTable, \$id)) {return -1;} 127 128 if ($stage eq "chip" || $stage eq "fake" || $stage eq "warp" || $stage eq "diff" || $stage eq "magicDS") { 129 $query = $self->{_db}->prepare(<<SQL); 130 SELECT COUNT(state) 131 FROM $table JOIN $joinTable 132 USING($id) 133 WHERE label LIKE '$label' 134 AND state = 'update' 135 AND data_state = 'update'; 136 SQL 137 } 138 else { 139 140 $query = $self->{_db}->prepare(<<SQL); 141 SELECT COUNT(state) 142 FROM $table JOIN $joinTable 143 USING($id) 144 WHERE label LIKE '$label' 145 AND state = 'update'; 146 SQL 147 } 148 149 } 150 else { 151 152 $query = $self->{_db}->prepare(<<SQL); 153 SELECT COUNT(state) 154 FROM $table 155 WHERE label LIKE '$label' 156 AND state = '$state' 157 SQL 158 } 103 159 104 160 105 my $query = $self->{_db}->prepare(<<SQL); 106 SELECT count(state) 107 FROM $table 108 WHERE label LIKE '$label' 109 AND state = '$state' 110 SQL 111 112 $query->execute; 161 $query->execute; 113 162 return scalar $query->fetchrow_array(); 114 163 } -
branches/eam_branches/ipp-20100621/tools/czartool/Pantasks.pm
r28794 r28980 5 5 6 6 package czartool::Pantasks; 7 8 7 9 8 my @servers = ( … … 21 20 ); 22 21 22 ########################################################################### 23 # 24 # Constructor TODO put in check that we can run pantasks_client 25 # 26 ########################################################################### 27 sub new { 28 my $class = shift; 29 my $self = {}; 30 31 bless $self, $class; 32 return $self; 33 } 23 34 24 35 ########################################################################### … … 35 46 ########################################################################### 36 47 # 37 # Constructor38 #39 ###########################################################################40 sub new {41 my $class = shift;42 my $self = {};43 44 bless $self, $class;45 return $self;46 }47 48 ###########################################################################49 #50 48 # Returns the correct server for this processing stage 51 49 # … … 58 56 } 59 57 58 ########################################################################### 59 # 60 # Checks for a meaningful response from pantasks client 61 # 62 ########################################################################### 63 sub outputOk { 64 my ($self, $output) = @_; 65 66 if ( 67 $output =~ m/.*show\.labels.*/i || 68 $output =~ m/.*Connection reset by peer.*/i || 69 $output =~ m/.*server is busy.*/i ) { 70 71 print "* WARNING: pantasks returned '$output'\n"; 72 return 0; 73 } 74 return 1; 75 } 60 76 61 77 ########################################################################### … … 75 91 76 92 chomp($line); 77 if ($line =~ m/pantasks:\s+(.*)/) { 78 79 # HACK quit if we get 'show.labels: Command not found.' 80 if ($1 =~ m/.*show\.labels.*/i) {return \@labels;}; 81 # HACK quit if we get 'Connection reset by peer' 82 if ($1 =~ m/.*Connection reset by peer.*/i) {return \@labels;}; 83 # HACK quit if we get 'server is busy' message 84 if ($1 =~ m/.*server is busy.*/i) {return \@labels;}; 85 # HACK to get around 'dummy' label in stdscience 86 if ($1 !~ m/.*dummy.*/) {push(@labels, $1);}; 87 $passedHeader=1; 88 next; 89 } 90 93 if (!$self->outputOk($line)) {return \@labels;} 94 if ($line =~ m/pantasks:\s+/) {$passedHeader=1; next;} 91 95 if ($passedHeader) {push(@labels, $line);} 92 96 } … … 113 117 if ($line =~ m/Scheduler is running/) {${$running} = 1; ${$alive}=1;last;} 114 118 if ($line =~ m/Task Status/) {last;} 115 116 119 } 117 120 } … … 125 128 my ($self, $server) = @_; 126 129 130 my @cmdOut = `echo "status;quit" | pantasks_client -c ~ipp/$server/ptolemy.rc 2>&1`; 131 my $line; 132 my $passedHeader=0; 133 print "\n"; 134 foreach $line (@cmdOut) { 135 136 if ($line =~ m/.*Task Status.*/) {$passedHeader=1;next;} 137 if ($passedHeader){print "$line";} 138 } 139 } 140 141 ########################################################################### 142 # 143 # Gets revert status for this stage 144 # 145 ########################################################################### 146 sub getRevertStatus { 147 my ($self, $stage, $reverting) = @_; 148 149 my $server = $self->getServerForThisStage($stage); 150 151 if ($stage eq "cam") {$stage = "camera";} 127 152 128 153 my @cmdOut = `echo "status;quit" | pantasks_client -c ~ipp/$server/ptolemy.rc 2>&1`; 129 154 my $line; 130 my $passedHeader=0;131 155 foreach $line (@cmdOut) { 132 156 133 157 chomp($line); 134 if ($line =~ m/.*Task Status.*/) {$passedHeader=1;next;} 135 if ($passedHeader){print "$line<br>";} 158 if ($line =~ m/\s+([+-])[+-]\s+$stage\.revert.*/) { 159 160 if ($1 =~ m/-/) {${$reverting} = 0;} 161 elsif ($1 =~ m/\+/) {${$reverting}=1;} 162 } 136 163 } 137 164 } 138 139 165 1;
Note:
See TracChangeset
for help on using the changeset viewer.
