Last Updated: June 27, 2014
2.0 Supported Platforms and Tcl Versions
6.0 Package STAFMon
STAF Tcl support must be installed in order to submit requests to STAF via a Tcl program.
Note: All of STAF's Tcl APIs are provided in the STAF namespace.
STAF Tcl support is only provided in the STAF installer files for the platforms listed below. STAF Tcl support is not provided in the STAF installer files for other operating systems.
The version of Tcl used to build the STAF Tcl libraries is usually the only Tcl version that will work with those STAF Tcl libraries. STAF currently provides STAF Tcl support on the following platforms:
Section 2.0 provides details about the STAF Tcl support by platform.
If you want to use higher version of Tcl, or if you want STAF Tcl support for a different operating system, you can either:
If you build STAF Tcl support for a different operating system and/or different Tcl version, please contribute it to the STAF project. To contribute it, browse the STAF Support Requests to see if someone else has already provided STAF Tcl support for this operating system and Tcl version combination. If not, open a STAF Support Request with the "Summary" containing "STAF V3 Support for Tcl x.x.x (Platform)", replacing x.x.x with the Tcl version and replacing Platform with the operating system on which you built the support. Attach the necessary files to the Support Request.
This section provides more information about the Tcl Versions supported by STAF by operating system.
Supported TCL Version | Built with | TCLSTAF library |
---|---|---|
8.3 | 8.3 (ActiveTcl) | {STAF/Config/STAFRoot}/bin/tcl83/TCLSTAF.dll |
8.4 | 8.4.19 (ActiveTcl) | {STAF/Config/STAFRoot}/bin/tcl84/TCLSTAF.dll |
8.5 | 8.5.9 (ActiveTcl) | {STAF/Config/STAFRoot}/bin/tcl85/TCLSTAF.dll |
8.6 | 8.6.0 (ActiveTcl) | {STAF/Config/STAFRoot}/bin/tcl86/TCLSTAF.dll |
Note: Support for Tcl Version 8.3 is installed by default to {STAF/Config/STAFRoot}/bin/TCLSTAF.dll during a "Typical" install of STAF for Windows 32-bit (unless another version of Tcl was selected as the default during the install). |
Supported TCL Version | Built with | TCLSTAF library |
---|---|---|
8.5 | 8.5.9 (ActiveTcl) | {STAF/Config/STAFRoot}/bin/tcl85/TCLSTAF.dll |
8.6 | 8.6.0 (ActiveTcl) | {STAF/Config/STAFRoot}/bin/tcl86/TCLSTAF.dll |
Note: Support for Tcl Version 8.5 is installed by default to {STAF/Config/STAFRoot}/bin/TCLSTAF.dll during a "Typical" install of STAF for Windows x64 (unless another version of Tcl was selected as the default during the install). |
Supported TCL Version | Built with | TCLSTAF library |
---|---|---|
8.4 | 8.5.4.19 (ActiveTcl) | {STAF/Config/STAFRoot}/lib/tcl84/libTCLSTAF.so |
8.5 | 8.5.9 (ActiveTcl) | {STAF/Config/STAFRoot}/lib/tcl85/libTCLSTAF.so |
8.6 | 8.6.0 (ActiveTcl) | {STAF/Config/STAFRoot}/lib/tcl86/libTCLSTAF.so |
Note: Support for Tcl Version 8.4 is installed by default to {STAF/Config/STAFRoot}/lib/libTCLSTAF.so during a "Typical" install of STAF for Linux 32-bit (unless another version of Tcl was selected as the default during the install). |
Supported TCL Version | Built with | TCLSTAF library |
---|---|---|
8.4 | 8.5.4.19 (ActiveTcl) | {STAF/Config/STAFRoot}/lib/tcl84/libTCLSTAF.so |
8.5 | 8.5.9 (ActiveTcl) | {STAF/Config/STAFRoot}/lib/tcl85/libTCLSTAF.so |
8.6 | 8.6.0 (ActiveTcl) | {STAF/Config/STAFRoot}/lib/tcl86/libTCLSTAF.so |
Note: Support for Tcl Version 8.4 is installed by default to {STAF/Config/STAFRoot}/lib/libTCLSTAF.so during a "Typical" install of STAF for Linux x86-64 (unless another version of Tcl was selected as the default during the install). |
Currently, STAF Tcl support is not provided in the STAF installer files for operating systems other than Windows 32-bit/AMD64 and Linux 32-bit/AMD64 (though you can build STAF Tcl support yourself). See section 1.0 Introduction above for more information on how to build STAF Tcl support yourself.
Once STAF Tcl support is installed, verify that the STAF Tcl library file exists:
export TCLLIBPATH=/usr/local/staf/libOr, if you already have set TCLLIBPATH to contain another directory (e.g. /usr/lib), then you would add the STAF lib directory and use a space to separate multiple directories. For example:
export TCLLIBPATH="/usr/local/staf/lib /usr/lib"
set TCLLIBPATH=C:/STAF/binOr, if you already have set TCLLIBPATH to contain another directory (e.g. C:/Tcl/bin), then you would add the STAF bin directory and use a space to separate multiple directories. For example:
set TCLLIBPATH="C:/STAF/bin C:/Tcl/bin"
Note that TCLLIBPATH must contain a Tcl list of directories, using a space to separate multiple directories (unlike the PATH environment variable which uses colons on Unix or semi-colons on Windows to separate multiple directories).
package require STAF
package require STAF # First, must register with STAF if {[STAF::Register "Tcl Test"] != $STAF::kOk} { puts "Error registering with STAF, RC: $STAF::RC" exit $STAF::RC } puts "Using handle $STAF::Handle" # Submit some STAF requests puts "Testing basic functionality" STAF::Submit local PING PING if {$STAF::Result != "PONG"} { puts "Wrong output for ping request" exit 1 } if {[STAF::Submit local VAR "RESOLVE STRING {STAF/Config/MachineNickname}"] != $STAF::kOk} { puts "Error resolving machine nickname, RC: $STAF::RC, Result: $STAF::Result" exit $STAF::RC } puts "Machine Nickname: $STAF::Result" # Unregister with STAF to remove the handle if {[STAF::UnRegister] != $STAF::kOk} { puts "Error unregistering with STAF, RC: $STAF::RC" exit $STAF::RC } puts "All tests successful" exit 0
# tcl testTcl.tcl Using handle 3 Testing basic functionality Machine Nickname: client1.company.com All tests successful #
These APIs allow you to register/unregister with STAF, submit STAF service requests, and to wrap the values of options used in STAF service requests.
This function allows you to register with STAF. You must register with STAF before you can use any of the other STAF related APIs.
Required argument processName is a String that contains the name by which your Tcl program will be known.
The variable STAF::RC will also contain the return code from this function.
The variable STAF::Handle will contain this program's STAF handle on a successful return. This variable should not be altered.
if {[STAF::Register "My program"] != $STAF::kOk} { puts "Error registering with STAF, RC: $STAF::RC" exit $STAF::RC } puts "My STAF handle: $STAF::Handle"
This function allows you to submit requests to STAF. This is the primary API that you will use when working with STAF.
Required argument location is a String that contains the endpoint for the system to which the request should be submitted. "Local" may be used to represent the local system, i.e., the system on which the Tcl program is running.
Required argument service is a String that contains the name of the service to which the request should be submitted.
Required argument request is a String that contains the actual request string itself.
The variable STAF::RC will also contain the return code from this function.
The variable STAF::Result will contain the textual result buffer from this request. See the individual service documentation for information on the contents of this buffer.
if {[STAF::Submit local ping ping] != $STAF::kOk} { puts "Error submitting ping request, RC: $STAF::RC" if {[string length $STAF::Result] != 0} { puts "Additional info: $STAF::Result" } exit $STAF::RC } puts "STAF Ping result: $STAF::Result"
This function allows you to unregister with STAF. This allows STAF to free up the information associated with your handle. This should be the last STAF related API that you call in your program.
This function has no arguments.
The variable STAF::RC will also contain the return code from this function.
The variable STAF::Handle will be deleted when this function returns.
if {[STAF::UnRegister] != $STAF::kOk} { puts "Error unregistering with STAF, RC: $STAF::RC" exit $STAF::RC }
Returns a colon-length-colon delimited version of the input string. This function is widely used to pass the values of options in STAF requests.
Required argument inputString is a String
set semName {My Synch Sem} STAF::Submit local sem "event [STAF::WrapData $semName] post"
These APIs allow you to define, manipulate, and (un)marshall data structures, and print marshalled data in human-readable ("pretty" print) format.
STAF supports the automatic marshalling and unmarshalling of structured data. The act of marshalling takes a data structure and converts it into a string-based representation. The act of unmarshalling reverses this and converts the string-based representation back into a data structure. See Section 6.1, "Marshalling Structured Data" in the STAF User's Guide for more information.
Since: STAF V3.1.0
The STAF::datatype procedure supports the following subcommands and their arguments:
The optional argument value specifies the value to assign.
The optional argument value specifies the value to assign.
The optional argument value specifies the value to assign.
The optional argument value specifies the root object to assign to the context.
Generally, you should use the STAF::mcontext create ?rootobject? procedure instead of this one to create a STAF marshalling context.
The required argument object specifies the object.
The required argument object specifies the object.
The required argument objectVar specifies the variable name of the object to set.
The required argument newValue specified the value to assign to the object.
# Using data type None puts "\nUsing data type: None" set dtNone [STAF::datatype createNone] puts "dtNone value: [STAF::datatype getValue $dtNone]" # Check if an object is a None data type if {[STAF::datatype getType $dtNone] == $STAF::NoneType} { puts "Data Type: [STAF::datatype getType $dtNone]" } # Using data type Context puts "\nUsing data type: Context" # Create a Context data type with None as the root object set dtContext [STAF::datatype createContext] puts "dtContext value: [STAF::datatype getValue $dtContext]" # Create a Context data type with a List data type as the root object set dtList [STAF::datatype createList [list "List" "Test" "Value"]] set dtContext [STAF::mcontext create $dtList] puts "dtContext value: [STAF::datatype getValue $dtContext]" # Check if an object is a Context data type if {[STAF::datatype getType $dtContext] == $STAF::ContextType} { puts "Data Type: [STAF::datatype getType $dtContext]" } # Using data type Scalar puts "\nUsing data type: Scalar" # Create a Scalar data type with an empty string value set dtScalar [STAF::datatype createScalar] puts "dtScalar value: [STAF::datatype getValue $dtScalar]" # Set the value for a Scalar data type to a string set myString "Testing 123..." STAF::datatype setValue dtScalar $myString puts "dtScalar value: [STAF::datatype getValue $dtScalar]" # Set the value for a Scalar data type to a number set myRC 99 set dtScalar [STAF::datatype createScalar $myRC] puts "dtScalar value: [STAF::datatype getValue $dtScalar]" # Check if an object is a Scalar data type if {[STAF::datatype getType $dtScalar] == "$STAF::ScalarType"} { puts "Data Type: [STAF::datatype getType $dtScalar]" } # Using data type List puts "\nUsing data type: List" # Create an empty List data type set dtList [STAF::datatype createList] puts "dtList value: [STAF::datatype getValue $dtList]" # Set the value for a List data type set listTestValue [list "List" "Test" "Value"] STAF::datatype setValue dtList $listTestValue puts "dtList value: [STAF::datatype getValue $dtList]" # Create a List data type assigning an initial value set listInitValue [list "List" "Init" "Value"] set dtList [STAF::datatype createList $listInitValue] puts "dtList value: [STAF::datatype getValue $dtList]" # Change the value for a List data type lappend listTestValue "And" lappend listTestValue "More" STAF::datatype setValue dtList $listTestValue puts "dtList value: STAF::datatype getValue $dtList]" # Append entries to a List data type lappend dtList "And" lappend dtList "More" puts "dtList value: [STAF::datatype getValue $dtList]" # Check if an object is a List data type if {[STAF::datatype getType $dtList] == "$STAF::ListType"} { puts "Data Type: [STAF::datatype getType $dtList]" } # Using data type Map puts "\nUsing data type: Map" # Create an empty Map data type set dtMap [STAF::datatype createMap] puts "dtMap value: [STAF::datatype getValue $dtMap]" # Set the value for a Map data type set mapTest(key1) value1 set mapTest(key2) value2 set mapTestValue [array get mapTest] STAF::datatype setValue dtMap $mapTestValue puts "dtMap value: [STAF::datatype getValue $dtMap]" # Create a Map data type assigning an initial value set mapInit(key3) value3 set mapInit(key4) value4 set mapInitValue [array get mapInit] set dtMap [STAF::datatype createMap $mapInitValue] puts "dtMap value: [STAF::datatype getValue $dtMap]" # Change the value for a Map data type STAF::datatype setValue dtMap $mapTestValue puts "dtMap value: [STAF::datatype getValue $dtMap]" # Add an additional key/value to a Map data type set mapAdditionalValue(key5) value5 append mapTestValue " " [array get mapAdditionalValue] append dtMap " " [array get mapAdditionalValue] puts "dtMap value: [STAF::datatype getValue $dtMap]" # Check if an object is a Map data type if {[STAF::datatype getType $dtMap] == "$STAF::MapType"} { puts "Data Type: [STAF::datatype getType $dtMap]" } # Using data types List and Map to create a list of maps puts "\nUsing data types List and Map to create a list of maps" set map1(key1) value1 set map1(key2) value2 set map1Value [array get map1] set dtMap1 [STAF::datatype createMap $map1Value] set map2(test1) C:/tests/test1.cmd set map2(test2) C:/tests/test2.sh set map2Value [array get map2] set dtMap2 [STAF::datatype createMap $map2Value] set listValue [list $dtMap1 $dtMap2] set dtList [STAF::datatype createList $listValue] puts "dtList: $dtList" puts "dtList value: [STAF::datatype getValue $dtList]"
This example prints the following:
Using data type: None dtNone value: None Data Type: STAF_DT_NONE Using data type: Context dtContext value: dtContext value: mapClassMap STAF_DT_MAP rootObj {STAF_DT_LIST List Test Value} Data Type: STAF_DT_CONTEXT Using data type: Scalar dtScalar value: dtScalar value: Testing 123... dtScalar value: 99 Data Type: STAF_DT_SCALAR Using data type: List dtList value: dtList value: List Test Value dtList value: List Init Value dtList value: List Test Value And More dtList value: List Test Value And More And More Data Type: STAF_DT_LIST Using data type: Map dtMap value: dtMap value: key1 value1 key2 value2 dtMap value: key3 value3 key4 value4 dtMap value: key1 value1 key2 value2 dtMap value: key1 value1 key2 value2 key5 value5 Data Type: STAF_DT_MAP Using data types List and Map to create a list of maps dtList: STAF_DT_LIST {STAF_DT_MAP key1 value1 key2 value2} {STAF_DT_MAP test1 C: /tests/test1.cmd test2 C:/tests/test2.sh} dtList value: {STAF_DT_MAP key1 value1 key2 value2} {STAF_DT_MAP test1 C:/tests/ test1.cmd test2 C:/tests/test2.sh}
Since: STAF V3.1.0
The STAF::mapclassdef procedure supports the following subcommands and their arguments:
The required argument mapclassname specifies the name of the STAF map class definition.
The required argument mapclassdef specifies the map class definition.
The required argument mapclassdefVar specifies the variable name of the map class definition.
The required argument keyName specifies the name of a key.
The optional argument displayName specifies a string to use when displaying the key. The default is None which indicates to use the actual key name when displaying the key.
The required argument mapclassdefVar specifies the variable name of the map class definition.
The required argument keyName specifies the name of a key for which this property is being set.
The required argument property specifies the name of the property being set. The only property name currently recognized is 'display-short-name' which is used by the STAF executable when displaying a result in a tabular format when the length of the values for the fields is less than the length of the 'display-name'.
The required argument value specifies the value for the property being set.
The required argument mapclassdef specifies the map class definition.
The required argument mapclassdef specifies the map class definition.
# Create a map class definition set myMapClassDef [STAF::mapclassdef create "Test/MyMap"] STAF::mapclassdef addKey myMapClassDef "name" "Name" STAF::mapclassdef addKey myMapClassDef "exec" "Executable" STAF::mapclassdef addKey myMapClassDef "testType" "Test Type" STAF::mapclassdef setKeyProperty myMapClassDef "testType" "display-short-name" "Test" STAF::mapclassdef addKey myMapClassDef "outputList" "Outputs" set mapClassDefName [STAF::mapclassdef getName $myMapClassDef] puts "The keys for map class definition '$mapClassDefName' are:" puts "[STAF::formatObject [STAF::mapclassdef getKeys $myMapClassDef]]"
The keys for map class definition 'Test/MyMap' are: [ { display-name: Name key : name } { display-name: Executable key : exec } { display-name : Test Type key : testType display-short-name: Test } { display-name: Outputs key : outputList } ]
In order to use a map class when marshalling data, you must add the map class definition to the marshalling context, set the root object of the marshalling context to the object you want to marshall, and then marshall the marshalling context itself. When you unmarshall a data structure, you will always receive a marshalling context. Any map class definitions referenced by map classes within the data structure will be present in the marshalling context.
The primary use of a STAF marshalling context is to represent multi-valued results that consist of a data structure (e.g. results from a QUERY/LIST service request, etc.) as a string that can also be converted back into the data structure. This string can be assigned to the string result buffer returned from the service request.
Since: STAF V3.1.0
The STAF::mcontext procedure supports the following subcommands and their arguments:
The optional argument rootObject specifies the root object to be marshalled. The default is None.
The required argument mcVar specifies the variable name of the marshalling context.
The required argument mapClassDef specifies a map class definition object that can be used when marshalling the object. You may call this method any number of times to set multiple map class definition objects for the marshalling context.
The required argument mc specifies the marshalling context.
The required argument mapClassName specifies a string containing the name of the map class definition object that you want to return.
The required argument mc specifies the marshalling context.
The required argument mapClassName specifies a string containing the name of the map class definition. This subcommand will check if it exists in the marshalling context's list of map class definitions.
The required argument mc specifies the marshalling context.
The required argument mc specifies the marshalling context.
The required argument mcVar specifies the variable name of the marshalling context.
The required argument rootObject can specify any object.
The required argument mc specifies the marshalling context.
The required argument mc specifies the marshalling context.
The required argument mc specifies the marshalling context.
Note that this is basically shorthand for a STAF::marshall procedure call when specifying a marshalling context as the object to be marshalled.
The required argument mc specifies the marshalling context whose root object will be formatted in a verbose, more readable format.
Note that this is basically shorthand for a STAF::formatObject procedure call when specifying a marshalling context as the object to be "pretty printed".
# Create a map class definition set myMapClassDef [STAF::mapclassdef create "Test/MyMap"] STAF::mapclassdef addKey myMapClassDef "name" "Name" STAF::mapclassdef addKey myMapClassDef "exec" "Executable" # Create a marshalling context and set the map class definition # and assign myTestList as the root object set mc [STAF::mcontext create] STAF::mcontext setMapClassDefinition mc $myMapClassDef # From a list of maps, create a list datatype of map class datatypes # and marshall that data and assign to a message set testList [list {exec /tests/TestA.py name TestA} \ {exec /tests/TestB.sh name TestB} \ {exec /tests/TestC.cmd name TestC}] set myTestList [STAF::datatype createList] foreach testObj $testList { array set test $testObj set testMapObj [STAF::mapclassdef createInstance $myMapClassDef] array set testMap [STAF::datatype getValue $testMapObj] set testMap(name) $test(name) set testMap(exec) $test(exec) lappend myTestList [STAF::datatype createMap [array get testMap]] } STAF::mcontext setRootObject mc $myTestList puts "\nTest List:\n[STAF::mcontext formatObject $mc]" # Create a string from the marshalling context # This string could be a message that you log or send to a queue, etc. set stringResult [STAF::mcontext marshall $mc] # Convert the marshalled string representation back into a list set mc2 [STAF::unmarshall $stringResult] set theTestList [STAF::mcontext getRootObject $mc2] puts "\nTest List:\n[STAF::mcontext formatObject $mc2]"
This example prints the following:
Test List: [ { Name : TestA Executable: /tests/TestA.py } { Name : TestB Executable: /tests/TestB.sh } { Name : TestC Executable: /tests/TestC.cmd } ] Test List: [ { Name : TestA Executable: /tests/TestA.py } { Name : TestB Executable: /tests/TestB.sh } { Name : TestC Executable: /tests/TestC.cmd } ]
The required argument someData is the string to be tested.
Since: STAF V3.2.1
if {[STAF::isMarshalledData $message]} { # Unmarshall the data set mc [STAF::unmarshall $message] }
The optional -context context option specifies a marshalling context to use. The default is None.
The required argument object is the object to be marshalled.
Since: STAF V3.1.0
Note, that the STAF::mcontext procedure also provides a marshall subcommand to marshall a marshalling context's root object.
set myTestArray(name) "TestA" set myTestArray(exec) "/tests/TestA.py" set myTestArray(testType) "FVT" set myTestArray(outputs) {"TestA.out" "TestA.err"} set myTestArrayString [array get myTestArray] set myArrayObject [STAF::datatype createMap $myTestArrayString] set message [STAF::marshall $myArrayObject] set request "QUEUE MESSAGE [STAF::WrapData $message]" if {[STAF::Submit local QUEUE $request] != $STAF::kOk} { puts "Error on STAF local QUEUE $request" puts "RC=$STAF::RC, Result: $STAF::Result" exit $STAF::RC } # Another process could obtain the message from the queue and unmarshall # it to get the original dictionary (map) object if {[STAF::Submit local QUEUE GET] != $STAF::kOk} { puts "Error on STAF local QUEUE GET" puts "RC=$STAF::RC, Result: $STAF::Result" exit $STAF::RC } set mc [STAF::unmarshall $STAF::Result] set messageMapObj [STAF::mcontext getRootObject $mc] array set messageMap [STAF::datatype getValue $messageMapObj] array set yourTestArray [STAF::datatype getValue $messageMap(message)] puts "Name : $yourTestArray(name)" puts "Exec : $yourTestArray(exec)" puts "Test Type: $yourTestArray(testType)" puts "Outputs : $yourTestArray(outputs)"
This example prints the following:
Name : TestA Exec : /tests/TestA.py Test Type: FVT Outputs : "TestA.out" "TestA.err"
This example creates a marshalling context with one map class definition and a list where each entry is a map. It then creates a string-based marshalled representation of it. Finally, it prints the marshalled data using the STAF::formatObject procedure.
# Create a map class definition set myMapClassDef [STAF::mapclassdef create "Test/MyMap"] STAF::mapclassdef addKey myMapClassDef "name" "Name" STAF::mapclassdef addKey myMapClassDef "exec" "Executable" # Create a marshalling context and set the map class definition set mc [STAF::mcontext create] STAF::mcontext setMapClassDefinition mc $myMapClassDef # From a list of maps, create a list datatype of map class datatypes # and marshall that data and assign to a message set testList [list {exec /tests/TestA.py name TestA} \ {exec /tests/TestB.sh name TestB} \ {exec /tests/TestC.cmd name TestC}] set myTestList [STAF::datatype createList] foreach testObj $testList { array set test $testObj set testMapObj [STAF::mapclassdef createInstance $myMapClassDef] array set testMap [STAF::datatype getValue $testMapObj] set testMap(name) $test(name) set testMap(exec) $test(exec) lappend myTestList [STAF::datatype createMap [array get testMap]] } set message [STAF::marshall -context $mc $myTestList] puts "Formatted Data:\n$[STAF::formatObject -context $mc $myTestList]"
This example prints the folowing:
[ { Name : TestA Executable: /tests/TestA.py } { Name : TestB Executable: /tests/TestB.sh } { Name : TestC Executable: /tests/TestC.cmd } ]
A procedure used to convert a string-based marshalled representation specified by argument data back into a data structure. It returns a marshalling context from which you can get the data structure via the STAF::mcontext procedure's subcommand getRootObject.
The optional -context context option specifies the STAF marshalling Context datatype object that should be used when unmarshalling the string. The default is None. Note that a new marshalling context will be returned even if an existing marshalling context is specified for this option.
The optional -ignoreIndirectObjects option can be used to control how to unmarshall the string. When a string is unmarshalled into a data structure, it is possible that one of the string objects that is unmarshalled is itself the string form of another marshalled data structure. The default is to recursively unmarshall these nested objects. Use the -ignoreIndirectObjects option to disable this additional processing.
The required argument data is a string to be unmarshalled.
Since: STAF V3.1.0
Note that STAF service requests that return multiple values in their result buffer return marshalled data. Refer to the service request's documentation for details on the data structure (e.g. list, map, etc) resulting from unmarshalling the result from a service request that returns marshalled data.
# Submit a query request to the FS Service to query info about a file set fileName "{STAF/Config/ConfigFile}" set request "QUERY ENTRY $fileName" puts "STAF local FS $request\n" if {[STAF::Submit local FS $request] != $STAF::kOk} { puts "Error on STAF local FS $request" puts "RC=$STAF::RC, Result: $STAF::Result" exit $STAF::RC } set mc [STAF::unmarshall $STAF::Result] set entryMapObj [STAF::mcontext getRootObject $mc] array set entryMap [STAF::datatype getValue $entryMapObj] # Submit a resolve requset to the VAR service to resolve the STAF variable STAF::Submit local VAR "RESOLVE STRING $fileName" set resolvedFileName $STAF::Result if {$entryMap(type) == "F"} { puts "File Name : $resolvedFileName" puts "File Size : $entryMap(lowerSize)" puts "Last Modified: $entryMap(lastModifiedTimestamp)" } else { puts "$resolvedFileName is not a file. Type=$entryMap(type)" }
This example could print something like the following:
STAF local FS QUERY ENTRY {STAF/Config/ConfigFile} File Name : C:\STAF\bin\staf.cfg File Size : 7333 Last Modified: 20060913-16:36:48
This example submits a request to the PROCESS service to run a command on a machine and to wait for the command to complete. The request returns marshalled data whose root object is a map that contains keys like 'rc' and 'fileList'. The value for 'fileList' is a list of the returned files. Each entry in the list consists of a map that contains keys 'rc' and 'data'. In our PROCESS START request, we returned one file, stdout (and returned stderr to this same file). (Note that the STAF User's Guide defines the results for each request submitted to an internal STAF service.)
# Submit a PROCESS START request and wait for it to complete set command "dir {STAF/Config/STAFRoot}" set request "START SHELL COMMAND [STAF::WrapData $command] RETURNSTDOUT STDERRTOSTDOUT WAIT" puts "\nSTAF local PROCESS $request" if {[STAF::Submit local PROCESS $request] != $STAF::kOk} { puts "Error on STAF local PROCESS $request" puts "Expected RC: 0" puts "Received RC: $STAF::RC, Result: $STAF::Result" exit $STAF::RC } # Unmarshall the result which is a marshalling context whose # root object is a map containing keys 'rc', and 'fileList'. # The value for 'fileList' is a list of the returned files. # Each entry in the list consists of a map that contains keys # 'rc' and 'data'. In our PROCESS START request, we returned # one file, stdout (and returned stderr to this same file). set mc [STAF::unmarshall $STAF::Result] set processMapObj [STAF::mcontext getRootObject $mc] array set processMap [STAF::datatype getValue $processMapObj] puts "Process RC: $processMap(rc)" # Verify that the rc is 0 for returning data for the Stdout file set fileListObj [STAF::datatype getValue $processMap(fileList)] set stdoutFileObj [STAF::datatype getValue [lindex $fileListObj 0]] array set stdoutFileMap [STAF::datatype getValue $stdoutFileObj] if {$stdoutFileMap(rc) != $STAF::kOk} { puts "Error on retrieving process's stdout data." puts "Expected RC: 0" puts "Received RC: $stdoutFileMap(rc)" exit $stdoutFileMap(rc) } # Print the data in the stdout file created by the process puts "\nProcess Stdout file contains:\n$stdoutFileMap(data)" # Verify that the process rc is 0 if {$processMap(rc) != $STAF::kOk} { puts "Process RC: $processMap(rc)" puts "Expected Process RC: 0" exit $processMap(rc) }
This example could print something like the following:
Process Stdout file contains: Volume in drive C has no label. Volume Serial Number is B0B7-F95A Directory of C:\STAF 01/26/2006 02:56p. 01/26/2006 02:56p .. 01/26/2006 02:56p lib 01/26/2006 02:56p codepage 01/26/2006 02:56p samples 01/26/2006 02:57p include 01/26/2006 02:57p bin 02/25/2008 01:30p 17,029 LICENSE.htm 01/26/2006 03:04p docs 01/26/2006 03:11p data 02/12/2008 05:05p 25 STAFReg.inf 06/05/2008 10:17a 8,729 NOTICES.htm 06/24/2008 04:34p 77 install.properties 4 File(s) 72,601 bytes 9 Dir(s) 8,199,012,352 bytes free
The optional -context context option specifies the STAF marshalling Context datatype object that should be used when generating the "pretty print" output. The default is None.
The required argument object specifies the object to be formatted in a verbose, more readable format.
Since: STAF V3.2.1
Note, that the STAF::mcontext procedure also provides a formatObject subcommand to "pretty print" a marshalling context's root object.
set myTestMap(name) TestA set myTestMap(exec) "/tests/TestA.tcl" set myTestMap(testType) FVT set listValue [list TestA.out TestA.err] set dtList [STAF::datatype createList $listValue] set myTestMap(outputs) $dtList set dtTestMap [STAF::datatype createMap [array get myTestMap]] puts [STAF::formatObject $dtTestMap]
This example could print the following output:
{ outputs : [ TestA.out TestA.err ] name : TestA exec : /tests/TestA.tcl testType: FVT }
This example prints the result from a FS QUERY ENTRY request in a "pretty" verbose format.
set fileName "{STAF/Config/ConfigFile}" set request "QUERY ENTRY $fileName" puts "STAF local FS $request\n" if {[STAF::Submit local FS $request] != $STAF::kOk} { puts "Error on STAF local FS $request" puts "RC=$STAF::RC, Result: $STAF::Result" exit $STAF::RC } set mc [STAF::unmarshall $STAF::Result] puts "Formatted output:\n[STAF::formatObject $mc]"
If successful, this example could print something like the following output:
STAF local FS QUERY ENTRY {STAF/Config/ConfigFile} Formatted output: { Name : c:\staf\bin\STAF.cfg Type : F Upper 32-bit Size : 0 Lower 32-bit Size : 5902 Modified Date-Time: 20061122-11:07:02 }
These APIs allow you to handle private data. See Section 7.3, "Private Data" in the STAF User's Guide for more information about handling private data.
Adds privacy delimiters to a string and returns the updated string. See Section 7.3, "Private Data" in the STAF User's Guide for more information about handling private data.
This method should be used by anyone who wants to protect private data specified in a STAF command option that supports handling private data.
Required argument data is a String that contains data you want to protect.
Since: STAF V3.1.0
Examples:
set password "passw0rd" set protectedPw [STAF::AddPrivacyDelimiters $password] set request "START COMMAND C:/tests/TestA USERNAME Test1 PASSWORD $protectedPw" if {[STAF::Submit local PROCESS $request] != $STAF::kOk} { puts "Error submitting process, RC: $STAF::RC, Result: $STAF::Result" }
set password "secret" set command "C:/tests/admin -password [STAF::AddPrivacyDelimiters $password]" set request "START COMMAND [STAF::WrapData $command]" if {[STAF::Submit local PROCESS $request] != $STAF::kOk} { puts "Error submitting process, RC: $STAF::RC, Result: $STAF::Result"
Escapes all privacy delimiters (!!@ and @!!) found in the data with a caret (^) and returns the updated string. See Section 7.3, "Private Data" in the STAF User's Guide for more information about handling private data.
This method should be used before calling the addPrivacyDelimiters method for data that needs to be protected but may contain substrings !!@ and/or @!! that should not be mistaken for privacy delimiters .
Required argument data is a String.
Since: STAF V3.1.0
For example, if the data is "passw@!!d", this method would return "passw^@!!d".
set password "passw@!!d" set protectedPw [STAF::AddPrivacyDelimiters [STAF::EscapePrivacyDelimiters $password]] set request "START COMMAND C:/tests/TestA USERNAME Test1 PASSWORD $protectedPw" if {[STAF::Submit local PROCESS $request] != $STAF::kOk} { puts "Error submitting process, RC: $STAF::RC, Result: $STAF::Result" }
Removes privacy delimiters found in the data and returns the updated string. See Section 7.3, "Private Data" in the STAF User's Guide for more information about handling private data.
Required argument data is a String that may contain privacy delimiters (e.g. !!@, @!!).
Optional argument numLevels in an int that specifies the number of levels of privacy data to remove. The default is 0 which indicates to remove all levels of privacy data. Note that, generally, you'll want to remove all levels of privacy delimiters.
Since: STAF V3.1.0
Examples:
set protectedPw "!!@secret@!!" set password [STAF::RemovePrivacyDelimiters $protectedPw]
Masks any private data (enclosed between opening, !!@, and closing, @!!, privacy delimiters) by replacing the private data with asterisks. See Section 7.3, "Private Data" in the STAF User's Guide for more information about handling private data.
Required argument data is a String that may contain privacy delimiters (e.g. !!@, @!!).
Since: STAF V3.1.0
Examples:
set password "passw0rd" set protectedPw [STAF::AddPrivacyDelimiters $password] set request "START COMMAND C:/tests/TestA.exe USERNAME Test1 PASSWORD $protectedPw" puts "[STAF::MaskPrivateData $request]"
The following variables affect the behavior of the STAFMon package. These variables values may be changed to alter the behavior of the STAFMon package.
This function logs a message to the Monitor service.
Required argument message is a String that contains the message to log.
Optional argument options is a String that contains any additional option(s) that should be passed on to the LOG request, e.g. RESOLVEMESSAGE.
The variables STAF::RC and STAF::Result will also be set based on the underlying STAF::Submit call.
if {[STAF::Monitor::Log "Hello World"] != $STAF::kOk} { puts "Error logging message to Monitor, RC: $STAF::RC" return $STAF::RC }
The following variables affect the behavior of the STAFLog package. These variables values may be changed to alter the behavior of the STAFLog package.
This function initializes the utility functions for a specific log file.
Required argument logName is a String that contains the name of the log.
Optional argument logType is a String that contains the type of log to be created: "GLOBAL", "MACHINE", or "HANDLE". The default is "MACHINE".
Optional argument monitorMask is a String that contains the logging level(s) which will also be sent to the Monitor service. The default is "FATAL ERROR WARNING INFO STATUS".
STAF::Log::Init Testcase1 GLOBAL "FATAL ERROR"
This function logs a message to the Log service. This function will also log the message to the Monitor service if the specified logging level is one of the levels defined in the Monitor Mask (set in STAF::Log::Init, above).
Required argument level is a String that contains the level of the message to log, e.g., WARNING or DEBUG.
Required argument message is a String that contains the message to log.
Optional argument options is a String that contains any additional options that should be passed on the the LOG request, e.g., RESOLVEMESSAGE.
The variables STAF::RC and STAF::Result will also be set based on the underlying STAF::Submit call.
if {[STAF::Log::Log WARNING "Unable to find specified file"] != $STAF::kOk} { puts "Error logging message to Log, RC: $STAF::RC" return $STAF::RC }