Oracle provides specific REST APIs for many of its cloud offerings, however one API in particular is useful for multiple cloud products – the Migration API. This API is sometimes referred to as the “LCM” API or the “interop” API. Regardless of the name, this is the API that provides Lifecycle Management functionality for EPM Cloud products.
If you’ve never worked with any of Oracle’s EPM REST APIs, have a look at my previous post here on the PBCS REST API. This will give you some context and background on the subject. We will be using Groovy for all examples. Steps for installing Groovy can be found within this post.
Using the Migration API, developers can perform the following tasks:
- Get API Versions and Details
- List Files in the Inbox/Outbox
- Upload Files to the Inbox/Outbox
- Download Files from the Inbox/Outbox
- Delete Files from the Inbox/Outbox
- List Available Services
- Restart a Service Instance
- Reset a Service Instance
- Upload/Download Application Snapshots
- Initiate LCM Imports & Exports
- Send Feedback Reports to Oracle
- Generate a User Provisioning Report
- Generate a User Audit Report
Some of the tasks above are not great candidates for automation. For example, it would be highly unusual to reset your service instance in an automated manner. I also wouldn’t recommend sending Oracle feedback in any automated fashion. They may have some “feedback” for you . . . with that said, there are some extremely useful features of the Migration API, and we will cover them below.
A Word About the Common Helper Functions . . .
As noted in previous posts, the Common Helper Functions offer a significant head start in automating an EPM environment. This post will reference many of these functions while illustrating how to put them together into a cohesive script.
** NOTE – Each section below has a link where readers may download the code samples.
After opening the Groovy Console, we will need to import some classes from the groovy.json package. If you’re unfamiliar with JSON, it’s basically a format for passing arrays commonly used in REST APIs. The code below will import the appropriate package (no need to download any additional jar files – these come with Groovy):
Next, we must define variables for our EPM environment and authentication. If you’ve read my previous post on the PBCS REST API, these should look familiar. You will need to update these with your instance information and credentials.
First Things First – Determine the API Version
It’s important to note that the API versions for the various EPM products can differ. The current version for the PBCS API is “V3”, however the Migration API version is “220.127.116.11.600”. Several functions require the API version, and they will not work if the wrong API version is passed as a parameter.
To get the current Migration API version, we will need the following functions from the Common Helper Functions:
Copy and paste these functions into your Groovy script below the EPM Instance Variables, then insert a line to call the getLCMVersions() function.
At this point, your code should look something like this.
Run your script and review the results in the Groovy Console output window:
At this point, it’s a good idea to define a variable apiVersion, and assign that variable a value within the getLCMVersions() function.
Listing the Files in the Inbox/Outbox
Now that we have the correct API version, we can perform some of the more interesting functions of the Migration API. For example, we can list the contents of the Inbox/Outbox. To do this, add the listFiles() function from the Common Helper Functions to your Groovy script. Then call the function as follows:
Run the script and review the list of files in the Groovy Console output window. At this point, your code should look something like this.
Uploading Files to the Inbox/Outbox
To add files to the Inbox/Outbox, we need to copy the following four functions from the Common Helper Functions into our Groovy script:
Note that the sendRequestToRest() function leverages a third-party library called JSON-lib. To use this library, download the java-json.jar file from http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip and unzip it into the C:\Program Files (x86)\Groovy\Groovy-2.4.6\lib directory. Add the following line (highlighted in yellow) to the top of your Groovy script and you’re ready to go!
Out of the box, the functions above will get the job done, however uploading files from a specific directory produces some undesirable behavior. For example, if we have a local file called C:\Temp\Test_File.txt, and we upload that file, here’s what shows up in the Inbox/Outbox:
Notice that the file path gets baked into the file name. We didn’t want to upload a file called “C:\Temp\Test_File.txt”. We wanted a file called “Test_File.txt”, and it just happened to be originally located in the C:\Temp directory (which is irrelevant once the file is uploaded).
We can rectify this situation by modifying the uploadFile() function, separating parameters for the directory and file name. Modify the uploadFile() function by adding the sections highlighted in yellow below:
Next, call the uploadFile() function with two separate parameters for the directory and file name. Note the double-slashes below.
Running the script now uploads the file to the Inbox/Outbox with the correct file name.
At this point, your code should look something like this.
Downloading Files from the Inbox/Outbox
To download files from the Inbox/Outbox, we need to copy the following function from the Common Helper Functions into our Groovy script:
Developers may find that this function benefits from a couple of key changes. The downloadFile() function doesn’t allow developers to specify a target directory for the downloaded file. By adding a parameter for the directory, and updating the saveFilePath, we can specify the target directory. Modify the function as follows (note the sections highlighted in yellow):
After successfully running the function, you may notice that Groovy doesn’t “release” the downloaded file. Trying to delete the file in Windows File Explorer results in the following error:
The only way to get past this error is to close the Groovy console completely. Upon inspection, it looks like the code opens an output stream, but never closes it. This is easily rectified by inserting the line below (highlighted in yellow) into the function:
After making the changes above, developers should be able to download files from the Inbox/Outbox to any local directory.
Test the downloadFile() function by calling it at the end of the Groovy script. Note the two parameters used by the function.
If you’ve been following along this whole time, that’s awesome! Your code should look something like this.
Bed Time . . .
In Part 2 of this post we will cover the remaining aspects of the Migration API . . . Artifact Snapshots, LCM and User Reports. Check back soon – I should have it posted by the end of next week!
One More Thing
I’m speaking at OpenWorld this year! My presentation on Essbase Hybrid Aggregation Mode will be in Moscone South – Room 303 on Sunday 9/18 at 1pm.