STAF Learning Note-A

Source: Internet
Author: User
Tags deprecated semaphore


The main contents include:

1. Stax's related introduction

2. Registering Staf as a Windows platform service

3.STAF Main class parsing: the example is located under STAF's installation directory \staf\samples\demo. If you need to import a Java file into eclipse, you need to load the jar file for STAF, located under C:\STAF\services\stax. Mainly has Stafevent.jar,stax.jar,staxdoc.jar,staxmon.jar


Three

3STAF Main class parsing:

Take Stafdemocontroller as an example, this example is located under STAF's installation directory \staf\samples\demo. If you need to import a Java file into eclipse, you need to load the jar file for STAF, located under C:\STAF\services\stax. Mainly has Stafevent.jar,stax.jar,staxdoc.jar,staxmon.jar

There are four main classes for a Java application:

Stafhandle: This class handles registering and Unregistering with STAF as well as submitting service requests.
stafexception: This class was thrown by Stafhandle when errors was encountered.
Stafresult : This class contains the result of the Stafhandle.submit2 () method as well as the STAF error constant S.
Stafutil: This class contains STAF utility functions.

Each Java application has and can only create one Stafhandle object.

Example: Create a Stafhandle object.

static Stafhandle handle;
try{
handle = new Stafhandle ("Stafdemo_controller");
}catch (stafexception e)
{
SYSTEM.OUT.PRINTLN ("Error registering with STAF, RC:" + e.rc);
System.exit (E.RC);
}

If you want to unregister the service, you can use Handle.unregister ()


To submit a service request:

Service requests May is submitted by one of the following methods:
L The Submit () method works in the traditional Java fashion, in that it throws an exception (a stafexception in
particular) if it encounters an error, and it returns a result string on success.
L The Submit2 () method returns a Stafresult object in all cases. This object contains the real STAF return code as
well as the result string. It is typically used in places where you wish to avoid catching exceptions when using
STAF.


Format of the STAF command:

The first parameter is where the STAF request was to be executed. In this case, it'll be executed locally.
The second parameter is the STAF Service where the request should be routed. In this case, it is the "var"
(Variable) service.
The third parameter is the actual request to being sent to the STAF Service. The request is to resolve the
String "{Staf/config/machine}".

That

Each request has three parameters, in the form of a system-service-parameter. The first parameter indicates that the request needs to be sent to the STAF system, which is stafproc resolved to determine whether the request should be handled locally or sent to another STAF system. When the request is sent to the STAF system that needs to be processed, Stafproc parses the second parameter to determine which service is called. Finally, Stafproc forwards the third parameter to the service that needs to be called, and the service handles the request.

Explanation of some terms:

External services:services for which the executable code for the service resides outside of Stafproc, and which must B e registered in the STAF configuration file. Some external services, such as LOG, are
Provided with STAF. Others is available from the STAF Web site and must is downloaded and installed.
Handle A:unique identifier which is used when submitting requests to STAF.
Internal services:services for which the executable code resides within Stafproc
PROCESS:A process is an object which can being executed on A test machine. Examples of processes Are:executables, shell scripts, etc.
Request:a string, sent to A service, which describes the operation the service was to perform.
Services:reusable components, provide all, the capability in STAF. Each STAF service provides a specific set of functionality and defines a set of requests that it would accept.
Staf:an Automation framework designed around the idea of reusable components
STAF command:a STAF command consists of A machine, service, and request. The request is sent-the Machine,the service on the machine processes the request, and returns a return code and a Resul T, if any.
Stafpro:the Daemon process which runs on each STAF system.

4 staf configuration file in detail:

The default configuration file is located in the STAF installation directory \staf\bin
# Turn on tracing of internal errors and deprecated options
Trace enable tracepoints "Error deprecated"

# Enable TCP/IP connections
Interface SSL Library staftcp option secure=yes option port=6550
Interface TCP Library staftcp option secure=no option port=6500

# Set Default Local Trust
Trust machine local://local Level 5

# ADD Default Service Loader
Serviceloader Library Stafdsls

You can also choose a different configuration file yourself, but you must add the parameter name when you start using your own profile.

Example: C:\Documents and settings\administrator>stafproc C:\STAF\bin\test.cfg

Machine:ibm-r86m1cv.cn.ibm.com
Machine Nickname:testmachine1
Startup time:20110914-14:21:14

Stafproc version 3.4.2 initialized

Meaning in the configuration file:

