Tcl User's Guide for STAF Version 3

Last Updated: June 27, 2014


Table of Contents

1.0 Introduction

2.0 Supported Platforms and Tcl Versions

2.1 Windows (Intel 32-bit)
2.2 Windows (AMD64, aka x64)
2.3 Linux (Intel 32-bit, aka i386 or x86-32)
2.4 Linux (AMD64, aka x86-64)

3.0 Installation

4.0 Tcl Script Example

5.0 Package STAF

5.1 Primary STAF APIs 5.1.1 STAF::Register
5.1.2 STAF::Submit
5.1.3 STAF::UnRegister
5.1.4 STAF::WrapData

5.2 Data Structure and Marshalling APIs 5.2.1 STAF::datatype
5.2.2 STAF::mapclassdef
5.2.3 STAF::mcontext
5.2.4 STAF::isMarshalledData
5.2.5 STAF::marshall
5.2.6 STAF::unmarshall
5.2.7 STAF::formatObject

5.3 Private Data Manipulation APIs 5.3.1 STAF::AddPrivacyDelimiters
5.3.2 STAF::EscapePrivacyDelimiters
5.3.3 STAF::RemovePrivacyDelimiters
5.3.4 STAF::MaskPrivateData

5.4 STAF Return Codes
5.5 STAF Constants
6.0 Package STAFMon 6.1 Monitor Service Variables
6.2 STAF::Monitor::Log
7.0 Package STAFLog 7.1 Log Service Return Codes and Variables
7.2 STAF::Log::Init
7.3 STAF::Log::Log


1.0 Introduction

This document describes STAF's V3 support for the Tcl language.  It includes information on the core STAF Tcl APIs as well as the wrappers provided for the Monitor and Log services.

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:


2.0 Supported Platforms and Tcl Versions

This section provides more information about the Tcl Versions supported by STAF by operating system.

2.1 Windows (Intel 32-bit)

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).

2.2 Windows (AMD64, aka x64)

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).

2.3 Linux (Intel 32-bit, aka i386 or x86-32)

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).

2.4 Linux (AMD64, aka x86-64)

>
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).

3.0 Installation

To install and configure STAF Tcl support, perform the following steps:

  1. Install STAF's Tcl support by selecting to install "Tcl support" during the install. STAF Tcl support is installed by default for a "typical" install of STAF if using a STAF installer for Windows 32-bit or AMD64, or for Linux 32-bit or AMD64. During the STAF install, you can specify what version of Tcl you will be using as there is a different STAF Tcl library file for each version of Tcl supported by STAF.

    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:

  2. To configure Tcl to find the STAF Tcl support files, you need to set or update your TCLLIBPATH environment variable so that it includes the STAF directory containing the Tcl support files for the version of Tcl that you are using.

    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).

  3. Verify that the version of Tcl you have installed matches the STAF Tcl version supported by the TCLSTAF library you specified for the TCLLIBPATH environment variable as there is a different TCLSTAF library for each version of Tcl supported by STAF. See section 2.0 Supported Platforms and Tcl Versions for a list of the Tcl versions supported by STAF by operating system.

  4. Finally, you simply need to add a "package require" statement in your Tcl scripts for any of the STAF packages (STAF, STAFLog, STAFMon) that you use in your Tcl script. For example:
      package require STAF
    

4.0 Tcl Script Example

Here's a simple Tcl script that registers with STAF, submits a couple of STAF requests, and unregisters: Here's an example of what the output from running this simple Tcl program could be:

5.0 Package STAF

The STAF package provides support for Tcl scripts to call into STAF.  This package externalizes the following APIs: This package also provides variables for the various STAF return codes and some constants.

5.1 Primary STAF APIs

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.

5.1.1 STAF::Register

Description

Result

Example

5.1.2 STAF::Submit

Description

Result

Example

5.1.3 STAF::UnRegister

Description

Result

Examples

5.1.4 STAF::WrapData

Description

Result

Example

5.2 Data Structure and Marshalling APIs

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.

5.2.1 STAF::datatype

Description

The STAF::datatype procedure supports the following subcommands and their arguments:

Examples

The following is an example of how to use the datatype procedures subcommands to create objects with the various data types (None, Context, Scalar, List, and Map) and to set and get values for a data type object and to get the type of a data type object.

This example prints the following:

