Hands-On Automation with STAF/STAX 3 - Part 3


Exercise 3.1 - Using the FSExt, Zip, Monitor, Respool, Sem. Trust, Service, Delay, Misc, and LifeCycle services

Objective - Learn how to use the FSExt, Zip, Monitor, Respool, Sem. Trust, Service, Delay, Misc, and LifeCycle services

  1. From the STAF CD, unzip file Part3\install\FSExtV302.zip to C:\STAF\services.

  2. Edit the C:\STAF\bin\STAF.cfg file and add the lines
    service fsext library JSTAF execute C:/STAF/services/fsext/STAFFSExt.jar
    Save the changes to the STAF.cfg file and restart STAF.

  3. From a command prompt, type
    staf local fsext filecontains file C:/STAF/bin/STAF.cfg string email
    you should get back an empty result buffer, since the STAF.cfg does contain the string "email".

  4. From a command prompt, type
    staf local fsext filecontains file C:/STAF/bin/STAF.cfg string emailXTZ
    you should an RC 4006.

  5. From a command prompt, type
    staf local help service fsext error 4006
    you should help for this return code. Note that service-specific return codes are in the 4000+ range.

  6. From a command prompt, type (substituting the correct location for <STAFCD>)
    staf local zip list zipfile <STAFCD>/Part2/install/STAXV345.zip
    you should see the contents of the zip file.

  7. We will need a static handle for the next several services. From a command prompt, type
    staf local handle create handle name MyHandle
    you should get back a handle number (for our examples we will use "33", but you should use the handle number you just received)
    set STAF_STATIC_HANDLE=33

  8. From a command prompt, type
    staf local monitor log message "We are doing Exercise 3.1"

  9. From a command prompt, type (substitute your handle for "33")
    staf local monitor query machine {STAF/Config/MachineNickname} handle 33
    you should get the status returned.

  10. From a command prompt, type
    staf local respool create pool exercise3.1 description "Respool for exercise 3.1"
    this will create the resource pool.

  11. From a command prompt, type
    staf local respool add pool exercise3.1 entry abc1 entry abc2
    this will add 2 entries to the resource pool.

  12. From a command prompt, type
    staf local respool request pool exercise3.1
    staf local respool request pool exercise3.1
    this will acquire the 2 entries in the resource pool.

  13. From a command prompt, type
    staf local respool request pool exercise3.1 timeout 10000
    this will another entry from the resource pool, and wait for a maximum of 10 seconds. You should see the request wait for 10 seconds and then return an RC 37.

  14. From a command prompt, type
    staf local help error 37
  15. From a command prompt, type
    staf local respool query pool exercise3.1
    this will display information about the resource pool.

  16. From a command prompt, type
    staf local respool delete pool exercise3.1 confirm force
    this will delete the resource pool.

  17. From a command prompt, type
    staf local sem request mutex myMutex
    this will acquire the "myMutex" mutex semaphore.

  18. From a new command prompt, type
    staf local sem request mutex myMutex
    notice that this hangs because the semaphore is in use.

  19. Back in the original command prompt, type
    staf local sem release mutex myMutex
    notice that this handle has released the semaphore and the request in the new command prompt window should have returned since the semaphore was available.

  20. From a command prompt, type
    staf local trust list
    this will list all of the trust settings on the machine.

  21. From a command prompt, type
    staf local service list
    this will list all of the registered services on the machine.

  22. From a command prompt, type
    staf local delay delay 10000
    this will delay for 10 seconds.

  23. From a command prompt, type
    staf local misc whoami
    this will delay information about who the machine thinks you are.

  24. From a command prompt, type
    staf local lifecycle register phase Startup
        machine local service process request "start command notepad"
    This will register a request with the LifeCycle service so that the Notepad process is started when STAFProc starts. Note that the registration ID (1) is returned.

  25. From a command prompt, type
    staf local lifecycle list
    This will list all of the requests currently registered with the LifeCycle service.

  26. From a command prompt, type
    staf local lifecycle query id 1
    This will query the information about the request you previously registered.

  27. Shutdown STAFProc and restart it. Verify that during the startup the Notepad process is started.

  28. From a command prompt, type
    staf local lifecycle unregister id 1
    This will unregister the request.


Exercise 3.2 - Using the Namespace, Email, Event, EventManager, Cron, HTTP, and FTP services