Trace Enable tracepoints "error deprecated". Form trace information When an error condition occurs

Interface TCP Library STAFTCP: Send and accept STAF requests on the network, the default port is 6500. If you need to define your own ports, you can use interface TCP library staftcp option secure=no option port=6600
Trust machine local://local levels: Set local machines to full access confidence level
Serviceloader Library STAFDSLS: Register the default service Loader. Services such as Log,monitor can be loaded dynamically
In addition
Machinenickname can be used to set the machine alias
Use set to set var variable to view STAF var List:staf local var list


The trust Level 5 machine tcp://client1.austin.ibm.com is used to set the credit rating. Use the command Staf Local trust list. You can view the trusted machines on this machine.

5 Common commands for STAF:

Many of the commands have been described in the previous section and are not repeated.

1.List HANDLE:STAF Local handle List handles

2. Check the service's Help: STAF Local Service assist

C:\Documents and Settings\administrator>staf LOCAL SHUTDOWN Help
Response
--------
SHUTDOWN Service Help * * *

SHUTDOWN

NOTIFY REGISTER [Machine <machine>] [HANDLE <Handle> | NAME <name>]
[Priority <priority>]
NOTIFY UNREGISTER [Machine <machine>] [HANDLE <Handle> | NAME <name>]
[Priority <priority>]
NOTIFY LIST

Help

3ping machine to determine whether access via STAF

C:\Documents and Settings\administrator>staf local ping Ping
Response
--------
PONG

C:\Documents and Settings\administrator>staf 10.6.125.164 Ping Ping
Response
--------
PONG

4 shutdown STAF:

STAF Local shutdown shutdown

5 Submit request via the command line:

The syntax of this command is:
STAF <Endpoint> <Service> <Request>
<Endpoint> is either local, if you wish to make a request for the local machine, or the name of the
Which wish to make a request
<Service> is the name of the Service, that would receive and process the request
<Request> is the service Request


6 last additions to the STAF architecture:

Sentence: Point to point

STAF runs as a daemon process (called Stafproc) on the each system. So, for example, if wanted to run STAF on your
Office machine and 5 test machines in a lab, you would install STAF to all 6 systems. Then, to use the STAF in this
Environment, you would the start Stafproc on all 6 machines. The collection of machines on which you have installed
STAF is referred to as the STAF environment.
STAF operates in a peer-to-peer environment; In other words, there is no client-server hierarchy among machines running
STAF. Figure 1 illustrates, the Stafproc daemons serve as the communication mechanism over the network






Two

STAX uses three technologies: STAF, XML, and Python. Simply put, STAX provides some interfaces on top of STAF, enabling users to manipulate STAF for automated testing.

Describe the concepts and mechanisms used in STAF and STAX.

1.1 Services (Service)

STAF builds an automated test framework based on reusable components, the reusable components of which are services. All the components in the STAF are services. A service is a collection of a series of features. STAF itself is a background program (STAFPROC) that provides a lightweight distribution mechanism that is responsible for forwarding requests to these services.

The services in STAF are divided into two types: internal (internal service) and external (external service). Internal services are integrated into the STAFPROC, providing key features such as data management and synchronization. External services are dynamically loaded by Stafproc and accessed through shared libraries (GKFX libraries).

STAF provides several common services: a program invocation service (Process Service): An internal service that, using this service, STAF can invoke external programs. File System Services (FileSystem Service): Internal service, using this service, STAF can operate on the file system, such as copy, delete, view and so on. Log service: An external service that helps users record and view logs. Resource Pool Services (Respool service): External services that provide management and operations for resource pools, such as view, create, and delete operations. Monitoring Services (monitor Service): External services that provide monitoring capabilities for the STAF runtime. Semaphore Service (Sem Service): An internal service that provides two semaphore operations, mutexes and event. Compression Services (ZIP service): External services that provide compression and decompression capabilities. Ping Service: Internal service, similar to the ping function of the operating system, to detect whether a remote STAF is running. Variable Services (Var service): An internal service that provides operations for system or user-level environment variables.

STAF also provides delays (delay service), help service, tracking (trace service) and other services, not listed here.

1.2 Request-Response format

Each service defines the format of the request it can accept. STAF invokes the functionality of the service through a request, and each request is sent as a string, which guarantees that the STAF can run across the platform. Each request has three parameters, in the form of a system-service-parameter. The first parameter indicates that the request needs to be sent to the STAF system, which is stafproc resolved to determine whether the request should be handled locally or sent to another STAF system. When the request is sent to the STAF system that needs to be processed, Stafproc parses the second parameter to determine which service is called. Finally, Stafproc forwards the third parameter to the service that needs to be called, and the service handles the request.

