There are a few steps to take in order to create an Agent component
Creating the actions
Each Agent component contains at least one Agent action. These actions are Java methods, so they exist in regular Java classes.
Here we will make two Java classes with actions. These will be used in the different user guide pages related to performance testing.
A very simple action class
A class with just one action which accepts input arguments from the test and returns back some result.
package com.myproduct.actions; import com.axway.ats.agent.core.model.Action; import com.axway.ats.agent.core.model.Parameter; import org.apache.log4j.Logger; public class SimpleActions { // we can use this logger in order to log some messages private static final Logger log = Logger.getLogger( SimpleActions.class ); @Action() public String sayHi( @Parameter(name = "myName") String myName, @Parameter(name = "myAge") int myAge ) { // we log some message from this action log.info( "Remote action message: Called by '" + myName + "' who is " + myAge + " years old" ); // this action returns some data back return "Hello " + myName + ". You are " + myAge + " years old"; } }
Action class doing file transfers over FTP
This one is using the ATS FileTransferClient class which is able to transfer files over a variety of protocols.
But the ATS FileTransferClient class cannot run in parallel for many users, now we make a wrapper around it to make this possible.
package com.myproduct.actions; import com.axway.ats.agent.core.model.Action; import com.axway.ats.agent.core.model.Parameter; import com.axway.ats.action.filetransfer.FileTransferClient; import com.axway.ats.common.filetransfer.TransferProtocol; public class FileTransferActions { // this is the ATS client used for sending files over variety of transfer protocols private FileTransferClient transferClient; @Action public void connect( @Parameter(name = "hostname") String hostname, @Parameter(name = "port") int port, @Parameter(name = "username") String username, @Parameter(name = "password") String password ) { // make instance of the transfer client and do a connect transferClient = new FileTransferClient( TransferProtocol.FTP ); transferClient.setPort( port ); transferClient.connect( hostname, username, password ); } @Action public void upload( @Parameter(name = "localFilePath") String localFilePath ) { transferClient.uploadFile( localFilePath, "/" ); } @Action public void disconnect() { transferClient.disconnect(); } }
Important details about actions
- A Java method becomes an action when we annotate it properly.
- Any input action arguments must be annotated properly as well.
- The action method body can have any content you wish.
Creating a cleanup handler
Each Agent component must contain one (and only one) cleanup handler. It is invoked at the end of restore operation (after restore DB tables and files) to complete restore logic common for the whole component.
Here we will create a default cleanup handler:
package com.myproduct.actions; import com.axway.ats.agent.core.model.EnvironmentCleanupHandler; // Invoked at the end of restore, after individual DB tables and files are already restored public class SimpleCleanupHandler implements EnvironmentCleanupHandler { public void clean() { // just write your own Java code that will do something useful in your case } }
Creating an Agent descriptor file
Each Agent component has one description file called agent_descriptor.xml
See the one below:
<?xml version="1.0" encoding="UTF-8" ?> <component name="myproduct_actions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="agent_descriptor.xsd"> <actionClass name="com.myproduct.actions.SimpleActions"/> <actionClass name="com.myproduct.actions.FileTransferActions"/> <cleanupHandler name="com.myproduct.actions.SimpleCleanupHandler"/> </component>
Here are the important details:
- appropriate component name.
- list with actions classes
- the one and only cleanup handler
Proceed with building and deploying your component
Back to parent page
Go to Table of Contents