Objective - Learn how to use the Namespace, Email, Event, EventManager, Cron, HTTP, and FTP services

  1. From the STAF CD, unzip file Part3\install\NamespaceV102.zip to C:\STAF\services.

  2. From the STAF CD, unzip file Part3\install\CronV338.zip to C:\STAF\services.

  3. From the STAF CD, unzip file Part3\install\EventManagerV338.zip to C:\STAF\services.

  4. From the STAF CD, unzip file Part3\install\HTTPV302.zip to C:\STAF\services.

  5. From the STAF CD, unzip file Part3\install\FTPV103.zip to C:\STAF\services.

  6. Edit the C:\STAF\bin\STAF.cfg file and add the lines
    service cron library JSTAF execute C:/STAF/services/cron/STAFCron.jar
    service eventmanager library JSTAF \
        execute C:/STAF/services/eventmanager/STAFEventManager.jar
    service namespace library JSTAF execute C:/STAF/services/namespace/Namespace.jar
    service http library JSTAF execute C:/STAF/services/http/STAFHTTP.jar
    service ftp library JSTAF execute C:/STAF/services/ftp/STAFFTP.jar
    Save the changes to the STAF.cfg file and restart STAF.

  7. From a command prompt, type
    staf local namespace create namespace Part3Exercises description "Exercises for Part 3"
    staf local namespace set var Exercise=3.2 namespace Part3Exercises
    staf local namespace query namespace Part3Exercises
    staf local namespace list namespace Part3Exercises
  8. Now shutdown STAF and restart it. Run the following commands and verify you get the same output as the previous step:
    staf local namespace query namespace Part3Exercises
    staf local namespace list namespace Part3Exercises
    
  9. From a command prompt, type (substituting your email address for <user>)
    staf local email send to <user>@us.ibm.com subject "Test Message"
        message "Hello and Welcome to STAF/STAX"
    go to your Inbox and you should see the email.

  10. From a command prompt, type
    staf local eventmanager register machine local service process
        request "start command notepad" type abc subtype xyz
    
    this will register with the EventManager service so that it will call the Process service to execute "Notepad" whenever an event of type "abc" and subtype "xyz" is generated. Note that the registration ID is returned.

  11. From a command prompt, type
    staf local event generate type abc subtype xyz
    
    this will generate an event with type "abc" and subtype "xyz". This should cause the notepad process to start on your machine.

  12. From a command prompt, type (substituting the correct registration ID, if it is not 1)
    staf local eventmanager unregister id 1
    
  13. From a command prompt, type
    staf local cron register machine local service process
        request "start command notepad" minute any
    
    this will register with the Cron service so that it will call the Process service to execute "Notepad" every minute. Note that the registration ID is returned. Let several minutes pass by, and you should see the notepad process started every time the minute changes.

  14. From a command prompt, type (substituting the correct registration ID, if it is not 1)
    staf local cron unregister id 1
    

  15. From a command prompt, type
    staf local http open session
    
    this will open a new session. Notice that the session ID is returned in the result buffer.

  16. From a command prompt, type
    staf local HTTP DOGET URL http://money.cnn.com/quote/quote.html/?symb=IBM RETURNNOCONTENT SESSION 1
    
    this will get the current IBM stock quote.

  17. From a command prompt, type
    staf local HTTP GET SESSION 1 CONTENT FILE c:/temp/ibmquote.html
    
    this will store the current contents of a session (1) in a file (c:/temp/ibmquote.html). The c:/temp/ibmquote.html file should be an html file equivalent to acquiring the page in a browser.

  18. Open a browser and navigate to the c:/temp/ibmquote.html file, which should contain the current IBM stock quote.

  19. From a command prompt, type
    staf local FTP HELP
    this will display the help for the FTP service. If you have access to an FTP site, try submitting some commands to the FTP site via the STAF FTP service.


Exercise 3.3 - Using STAF marshalled data

Objective - Learn how to use STAF marshalled data


  1. When structured data is returned in the result strings above, the STAF command will automatically unmarshall the data and print it in the most appropriate format

  2. For example, run the following command:
    staf local fs list directory c:/
    
    Since the data is a <List> of <String>, then each entry in the list will be printed on its own line.

  3. Next, run the following command:
    staf local log list settings
    
    Since the data is a <Map> which has values which are all of type <String>, then each key/value pair will be printed on its own line. These last 2 examples of formatted output are frequently referred to as "default format".

  4. Next, run the following command:
    staf local handle list handles
    
    Since the data is a <List> where every item in the list is an instance of the same map class, then the data will be printed out in a tabular format, called "table format".

  5. Next, run the following command:
    staf -verbose local handle list handles
    
    You can use the -verbose option to disable the table format. Instead, the output will be printed in a hierarchical nested format, called "verbose format". You can force the exclusive use of the verbose mode by setting the environment variable STAF_PRINT_MODE to "verbose".

  6. Next, run the following commands:
    staf local sem reset event Test
    staf local sem wait event Test
    

  7. From another command prompt, run the following command:
    staf local sem wait event Test
    

  8. From another command prompt, run the following command:
    staf local sem wait event Test
    

  9. Now, from another command prompt, run the following command:
    staf local sem query event Test
    
    Notice that since the data is more complex, the output will be printed in a hierarchical nested format.