When the request is processed, the service returns two kinds of data: The return code and the request-specific information. The return code represents the result of the service processing. The request-specific information represents the specific data returned by the service, and if the request is returned successfully, the information will include the data requested by the request, which will contain additional diagnostic information if the request appears to be an error.

Full use of strings as request-response formats can simplify many aspects of STAF, including interfaces with other languages, communication between services, cross-platform operations, and so on. Other languages require only one interface Stafsubmit () to request STAF services, and only three string parameters are passed. The service also only needs to send a receive request through a string.

1.3 STAX

STAX is a STAF-based execution engine that provides a workflow language in XML format. Users can write XML script files to invoke STAF's service through STAX to complete automated testing. Users can open their own automated test environment without having to deal with the programming language. STAX provides the following features: support for parallel operation, user-defined run control granularity, nested test cases, control of run time, support for existing Java and Python modules, etc. STAX also provides a graphical monitoring tool through which the user can clearly see the location of the test run, status and error messages. Below we will demonstrate the capabilities of STAF and STAX by automating deployment with FTP and CVS.

3 Register STAF as a Windows platform service.

STAF does not provide power-on auto-start function, on the Windows platform, only when a user logs on, the STAF will start. This is not a good news for the environment of automated testing. So we need to start STAF automatically, which is simpler on Linux, as long as/etc/rc.d/rc.local (if it's SuSE Linux, or/etc/rc.d/boot.local) joins the STAF boot command/usr/ Local/staf/bin/stafproc & is ready. The Windows platform is not so convenient, so this section describes how to register STAF as a service for Windows so that it can be restarted automatically. First use the INSTSRV command to register a basic service staf:instsrv STAF C:\winnt\system32\srvany.exe. Open Registry Editor (regedit) to find the key value of My Computer\hkey_local_machine\system\controlset001\services\staf. Create a key under STAF with the name Parameters. Under the Parameters key, create a string value, named Application, with a value of Stafproc full path, such as C:\STAF\bin\STAFProc.exe. Use the command services.msc to start the Windows Service window, locate Staf, right-select the property, and navigate to the login window and select "Allow service to interact with the desktop." Use the command net start Staf or restart the machine to start the STAF service. Use the command STAF Local Service list to verify that the STAF has started successfully. (This method should also be able to register other services as Windows platform services, write down, may be used later)

Reference articles:

http://www.ibm.com/developerworks/cn/opensource/os-cn-staf/


One

installation and download of STAF:

http://staf.sourceforge.net/

STAF installation is simple, just follow the wizard prompts. After the installation is complete, you can start STAF with the Stafproc command.

Close STAF can be used with the following command: STAF local shutdown shutdown.

After downloading STAX, unzip it to the $STAF _install_directory\services\stax directory, and then change the STAF profile staf.cfg. This file is under the $STAF _install_directory\bin directory. Add the following code at the end of the Staf.cfg file, and then restart STAF.

SERVICE STAX LIBRARY jstaf EXECUTE {staf/config/stafroot}/services/stax/stax.jar \
OPTION j2=-xmx384m
SERVICE EVENT LIBRARY Jstaf EXECUTE \
{Staf/config/stafroot}/services/stax/stafevent.jar
SET Maxqueuesize 10000

After installation, you can view Staf's service by command

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and SETTINGS\ADMINISTRATOR&GT;STAF Local Service list
Response
--------
Name Library Executable
--------- ---------- -----------------------------------
DELAY <Internal> <None>
DIAG <Internal> <None>
ECHO <Internal> <None>
EVENT Jstaf C:\staf/services/stax/stafevent.jar
FS <Internal> <None>
HANDLE <Internal> <None>
Help <Internal> <None>
LIFECYCLE <Internal> <None>
LOG Staflog <None>
MISC <Internal> <None>
PING <Internal> <None>
PROCESS <Internal> <None>
QUEUE <Internal> <None>
SEM <Internal> <None>
SERVICE <Internal> <None>
SHUTDOWN <Internal> <None>
STAX Jstaf C:\staf/services/stax/stax.jar
TRACE <Internal> <None>
TRUST <Internal> <None>
VAR <Internal> <None>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.