On This Page:
Table of Contents |
---|
EagleML REST API
The EagleML API 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.
Execute Requests in the Eagle ML APL Library
No Format |
---|
dependencies { compile 'com.eagleinvsys.eaglemlapi:eaglemlapiclient:1.2.0' } |
...
No Format |
---|
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. This example should be executed only once.
...
Code Block | ||||
---|---|---|---|---|
| ||||
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
The following is an example of a wait on a Future<IEagleApiResult> object.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// THIS IS A SAMPLE OF THE REQUEST EXECUTION. REQUESTS CAN BE EXECUTED ONLY AFTER THE eaglemlApi.start() is called. Map<String, String> parameters = new HashMap<String, String>(); // Add the parameters required to build an URI // Generate a unique correlationId // Add the attachments for the POST request Future<IEagleApiResult> futureResult = eaglemlApi.executeRestRequestAsync("GET", "/eagle/v2/manager-relationships", parameters, correlationId, null, 600 /* timeout in seconds */); try (IEagleApiResult result = futureResult.get()) { switch(result.getResultStatus()) { case EagleApiResultStatus.SUCCESS: List<IEagleApiResultDataFile> files = result.getDataFiles(); for (IEagleApiResultDataFile file : files) { // See the java doc for the IEagleApiResultDataFile. The file will represent one result. // Currently EaglemlApi will produce only one file. // You can get a stream of uncompressed data: try(InputStream stream = file.getStream()) { // Parse the extract and execute any transformations - for example to JSON } // If needed you can get the compressed data and get access to the file with the file.isInMemory(), file.getData(), file.getFile() // The temporary files (if any) created while processing the extracts will be removed when you close the IEagleApiResult instance. // If you want to preserve you'll have to move/copy them here. } break; case EagleApiResultStatus.TIMEOUT: // TIMEOUT - report an error break; case EagleApiResultStatus.ERROR: // ERROR - use result.getErrorMessage to get the error message break; case EagleApiResultStatus.STOPPED: // The request execution was stopped, when eaglemlApi.stop() is called break; case EagleApiResultStatus.NO_DATA: // The no data result retrieved. Report this back. break; } } |
Asynchronous Execution with a Callback
The following is an example of an asynchronous execution with a callback.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
• // THIS IS A SAMPLE OF THE REQUEST EXECUTION. REQUESTS CAN BE EXECUTED ONLY AFTER THE eaglemlApi.start() is called. Map<String, String> parameters = new HashMap<String, String>(); // Add the parameters required to build an URI // Generate a unique correlationId // Add the attachments for the POST request eaglemlApi.executeRestRequestAsync("GET", "/eagle/v2/manager-relationships", parameters, correlationId, businessTaskId, null, 600 /* timeout in seconds */, (result, exception) -> { if(exception != null) { // There was an exception while executing the request. Process it. } else { switch(result.getResultStatus()) { case EagleApiResultStatus.SUCCESS: List<IEagleApiResultDataFile> files = result.getDataFiles(); for (IEagleApiResultDataFile file : files) { // See the java doc for the IEagleApiResultDataFile. The file will represent one extract. // Currently EaglemlApi will produce only one file. // You can get a stream of uncompressed data: try(InputStream stream = file.getStream()) { // Parse the extract and execute any transformations - for example to JSON } // If needed you can get the compressed data and get access to the file with the file.isInMemory(), file.getData(), file.getFile() // The temporary files (if any) created while processing the extracts will be removed when you close the IEagleApiResult instance. // If you want to preserve you'll have to move/copy them here. } break; case EagleApiResultStatus.TIMEOUT: // TIMEOUT - report an error break; case EagleApiResultStatus.ERROR: // ERROR - use result.getErrorMessage to get the error message break; case EagleApiResultStatus.STOPPED: // The request execution was stopped, when eaglemlApi.stop() is called break; case EagleApiResultStatus.NO_DATA: // The extract resulted in no data retrieved. Report this back. break; } } }); |
Execute the Request Synchronously
You can execute the request synchronously by following the sample below. Requests can be executed only after the eaglemlApi.start() has been called.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// THIS IS A SAMPLE OF THE REQUEST EXECUTION. REQUESTS CAN BE EXECUTED ONLY AFTER THE eaglemlApi.start() is called. Map<String, String> parameters = new HashMap<String, String>(); // Add the parameters required to build an URI // Generate a unique correlationId // Add the attachments for the POST request try (IEagleApiResult result = eaglemlApi.executeRequestAsync("GET", "/eagle/v2/manager-relationships", parameters, correlationId, null, 600 /* timeout in seconds */)) { switch(result.getResultStatus()) { case EagleApiResultStatus.SUCCESS: List<IEagleApiResultDataFile> files = result.getDataFiles(); for (IEagleApiResultDataFile file : files) { // See the java doc for the IEagleApiResultDataFile. The file will represent one extract. // Currently EaglemlApi will produce only one file. // You can get a stream of uncompressed data: try(InputStream stream = file.getStream()) { // Parse the extract and execute any transformations - for example to JSON } // If needed you can get the compressed data and get access to the file with the file.isInMemory(), file.getData(), file.getFile() // The temporary files (if any) created while processing the extracts will be removed when you close the IEagleApiResult instance. // If you want to preserve you'll have to move/copy them here. } break; case EagleApiResultStatus.TIMEOUT: // TIMEOUT - report an error break; case EagleApiResultStatus.ERROR: // ERROR - use result.getErrorMessage to get the error message break; case EagleApiResultStatus.STOPPED: // The request execution was stopped, when eaglemlApi.stop() is called break; case EagleApiResultStatus.NO_DATA: // The extract resulted in no data retrieved. Report this back. break; } } catch(EagleApiException e) { // Process the exception }; |
Command Line Interface for Executing REST Requests
Synchronous Mode
To enable synchronous mode, enter the following in the console:
...
- 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:
...
- 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 | The username to log in the environment |
EAGLEAPIPASS | password | The 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 | The Endpoint address |
-file | file path | The path to the file with the query. |
-execution | sync or async | The execution mode. This can be synchronous or asynchronous. |
Query File Details
The file with the query is selected by the -file command, for example:
...
No Format |
---|
GET|/eagle/v2/manager-relationships?entityselectiontype=EntityID&entityselectionvalue=EMLFUN10&outputformat=XML|ABCDEF POST|/eagle/v2|ABCDEF|application/xml|test.xml |
Examples of Use
Synchronous Mode
In the example below, the EagleMLAPI Client is launched in synchronous mode from the command line.
...
No Format |
---|
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, two asynchronous requests are launched.
...