On This Page:
EagleML REST API
The EagleMLApi library can execute requests in asynchronous or synchronous mode.
The asynchronous mode receives the reply from EagleML API through a callback. The EagleML API client sends a REST request to MC2 and waits for the Task Status Reply and the extract data to be delivered asynchronously when ready via a callback.
The synchronous mode executes the request and waits for the TSR/reply on the same connection.
To use the library, add the following dependency:
dependencies { compile 'com.eagleinvsys.eaglemlapi:eaglemlapiclient:1.2.0' }
In the gradle.build
script add:
repositories { maven { url "http://inno-artifactory/artifactory/libs-release" } }
Initialization
Before using the EagleML API for REST calls it should be initialized as described here:
The above should be executed only once. After the initial request, you can execute multiple requests concurrently on the eaglemlApi object.
To stop the eaglemlApi instance and clean up the resources, run the following:
eaglemlApi.stop();
Execute the request Asynchronously
You can execute the requests only after EagleML Client API is started using the EagleApi.start() method.
You can execute the asynchronous requests in two modes:
- Wait on a Future<IEagleApiResult> object
- Asynchronous execution with a callback
Wait on a Future<IEagleApiResult> object
Asynchronous Execution with a Callback
Execute the Request Synchronously
Command Line Interface for Executing REST Requests
Synchronous Mode
To enable synchronous mode, enter the following in the console:
-execution=sync -rest
To launch a single request, you can determine all necessary parameters directly in console with the "-data=" option. For example:
-data="httpMethod|httpPath|basecorrid|contentType|pathToFile"
The contentType and pathToFile are optional.
When you want to launch several extracts or want to read all parameters from a file, use the "-file=" option:
-file="C:\Users\User\Documents\my_config.txt"
In synchronous mode, the client:
- Sends a REST request.
- Saves the response in the temporary folder with correlation id as its name. The temporary folder is the system %TEMP%. For example: C:\Users\admin\AppData\Local\Temp\. This folder is not purged automatically.
- Moves to the next request on the list.
Asynchronous Mode
To enable asynchronous mode, enter the following in the console:
-execution=async -rest
To launch a single request you can determine all necessary parameters directly in console with the "-data=" option. For example:
-data="httpMethod|httpPath|basecorrid|contentType|pathToFile"
When you want to launch several requests or want to read all parameters from a file, use the "-file=" option:
-file="C:\Users\User\Documents\my_config.txt"
In asynchronous mode, the client executes the following steps.
- Creates a callback. It is represented by a Jetty HTTP Servlet server which starts to listen on a random free port. You can set a timeout here. When it expires, the callback is unregistered and the timeout error is displayed. For example, a 5 min t/o:
-timeout=300
2. The client then executes REST request. The request contains x-eagle-rest-callback header with the IP address of the Eagle API client, the communication port and /eagleapicallback suffix. For example:
x-eagle-rest-callback: http://99.99.99.999:63345/eagleapicallback
3. When the server receives a request with x-eagle-rest-callback header, it sends the TaskAcknowledged (ACK) message back to the client, performs the request, archives the result data, then tries to send a multipart message consisting of the TaskStatusResponse and the result data.
4. The client receives the ACK and waits for incoming multiparts (TSR+data).
5. On multipart arrival it switches off the callback (the port is free now).
6. Parses the TaskStatusResponse to understand if its task status is SUCCESS, FAILED or NO_DATA.
- If the status is SUCCESS, the result data is uploaded as an archive file and saved in the temporary folder with correlation id as its name. The temporary folder is the system %TEMP%. For example: C:\Users\admin\AppData\Local\Temp\. This folder is not purged automatically.
- If a folder is specified in the resultsdir parameter, the result data is unzipped and stored in this particular folder.
- If “resultsdir” is not specified or empty, the extract remains unzipped in the temp folder.
- If the status is FAILED or NO_DATA, an error description is displayed.
- If the multipart does not arrive before the timeout expires, the callback is unregistered and a timeout error is displayed.
Available Settings
Name | Valid Values | Description |
---|---|---|
-login | username | Username to log in the environment |
EAGLEAPIPASS | password | Password for the environment set as a global system variable. Can be defined in the command line, for example: set EAGLEAPIPASS=my_password |
-resultsdir | empty or folder path | The folder in which unzipped result file will be stored. If not specified, the result will remain unzipped in the temp folder |
-csvmetricsdir | empty or folder path | The folder in which metrics will be stored |
-threads | even number, 1 or greater | Defines the number of separate threads for an async process. For each thread a separate listener are created. |
-endpoint | address of the environment | Endpoint address |
-file | file path | Path to the file with the query |
-execution | sync or async | Execution mode - synchronous or asynchronous |
Query File Details
The file with the query is selected by the -file command, for example:
-file="C:\Users\User\Documents\my_config.txt"
It should be formatted as follows:
httpMethod|httpPath|basecorrid|contentType|pathToFile
contentType and pathToFile are not necessaryoptional.
For example:
GET|/eagle/v2/manager-relationships?entityselectiontype=EntityID&entityselectionvalue=EMLFUN10&outputformat=XML|ABCDEF POST|/eagle/v2|ABCDEF|application/xml|test.xml
Example of Use
Synchronous Mode
In the example below, the EagleMLAPI Client is launched in synchronous mode from the command line.
- The request is formed in this query:
-data="GET|/eagle/v2/manager-relationships?entityselectiontype=EntityID&entityselectionvalue=EMLFUN10&outputformat=XML|ABCDEF"
- To start execution, execute the following command:
SET EAGLEAPIPASS=eagle1 java -jar eaglemlapiclient-1.0.3-SNAPSHOT.jar "-data=GET|/eagle/v2/manager-relationships?entityselectiontype=EntityID&entityselectionvalue=EMLFUN10&outputformat=XML|ABCDEF" -execution=sync -login=eagleadmin -endpoint=http://sbnyl1312qa003.eagleinvsys.com:20427 -rest
Asynchronous Mode
In this example, 2 asynchronous requests are launched.
- The requests are formed from the request.txt query file located in testFolder:
GET|/eagle/v2/manager-relationships?entityselectiontype=EntityID&entityselectionvalue=EMLFUN10&outputformat=XML|ABCDEF GET|/eagle/v2/manager-relationships?entityselectiontype=EntityID&entityselectionvalue=EMLFUN10|ABCDEF
Two queries are executed in parallel (-threads=2)
- To start execution, execute the following command:
SET EAGLEAPIPASS=eagle1 java -jar eaglemlapiclient-1.0.3-SNAPSHOT.jar "-data=GET|/eagle/v2/manager-relationships?entityselectiontype=EntityID&entityselectionvalue=EMLFUN10&outputformat=XML|ABCDEF" -login=eagleadmin -endpoint=http://sbnyl1312qa003.eagleinvsys.com:20427 -threads=2 -rest