Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

YadaMachines.tcl

00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## YadaMachines - configure document for all machines. 00013 ## \ingroup YadaConfiguration 00014 ## 00015 ## \author Michael Daum 00016 ## 00017 ## $Id: YadaMachines.tcl,v 1.12 2004/10/15 17:24:37 micha Exp $ 00018 ## ---------------------------------------------------------------------------- 00019 class YadaMachines { 00020 inherit YadaConfigDocument 00021 00022 # methods ------------------------------------------------------------------ 00023 public method init {} 00024 public method load {} 00025 public method save {} 00026 00027 constructor {args} {}; ## \type TclList 00028 00029 private method _commit {} 00030 private method _defaults {{fileName ""}}; ## \type TclString 00031 private method _new {} 00032 private method _delete {} 00033 private method _select {{machineName ""}}; ## \type TclString 00034 00035 }; 00036 00037 ## ---------------------------------------------------------------------------- 00038 ## constructor 00039 ## ---------------------------------------------------------------------------- 00040 body YadaMachines::constructor {args} { 00041 00042 set _allAspects {name nodes access cpus} 00043 00044 00045 00046 # nodes 00047 itk_component add nodesLabel { 00048 label $itk_component(childsite).nodesLabel \ 00049 -text "Nodes:" \ 00050 -anchor nw 00051 } {} 00052 00053 itk_component add nodesMark { 00054 frame $itk_component(childsite).nodesMark \ 00055 -borderwidth 2 00056 } {} 00057 00058 itk_component add nodes { 00059 iwidgets::combobox $itk_component(nodesMark).box \ 00060 -completion false \ 00061 -unique true \ 00062 -borderwidth 2 \ 00063 } {} 00064 set entry [$itk_component(nodes) component entry] 00065 $entry configure \ 00066 -validate all \ 00067 -validatecommand [code $this _validateCommand "nodes" %P] 00068 00069 # access 00070 itk_component add accessLabel { 00071 label $itk_component(childsite).accessLabel \ 00072 -text "Access:" \ 00073 -anchor nw 00074 } {} 00075 00076 itk_component add accessMark { 00077 frame $itk_component(childsite).accessMark \ 00078 -borderwidth 2 00079 } {} 00080 00081 itk_component add access { 00082 iwidgets::combobox $itk_component(accessMark).box \ 00083 -completion false \ 00084 -unique true \ 00085 -borderwidth 2 \ 00086 } {} 00087 set entry [$itk_component(access) component entry] 00088 $entry configure \ 00089 -validate all \ 00090 -validatecommand [code $this _validateCommand "access" %P] 00091 00092 # cpus 00093 itk_component add cpusLabel { 00094 label $itk_component(childsite).cpusLabel \ 00095 -text "CPUs:" \ 00096 -anchor nw 00097 } {} 00098 00099 itk_component add cpusMark { 00100 frame $itk_component(childsite).cpusMark \ 00101 -borderwidth 2 00102 } {} 00103 00104 itk_component add cpus { 00105 entry $itk_component(cpusMark).cpus \ 00106 -borderwidth 2 \ 00107 -validatecommand [code $this _validateCommand "cpus" %P] \ 00108 -validate all 00109 } {} 00110 00111 # load 00112 itk_component add loadLabel { 00113 label $itk_component(childsite).loadLabel \ 00114 -text "Current Load:" \ 00115 -anchor nw 00116 } {} 00117 00118 itk_component add loadMark { 00119 frame $itk_component(childsite).loadMark \ 00120 -borderwidth 2 00121 } {} 00122 00123 itk_component add load { 00124 entry $itk_component(loadMark).load \ 00125 -borderwidth 2 \ 00126 -state disabled 00127 } {} 00128 00129 # 00130 # packing + gridding 00131 # 00132 grid rowconfigure $itk_component(childsite) 4 -weight 1 00133 grid configure $itk_component(nameMark) -columnspan 3 00134 00135 grid $itk_component(nodesLabel) -sticky new -row 1 -column 0 -pady 10 00136 grid $itk_component(nodesMark) -sticky new -row 1 -column 1 -pady 10 -columnspan 3 00137 pack $itk_component(nodes) -fill both -expand 1 -side left 00138 00139 grid $itk_component(accessLabel) -sticky new -row 2 -column 0 -pady 10 00140 grid $itk_component(accessMark) -sticky new -row 2 -column 1 -pady 10 -columnspan 3 00141 pack $itk_component(access) -fill both -expand 1 -side left 00142 00143 grid $itk_component(cpusLabel) -sticky ew -row 3 -column 0 -pady 10 00144 grid $itk_component(cpusMark) -sticky w -row 3 -column 1 -pady 10 00145 pack $itk_component(cpus) -fill both -expand 1 -side left 00146 00147 grid $itk_component(loadLabel) -sticky ew -row 3 -column 2 -pady 10 00148 grid $itk_component(loadMark) -sticky w -row 3 -column 3 -pady 10 00149 pack $itk_component(load) -fill both -expand 1 -side left 00150 00151 eval itk_initialize $args 00152 } 00153 00154 ## ---------------------------------------------------------------------------- 00155 ## init 00156 ## ---------------------------------------------------------------------------- 00157 body YadaMachines::init {} { 00158 if {$_isInitialized} { 00159 return 00160 } 00161 chain 00162 00163 # initialize the nodes combobox 00164 set nodesList "" 00165 set accessList "" 00166 foreach machine [getAllItems] { 00167 set nodes [$machine cget -nodes] 00168 set access [$machine cget -access] 00169 if {[lsearch $nodesList $nodes] < 0} { 00170 lappend nodesList $nodes 00171 } 00172 if {[lsearch $accessList $access] < 0} { 00173 lappend accessList $access 00174 } 00175 } 00176 eval $itk_component(nodes) insert list end $nodesList 00177 eval $itk_component(access) insert list end $accessList 00178 00179 00180 #set machines [itcl_info objects -class YadaMachine] 00181 #foreach machine $machines { 00182 # if { [$machine hasSavedState] } { 00183 # $machine load 00184 # } 00185 #} 00186 00187 _select "<none>" 00188 } 00189 00190 ## ---------------------------------------------------------------------------- 00191 ## _select 00192 ## ---------------------------------------------------------------------------- 00193 body YadaMachines::_select {{machineName ""}} { 00194 00195 # get a machine name from the combobox if we didn't provide one 00196 if {$machineName == ""} { 00197 set machineName [$itk_component(name) get] 00198 } 00199 00200 set currentItem [getItem $machineName] 00201 if {$currentItem == ""} { 00202 printMessage "ERROR: machine `$machineName' is unknown" error 00203 return 00204 } 00205 00206 # check if we didn't commit changes 00207 if {![_askChange]} { 00208 return 00209 } 00210 00211 00212 # set the active machine 00213 setCurrentItem $currentItem 00214 00215 ## update title bar 00216 displayTitle 00217 00218 # update the name box 00219 foreach aspect {name nodes access} { 00220 set box $itk_component($aspect) 00221 set values [[$box component list] get 0 end] 00222 set value [$currentItem cget -$aspect] 00223 set index [lsearch $values $value] 00224 if {$index > 0} { 00225 $box selection set $index $index 00226 } 00227 $box delete entry 0 end 00228 $box insert entry 0 $value 00229 } 00230 00231 # update the entries 00232 foreach aspect {cpus} { 00233 set entry $itk_component($aspect) 00234 $entry delete 0 end 00235 $entry insert 0 [$currentItem cget -$aspect] 00236 } 00237 set entry $itk_component(load) 00238 $entry configure -state normal 00239 $entry delete 0 end 00240 $entry insert 0 [$currentItem getLoad] 00241 $entry configure -state disabled 00242 00243 # remove marking 00244 _unmark 00245 00246 00247 # remember this selected name 00248 set _oldItem $machineName 00249 00250 } 00251 00252 ## ---------------------------------------------------------------------------- 00253 ## _defaults 00254 ## ---------------------------------------------------------------------------- 00255 body YadaMachines::_defaults {{fileName ""}} { 00256 global env 00257 00258 # default 00259 if {$fileName == ""} { 00260 set fileName [file join $env(YADA_LIB) machines.tcl.sample] 00261 } 00262 00263 # ... configured machines 00264 if {[catch {source $fileName} errMsg]} { 00265 bgerror "There's an error in your machines init file $fileName!" 00266 } 00267 00268 # required localhost machine 00269 YadaMachine ::#auto -name "localhost" -nodes "127.0.0.1" 00270 YadaMachine ::#auto -name "<none>" -nodes "" -access "" -cpus 0 00271 00272 # assert machines into the class 00273 set machines [itcl_info objects -class YadaMachine] 00274 foreach machine $machines { 00275 set machineName [$machine cget -name] 00276 set item [getItem $machineName] 00277 if {$item != ""} { 00278 puts "WARNING: machine `$machineName' already exists" 00279 } 00280 00281 setItem $machine 00282 } 00283 00284 .main printStatus "... built [llength $machines] machines" 00285 } 00286 00287 ## ---------------------------------------------------------------------------- 00288 ## _commit 00289 ## ---------------------------------------------------------------------------- 00290 body YadaMachines::_commit {} { 00291 00292 set currentItem [getCurrentItem] 00293 set oldName [$currentItem cget -name] 00294 00295 if {![chain]} { 00296 return 00297 } 00298 00299 # adjust each experiment using a machine with a changed name 00300 set newName [$currentItem cget -name] 00301 if {$oldName != $newName} { 00302 foreach experiment [.main getExperiments] { 00303 if {[$experiment cget -machineName] == $oldName} { 00304 $experiment configure -machineName $newName 00305 } 00306 } 00307 } 00308 00309 # save all aspects 00310 foreach aspect {nodes access cpus} { 00311 $currentItem configure -$aspect [$itk_component($aspect) get] 00312 } 00313 00314 # save data unique in comboboxes 00315 foreach aspect {nodes access} { 00316 set box $itk_component($aspect) 00317 set value [$currentItem cget -$aspect] 00318 set listBox [$box component list] 00319 if {[getIndexOfName $listBox $value] < 0} { 00320 set entries [$listBox get 0 end] 00321 lappend entries $value 00322 $listBox delete 0 end 00323 eval $listBox insert 0 [lsort -dictionary $entries] 00324 } 00325 } 00326 00327 # remember this selected name 00328 set _oldItem [$currentItem cget -name] 00329 00330 ## Mark as modified 00331 $currentItem setModified 00332 00333 # remove marking 00334 _unmark 00335 _select 00336 } 00337 00338 ## ---------------------------------------------------------------------------- 00339 ## _delete. 00340 ## \todo not yet implemented 00341 ## ---------------------------------------------------------------------------- 00342 body YadaMachines::_delete {} { 00343 } 00344 00345 ## ---------------------------------------------------------------------------- 00346 ## _new. 00347 ## \todo not yet implemented 00348 ## ---------------------------------------------------------------------------- 00349 body YadaMachines::_new {} { 00350 } 00351 00352 00353 ## ---------------------------------------------------------------------------- 00354 ## Overriding default implementation. Delegates command to current machine's 00355 ## load method 00356 ## ---------------------------------------------------------------------------- 00357 body YadaMachines::load {} { 00358 set currentItem [getCurrentItem] 00359 00360 if { [$currentItem cget -name] != "<none>"} { 00361 [getCurrentItem] load 00362 _select 00363 displayTitle 00364 } 00365 } 00366 00367 ## ---------------------------------------------------------------------------- 00368 ## Overriding default implementation. Delegates command to current machine's 00369 ## save method 00370 ## ---------------------------------------------------------------------------- 00371 body YadaMachines::save {} { 00372 set currentItem [getCurrentItem] 00373 00374 if { [$currentItem cget -name] != "<none>"} { 00375 [getCurrentItem] save 00376 displayTitle 00377 } 00378 } 00379 00380 00381 00382 00383

YADA 2.0-alpha (20 Oct 2004)