Dayalan Punniyamoorthy Blog

Wednesday, November 29, 2017

Explore Migration REST API - Oracle PBCS with Groovy flavor !!!

I hope you have enjoyed the Introduction and the Planning REST API posts which were posted earlier. Lets explore the Migration related REST API for the Oracle PBCS in this post.




Migration REST APIs


Use the Migration REST APIs to get API versions, work with files, and manage
services and application snapshots.



1.Getting API Versions for Migration APIs

This function will retrieve the information about the available Migration API version.
Output of the Program


2. Get Information About a Specific REST API Version for Migration

This function returns information about the specific version

Output of the program 

3.Upload and Download Files

3.1 Download

Downloads an application snapshot from the Oracle Planning and Budgeting Cloud
repository to the local environment.

Pasting the code since couldn't capture it as a screenshot.

// Download File Function
def downloadFile(filename) {
def url;
try {
String encodedFileName = URLEncoder.encode(filename, "UTF-8");
url = new URL(serverUrl + "/interop/rest/" + apiVersion + "/applicationsnapshots/" + encodedFileName + "/contents");
} catch (MalformedURLException e) {
println "Malformed URL. Please pass valid URL"
System.exit(0);
}
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", basicAuth);
int statusCode
try {
statusCode = connection.responseCode;
} catch (all) {
println "Error connecting to the URL"
System.exit(0);
}
if (statusCode == 200) {
InputStream is;
if (connection.getContentType() != null && connection.getContentType().contains("application/json")) {
is = connection.getInputStream();
if (is != null) {
response = fetchResponse(is)
def object = new JsonSlurper().parseText(response)
println "Error occurred while downloading file"
if (object.details != null)
println "Error details: " + object.details
}
} else {
final int BUFFER_SIZE = 5 * 1024 * 1024;
saveFilePath = path + filename
File f = new File(saveFilePath);
is = connection.getInputStream();
FileOutputStream outputStream = new FileOutputStream(f);
int bytesRead = -1;
byte[] buffer = new byte[BUFFER_SIZE];
while ((bytesRead = is.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
println "Downloaded "  + filename + " successfully";
}
} else {
println "Error occurred while executing request"
println "Response error code : " + statusCode
InputStream is = connection.getErrorStream();
if (is != null && connection.getContentType() != null &&
connection.getContentType().startsWith("application/json"))
println fetchJobStatusFromResponse(fetchResponse(is))
System.exit(0);
}
connection.disconnect();
}

Specifying the file name to download
 Output of the Program


3.2 Upload


4. View and Delete Files

Use these REST APIs to list and delete files.

4.1 List Files

Lists the files in the Oracle Planning and Budgeting Cloud repository and returns information about the available file and application snapshots. It provides details such as name, type, size and last modified time. Size and last modified are not available for LCM snapshots.

Function to list the files

Output of the Program

4.2 Delete Files

Deletes a file from the Oracle Planning and Budgeting Cloud repository.

Function to delete a file

Output of the Program

5. Manage Services

You can manage all available services using the following REST resources

5.1 Get Information About All Services

Returns information about all services that you can perform in an Oracle Planning and Budgeting Cloud instance.

Function to get migration services

Output of the Program
If you run the same program with the url = new URL(serverUrl + "/interop/rest/" + apiVersion)
It does give you this output.


5.2 Run Recreate on a Service

Recreates an Oracle Planning and Budgeting Cloud instance environment and sets it to its base settings.



Output of the Program

5.3 Restart the Service Instance 

Function to restarts the service instance.

Output of the Program


6.Manage Application Snapshots

You can manage the file system artifacts or application snapshots using the following REST resources.

6.1 Get Information About All Application Snapshots 

This API returns information about all application snapshots that are available in an Oracle Planning and Budgeting Cloud instance. It provides details such as name, type, size, and last modified time. Type signifies whether it is a Migration snapshot or an external snapshot. Size and last modified time are not available for Migration type snapshots.

Function to get the details


Output of the Program

6.2 Get Information About a Specific Application Snapshot

Returns information about all the operations that can be performed on a particular application snapshot. It provides details on operations such as Migration import and export, upload, download, and delete.

Function to retrieve the information about a specific snapshot

 Output of the Program


7. Use the Application Snapshot Service 


7.1 Upload Application Snapshot 

This is already covered under upload, use the same function to upload a snapshot.

7.2 Download Application Snapshot

This is already covered under download , use the same function to upload a snapshot.


7.2 Copy Application Snapshot 

This API copies a snapshot of one Oracle Planning and Budgeting Cloud environment (source) to another Oracle Planning and Budgeting Cloud environment (target).

This API is executed on the target environment after details are provided for the source environment from which the snapshot is to be copied.

Prerequisites: The password of the source EPM Cloud environment must have already been encrypted using EPM Automate. The encrypted password.epw file must then passed as one of the parameters for the copysnapshot REST API.

Function to call CopySnapsot
 Output of the Program

Make sure you have the Snapshot by the name "GroovyCopy" in the Source and no snapshot with the same exists in the Target.


8. Provide Feedback

This feedback service sends feedback or reports an issue to Oracle

Function to provide feedback


It will shoot an email to all the stakeholders as shown below,

9. LCM Export

Initiates a repeat export of a Migration artifact based on the settings that were used to export artifacts using the Migration artifact export screen.

Function

Output

10. LCM Import  

Initiates import of a Migration snapshot so that the contents of the application snapshot are imported into the application.


Output

Will continue this series with Data Management in the next post, until then have a good time with Oracle PBCS !!!!

4 comments:

  1. hello Where can i found the fetchPwdFromFile function ? thanks in advance

    ReplyDelete
  2. Sorry for the late reply,If i understand it you are interested in getting the password form a file. If yes look at this example program where i read the values from a file https://onlyhyperion.blogspot.in/2017/09/Finally-REST-on-Oracle-PBCS.html

    ReplyDelete
  3. in the recreate service what is the service name ?

    ReplyDelete
  4. How we can implement this REST API to VBA?

    ReplyDelete