5.2.2 STAF::mapclassdef

Description

The STAF::mapclassdef procedure supports the following subcommands and their arguments:

Example

The following is an example of how to create a map class definition named 'Test/MyMap' containing four keys, each with a display name, and one with a short display name. This example prints the following:

5.2.3 STAF::mcontext

Description

The STAF::mcontext procedure supports the following subcommands and their arguments:

Examples

The following is an example of how to create a marshalling context containing one map class definition named 'Test/MyMap' and a root object which is a list datatype of map class datatypes defined by the map class definition. Then it shows how to marshall and unmarshall the marshalling context.

This example prints the following:

5.2.4 STAF::isMarshalledData

Description

Result

Examples

This example checks if a string contains marshalled data and, if so, unmarshalls it.

5.2.5 STAF::marshall

Description

Result

Examples

This example converts a Tcl array (aka map) into a string-based marshalled representation. It also shows how to convert this marshalled string back into the original Tcl array.

This example prints the following:

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.

This example prints the folowing:

5.2.6 STAF::unmarshall

Description

Result

Examples

This example submits a request to the FS service to query information about a file. The request returns marshalled data whose root object is a map that contains keys like 'type', 'lowerSize', and 'lastModifiedTimestamp'. (Note that the STAF User's Guide defines the results for each request submitted to an internal STAF service.)

This example could print something like the following:

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.)

This example could print something like the following:

5.2.7 STAF::formatObject

Description

Result

Examples

This example creates a Map datatype object and prints it in a "pretty" verbose format.

This example could print the following output:

This example prints the result from a FS QUERY ENTRY request in a "pretty" verbose format.

If successful, this example could print something like the following output:

5.3 Private Data Manipulation APIs

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.

5.3.1 STAF::AddPrivacyDelimiters

Description

Result

Examples

This example adds privacy delimiters to "passw0rd" used in the PASSWORD option when starting a process as another user. This example adds privacy delimiters to password "secret" used in the COMMAND option when starting a process.

5.3.2 STAF::EscapePrivacyDelimiters

Description

Result

Examples

This example escapes privacy delimiters in password "passw@!!d" before adding privacy delimiters to it and then uses the password in the PASSWORD option when starting a process as another user.

5.3.3 STAF::RemovePrivacyDelimiters

Description

Result

Examples

This example removes privacy delimiters from protected password "!!@secret@!!" and assigns "secret" as the password.

5.3.4 STAF::MaskPrivateData

Description

Result

Examples

This example masks any private data indicated by privacy delimiters in a request string before displaying it. This example prints:
START COMMAND C:/tests/TestA.exe USERNAME Test1 PASSWORD **************

5.4 STAF Return Codes

The following variables are defined, which represent the numeric return codes generated by STAF. For a complete description of these return codes and their meaning, please see the STAF User's Guide.

5.5 STAF Constants

Constants defined in the STAF namespace include:

6.0 Package STAFMon

The STAFMon package provides a function to ease the use of the Monitor service, as well as, variables which define the return codes from the Monitor service and variables which affect the operation of the utility function provided.

6.1 Monitor Service Variables

The following variables affect the behavior of the STAFMon package.  These variables values may be changed to alter the behavior of the STAFMon package.

6.2 STAF::Monitor::Log

Description

Result

Examples

This example logs message "Hello World" to the Monitor service.

7.0 Package STAFLog

The STAFLog package provides a set of functions to ease the use of the Log service, as well as, variables which define the return codes from the Log service and variables which affect the operation of the utility functions provided. These functions also interface with the Monitor service to allow messages which are logged to also be monitored.

7.1 Log Service Variables and Return Codes

The following variables are defined, which represent the numeric return codes generated by the STAF Log service. For a complete description of these return codes and their meaning, please see the STAF User's Guide.

The following variables affect the behavior of the STAFLog package. These variables values may be changed to alter the behavior of the STAFLog package.

7.2 STAF::Log::Init

Description

Result

Examples

This example initializes the utility functions for global log file "Testcase1", setting the monitor mask to logging levels "FATAL ERROR".

7.3 STAF::Log::Log

Description

Result

This function returns a numeric return code. Return codes are documented in the STAF User's Guide.

The variables STAF::RC and STAF::Result will also be set based on the underlying STAF::Submit call.

Example

This example logs warning mesage "Unable to find specified file".