Changeset 6705 for branches/1.7/lang/tcl
- Timestamp:
- Jan 4, 2019, 3:14:36 PM (6 years ago)
- Location:
- branches/1.7/lang/tcl/scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.7/lang/tcl/scripts/result.tcl
r3728 r6705 65 65 66 66 if {$status == 0} { 67 puts "=RAPPTURE-RUN=>$oname" 67 set fileName [file join [pwd] $oname] 68 puts "=RAPPTURE-RUN=>$fileName" 68 69 } 69 70 } -
branches/1.7/lang/tcl/scripts/task.tcl
r6702 r6705 26 26 private method GetDriverFile {} 27 27 private method GetSignal { signal } 28 private method GetCacheHelperCommand { driverFile } 28 29 private method GetSimulationCommand { driverFile } 29 30 private method GetUQErrors {} … … 31 32 private method GetUQTemplateFile {} 32 33 private method IsCacheable {} 34 private method IsCacheHelperEligible {} 33 35 private method LogCachedSimulationUsage {} 34 36 private method LogSimulationUsage {} … … 54 56 public method save {xmlobj {name ""}} 55 57 58 protected method OnError {data} 56 59 protected method OnOutput {data} 57 60 protected method Log {args} … … 63 66 private variable _origxml "" ;# copy of original XML (for reset) 64 67 private variable _installdir "" ;# installation directory for this tool 68 private variable _errorcb "" ;# callback for tool error 65 69 private variable _outputcb "" ;# callback for tool output 66 70 private common jobnum 0 ;# counter for unique job number … … 73 77 74 78 public common _resources 75 public proc setAppName {name} { set _resources(-appname) $name } 76 public proc setHubName {name} { set _resources(-hubname) $name } 77 public proc setHubURL {name} { set _resources(-huburl) $name } 78 public proc setSession {name} { set _resources(-session) $name } 79 public proc setJobPrt {name} { set _resources(-jobprotocol) $name } 80 public proc setResultDir {name} { set _resources(-resultdir) $name } 81 public proc setCacheHosts {name} { set _resources(-cachehosts) $name } 79 public proc setAppName {name} { set _resources(-appname) $name } 80 public proc setHubName {name} { set _resources(-hubname) $name } 81 public proc setHubURL {name} { set _resources(-huburl) $name } 82 public proc setSession {name} { set _resources(-session) $name } 83 public proc setJobPrt {name} { set _resources(-jobprotocol) $name } 84 public proc setResultDir {name} { set _resources(-resultdir) $name } 85 public proc setCacheHosts {name} { set _resources(-cachehosts) $name } 86 public proc setCacheUser {name} { set _resources(-cacheuser) $name } 87 public proc setCacheWriteHost {name} { set _resources(-cachewritehost) $name } 82 88 83 89 # default method for -jobstats control … … 95 101 job_protocol Rappture::Task::setJobPrt \ 96 102 results_directory Rappture::Task::setResultDir \ 97 cache_hosts Rappture::Task::setCacheHosts 103 cache_hosts Rappture::Task::setCacheHosts \ 104 cache_user Rappture::Task::setCacheUser \ 105 cache_write_host Rappture::Task::setCacheWriteHost 98 106 } 99 107 … … 208 216 209 217 # if there are any args, use them to override parameters 218 set _errorcb "" 210 219 set _outputcb "" 211 220 set _uq(type) "" … … 214 223 set _uq(paramsFile) "" 215 224 foreach {path val} $args { 216 if {$path == "- output"} {225 if {$path == "-stdout"} { 217 226 set _outputcb $val 227 } elseif {$path == "-stderr"} { 228 set _errorcb $val 218 229 } elseif {$path == "-uq_type"} { 219 230 set _uq(type) $val 220 231 } elseif {$path == "-uq_args"} { 221 232 set _uq(args) $val 222 } else {233 } elseif {$path != "-output"} { 223 234 $_xmlobj put $path.current $val 235 } 236 } 237 foreach {path val} $args { 238 if {$path == "-output"} { 239 if {$_outputcb == ""} { 240 set _outputcb $val 241 } 224 242 } 225 243 } … … 238 256 239 257 SetCpuResourceLimit 258 259 set helperEligible [IsCacheHelperEligible] 260 240 261 set driverFile [GetDriverFile] 241 262 set cached 0 … … 244 265 set cached [CheckForCachedRunFile $driverFile] 245 266 } ]" 246 puts stderr "checking cache =$cached"267 puts stderr "checking cached=$cached" 247 268 } 248 269 if { !$cached } { … … 250 271 set _uq(tFile) [GetUQTemplateFile] 251 272 } 273 global env 252 274 if { $_uq(type) == "" } { 253 set cmd [GetSimulationCommand $driverFile] 254 global env 275 if { $helperEligible } { 276 set cmd [GetCacheHelperCommand $driverFile] 277 } else { 278 set cmd [GetSimulationCommand $driverFile] 279 } 255 280 set ::env(RAPPTURE_UQ) False 256 281 } else { 257 282 set cmd [GetUQSimulationCommand $driverFile] 258 global env259 283 set ::env(RAPPTURE_UQ) True 260 284 } … … 417 441 # use the runfile name generated by the last run 418 442 if {$_job(runfile) ne ""} { 419 set filename [file join $rdir $_job(runfile)]443 set filename [file join $rdir [file tail $_job(runfile)]] 420 444 } else { 421 445 set filename [file join $rdir run.xml] … … 456 480 if {[string length $_outputcb] > 0} { 457 481 uplevel #0 $_outputcb [list $data] 482 } 483 } 484 485 # ---------------------------------------------------------------------- 486 # USAGE: OnError <data> 487 # 488 # Used internally to send each bit of error <data> coming from the 489 # tool onto the caller, so the user can see progress. 490 # ---------------------------------------------------------------------- 491 itcl::body Rappture::Task::OnError {data} { 492 if {[string length $_errorcb] > 0} { 493 uplevel #0 $_errorcb [list $data] 458 494 } 459 495 } … … 504 540 set state [$_xmlobj get "tool.cache"] 505 541 } 506 puts stderr "cache tag is \"$state\"" 507 if { $state == "" || ![string is boolean $state] } { 542 if { $state ne "" } { 543 puts stderr "cache tag is \"$state\"" 544 } 545 if { $state eq "" || ![string is boolean $state] } { 508 546 return 1; # Default is to allow caching. 509 547 } 510 548 return $state 549 } 550 551 itcl::body Rappture::Task::IsCacheHelperEligible {} { 552 global env 553 if { ![info exists env(IONHELPER_ALLOWED)] } { 554 set helperEligible 0 555 } else { 556 if { $env(IONHELPER_ALLOWED) ne "1" } { 557 set helperEligible 0 558 } else { 559 if { $_uq(type) == "" } { 560 # puts stderr "cache_user exists = [info exists _resources(-cacheuser)]" 561 # puts stderr "cache_write_host exists = [info exists _resources(-cachewritehost)]" 562 if { ![info exists _resources(-cacheuser)] || ![info exists _resources(-cachewritehost)] } { 563 set helperEligible 0 564 } else { 565 if { ![info exists env(USER)] } { 566 set helperEligible 0 567 } else { 568 # puts stderr "env(USER) = $env(USER)" 569 # puts stderr "cache_user = $_resources(-cacheuser)" 570 if { $env(USER) eq $_resources(-cacheuser) } { 571 set helperEligible 0 572 } else { 573 set toolId [$_xmlobj get tool.id] 574 set toolVers [$_xmlobj get tool.version.application.revision] 575 set toolDir [$_xmlobj get tool.version.application.directory(top)] 576 set verifyDir [file join / apps ${toolId} r${toolVers}] 577 # puts stderr "toolDir = $toolDir" 578 # puts stderr "verifyDir = $verifyDir" 579 if { $toolDir eq $verifyDir } { 580 if { [ catch { file readlink [file join / apps ${toolId} current] } currentVers ] != 0 } { 581 set helperEligible 0 582 } else { 583 # puts stderr "currentVers = $currentVers" 584 if { "r$toolVers" eq $currentVers } { 585 set helperEligible 1 586 } else { 587 set helperEligible 0 588 } 589 } 590 } else { 591 set helperEligible 0 592 } 593 } 594 } 595 } 596 } else { 597 set helperEligible 0 598 } 599 } 600 } 601 # puts stderr "helperEligible = $helperEligible" 602 603 return $helperEligible 511 604 } 512 605 … … 585 678 } 586 679 680 itcl::body Rappture::Task::GetCacheHelperCommand { driverFile } { 681 set cmd "" 682 set helperDriverDir [file join / var ion drivers] 683 if { [file exists $helperDriverDir] } { 684 set cacheHelperCommand [file join / apps bin iondrive] 685 if { [file exists $cacheHelperCommand] } { 686 file copy -force $driverFile $helperDriverDir 687 set cmd $cacheHelperCommand 688 } 689 } 690 691 return $cmd 692 } 693 587 694 itcl::body Rappture::Task::GetCommand { } { 588 695 set cmd [$_xmlobj get tool.command] … … 681 788 -keepnewline yes \ 682 789 -killsignal SIGTERM \ 790 -onerror [list [itcl::code $this OnError]] \ 683 791 -onoutput [list [itcl::code $this OnOutput]] \ 684 792 -output [list [itcl::scope _job(stdout)]] \ … … 749 857 # Need to save job info? then invoke the callback 750 858 if { [string length $jobstats] > 0} { 751 lappend args \ 752 "job" [incr jobnum] \ 753 "event" $simulation \ 754 "start" $times(start) \ 755 "walltime" $times(walltime) \ 756 "cputime" $times(cputime) \ 757 "status" $_job(exitcode) 859 lappend args "job" [incr jobnum] \ 860 "event" $simulation \ 861 "start" $times(start) \ 862 "walltime" $times(walltime) \ 863 "cputime" $times(cputime) \ 864 "status" $_job(exitcode) 758 865 uplevel #0 $jobstats $args 759 866 } … … 852 959 # [click] messages go here 853 960 if { [string length $jobstats] > 0} { 854 lappend args \ 855 "job" [incr jobnum] \ 856 "event" "\[click\]" \ 857 "start" $times(start) \ 858 "walltime" 0 \ 859 "cputime" 0 \ 860 "status" 0 861 uplevel #0 $jobstats $args 961 set recordJobstats 1 962 if { [info exists _resources(-cacheuser)] } { 963 global env 964 if { $env(USER) eq $_resources(-cacheuser) } { 965 set recordJobstats 0 966 } 967 } 968 if { $recordJobstats } { 969 lappend args "job" [incr jobnum] \ 970 "event" "\[click\]" \ 971 "start" $times(start) \ 972 "walltime" 0 \ 973 "cputime" 0 \ 974 "status" 0 975 uplevel #0 $jobstats $args 976 } 862 977 } 863 978 … … 894 1009 set data(start) [expr { $times(start) + $data(start) }] 895 1010 1011 # puts stderr "event subsimulation start = $data(start)" 1012 896 1013 set details "" 897 1014 foreach key {job event start walltime cputime status} { … … 933 1050 934 1051 if { [string length $jobstats] > 0} { 935 lappend args \ 936 "job" [incr jobnum] \ 937 "event" "\[click-uq\]" \ 938 "start" $times(start) \ 939 "walltime" 0 \ 940 "cputime" 0 \ 941 "status" 0 1052 lappend args "job" [incr jobnum] \ 1053 "event" "\[click-uq\]" \ 1054 "start" $times(start) \ 1055 "walltime" 0 \ 1056 "cputime" 0 \ 1057 "status" 0 942 1058 uplevel #0 $jobstats $args 943 1059 } … … 960 1076 error "Can't create rappture library: $xmlobj" 961 1077 } 962 # Get the session from runfile963 set session [$xmlobj get "output.session"]964 if { [catch {exec submit --cache $session} result] != 0 } {965 puts stderr "submit --cache failed: $result"966 }967 1078 set _job(xmlobj) $xmlobj 968 1079 } … … 981 1092 http::geturl $url -query $query -timeout 6000 -binary yes 982 1093 } token] != 0 } { 983 puts stderr "error performing cache query: token=$token"1094 puts stderr "error performing cache query: driverFile=$driverFile url=$url token=$token" 984 1095 return 0 985 1096 } … … 990 1101 # puts stderr "meta = [::http::meta $token]" 991 1102 1103 set squid "" 992 1104 foreach {key value} [::http::meta $token] { 993 1105 set headers([string tolower $key]) $value 994 1106 if { [string tolower $key] == "etag" } { 995 set guid $value1107 set squid $value 996 1108 } 997 1109 } 998 1110 # puts stderr "SQUID = $headers(etag)" 999 # puts stderr "SQUID = $guid" 1111 # puts stderr "SQUID = $squid" 1112 if { [resources -jobprotocol] == "submit" } { 1113 if { $squid != "" } { 1114 # If the code is 200, we'll assume it's a cache hit. 1115 if { [http::ncode $token] == 200} { 1116 if { [catch {exec submit --cacheHit $squid} result] != 0 } { 1117 puts stderr "submit --cacheHit $squid failed: $result" 1118 } 1119 # puts stderr "submit --cacheHit $squid" 1120 } else { 1121 if { [catch {exec submit --cacheMiss $squid} result] != 0 } { 1122 puts stderr "submit --cacheMiss $squid failed: $result" 1123 } 1124 # puts stderr "submit --cacheMiss $squid" 1125 } 1126 } else { 1127 puts stderr "cache squid could not be determined." 1128 } 1129 } 1000 1130 1001 1131 # If the code isn't 200, we'll assume it's a cache miss.
Note: See TracChangeset
for help on using the changeset viewer.