Changeset 6705 for branches/1.7/lang/tcl


Ignore:
Timestamp:
Jan 4, 2019, 3:14:36 PM (6 years ago)
Author:
clarksm
Message:

Enable "ionhelper" to execute jobs and immediately put results in cache.
This includes reporting run.xml location with absolute path.

Location:
branches/1.7/lang/tcl/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.7/lang/tcl/scripts/result.tcl

    r3728 r6705  
    6565
    6666    if {$status == 0} {
    67         puts "=RAPPTURE-RUN=>$oname"
     67        set fileName [file join [pwd] $oname]
     68        puts "=RAPPTURE-RUN=>$fileName"
    6869    }
    6970}
  • branches/1.7/lang/tcl/scripts/task.tcl

    r6702 r6705  
    2626    private method GetDriverFile {}
    2727    private method GetSignal { signal }
     28    private method GetCacheHelperCommand { driverFile }
    2829    private method GetSimulationCommand { driverFile }
    2930    private method GetUQErrors {}
     
    3132    private method GetUQTemplateFile {}
    3233    private method IsCacheable {}
     34    private method IsCacheHelperEligible {}
    3335    private method LogCachedSimulationUsage {}
    3436    private method LogSimulationUsage {}
     
    5456    public method save {xmlobj {name ""}}
    5557
     58    protected method OnError {data}
    5659    protected method OnOutput {data}
    5760    protected method Log {args}
     
    6366    private variable _origxml ""     ;# copy of original XML (for reset)
    6467    private variable _installdir ""  ;# installation directory for this tool
     68    private variable _errorcb ""     ;# callback for tool error
    6569    private variable _outputcb ""    ;# callback for tool output
    6670    private common jobnum 0          ;# counter for unique job number
     
    7377
    7478    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 }
    8288
    8389    # default method for -jobstats control
     
    95101        job_protocol      Rappture::Task::setJobPrt \
    96102        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
    98106}
    99107
     
    208216
    209217    # if there are any args, use them to override parameters
     218    set _errorcb ""
    210219    set _outputcb ""
    211220    set _uq(type) ""
     
    214223    set _uq(paramsFile) ""
    215224    foreach {path val} $args {
    216         if {$path == "-output"} {
     225        if {$path == "-stdout"} {
    217226            set _outputcb $val
     227        } elseif {$path == "-stderr"} {
     228            set _errorcb $val
    218229        } elseif {$path == "-uq_type"} {
    219230            set _uq(type) $val
    220231        } elseif {$path == "-uq_args"} {
    221232            set _uq(args) $val
    222         } else {
     233        } elseif {$path != "-output"} {
    223234            $_xmlobj put $path.current $val
     235        }
     236    }
     237    foreach {path val} $args {
     238        if {$path == "-output"} {
     239            if {$_outputcb == ""} {
     240                set _outputcb $val
     241            }
    224242        }
    225243    }
     
    238256
    239257    SetCpuResourceLimit
     258
     259    set helperEligible [IsCacheHelperEligible]
     260
    240261    set driverFile [GetDriverFile]
    241262    set cached 0
     
    244265        set cached [CheckForCachedRunFile $driverFile]
    245266     } ]"
    246 puts stderr "checking cache=$cached"
     267puts stderr "checking cached=$cached"
    247268    }
    248269    if { !$cached } {
     
    250271            set _uq(tFile) [GetUQTemplateFile]
    251272        }
     273        global env
    252274        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            }
    255280            set ::env(RAPPTURE_UQ) False
    256281        } else {
    257282            set cmd [GetUQSimulationCommand $driverFile]
    258             global env
    259283            set ::env(RAPPTURE_UQ) True
    260284        }
     
    417441        # use the runfile name generated by the last run
    418442        if {$_job(runfile) ne ""} {
    419             set filename [file join $rdir $_job(runfile)]
     443            set filename [file join $rdir [file tail $_job(runfile)]]
    420444        } else {
    421445            set filename [file join $rdir run.xml]
     
    456480    if {[string length $_outputcb] > 0} {
    457481        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# ----------------------------------------------------------------------
     491itcl::body Rappture::Task::OnError {data} {
     492    if {[string length $_errorcb] > 0} {
     493        uplevel #0 $_errorcb [list $data]
    458494    }
    459495}
     
    504540        set state [$_xmlobj get "tool.cache"]
    505541    }
    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] } {
    508546        return 1;                       # Default is to allow caching.
    509547    }
    510548    return $state
     549}
     550
     551itcl::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
    511604}
    512605
     
    585678}
    586679
     680itcl::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
    587694itcl::body Rappture::Task::GetCommand { } {
    588695    set cmd [$_xmlobj get tool.command]
     
    681788            -keepnewline yes \
    682789            -killsignal  SIGTERM \
     790            -onerror     [list [itcl::code $this OnError]] \
    683791            -onoutput    [list [itcl::code $this OnOutput]] \
    684792            -output      [list [itcl::scope _job(stdout)]] \
     
    749857    # Need to save job info? then invoke the callback
    750858    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)
    758865        uplevel #0 $jobstats $args
    759866    }
     
    852959# [click] messages go here
    853960    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        }
    862977    }
    863978
     
    8941009        set data(start) [expr { $times(start) + $data(start) }]
    8951010
     1011#       puts stderr "event subsimulation start = $data(start)"
     1012
    8961013        set details ""
    8971014        foreach key {job event start walltime cputime status} {
     
    9331050
    9341051    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
    9421058        uplevel #0 $jobstats $args
    9431059    }
     
    9601076        error "Can't create rappture library: $xmlobj"
    9611077    }
    962     # Get the session from runfile
    963     set session [$xmlobj get "output.session"]
    964     if { [catch {exec submit --cache $session} result] != 0 } {
    965        puts stderr "submit --cache failed: $result"
    966     }
    9671078    set _job(xmlobj) $xmlobj
    9681079}
     
    9811092        http::geturl $url -query $query -timeout 6000 -binary yes
    9821093    } token] != 0 } {
    983         puts stderr "error performing cache query: token=$token"
     1094        puts stderr "error performing cache query: driverFile=$driverFile url=$url token=$token"
    9841095        return 0
    9851096    }
     
    9901101#   puts stderr "meta   = [::http::meta $token]"
    9911102
     1103    set squid ""
    9921104    foreach {key value} [::http::meta $token] {
    9931105        set headers([string tolower $key]) $value
    9941106        if { [string tolower $key] == "etag" } {
    995             set guid $value
     1107            set squid $value
    9961108        }
    9971109    }
    9981110#   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    }
    10001130
    10011131    # If the code isn't 200, we'll assume it's a cache miss.
Note: See TracChangeset for help on using the changeset viewer.