def awaitCompletion(HttpResponse
// Parse the JSON response to get the standing of the operation. Hold polling the server till the operation completes.
for(lengthy delay = 50; standing == IN_PROGRESS; delay = Math.min(1000, delay * 2)) {
println(“$operation $.n”)
HttpResponse
- Polling
Logic:
The script makes use of exponential backoff for polling the job standing, beginning
from 50 milliseconds and doubling the delay till a most of 1000
milliseconds. - Error
Dealing with:
The script throws an exception if the preliminary HTTP response just isn’t
profitable (standing code not within the vary 200-299). - Job
Standing:
It checks if the job standing is IN_PROGRESS. In that case, it continues
polling till the job completes. - Print
Consequence:
It prints whether or not the operation was profitable or failed based mostly on the ultimate
job standing.
This
script must be built-in inside a bigger utility context the place the operation
object and its strategies (utility.getConnection and throwVetoException)
are outlined
Run the EPCM Calculation utilizing REST API & connection /************************************************************************************************/
/*
1. Run Calculation
*/
/************************************************************************************************/
println “1 Run Calculation”
jsonResponse
=
operation.utility.getConnection(“Localhost”).submit(‘/relaxation/v3/functions/PCM/jobs/’)
.header(“Content material-Kind”,
“utility/json”)
.physique(json([
“jobType”:”Calculation”,
“jobName”:”Run Calculation”,
“parameters”:[
“povDelimiter”:”:”,
“povName”:”$CurYr:$CurMth:Actual:Working”,,
“modelName”:”IC
Calcs”,
“executionType”:”ALL_RULES”,
“clearCalculatedData”:”true”,
“executeCalculations”:”true”,
“optimizeForReporting”:”true”,
“captureDebugScripts”:”false”]
])
)
.asString();
println
‘Response Acquired’
println
jsonResponse.physique
WaitforCompletion =
awaitCompletion(jsonResponse, “Localhost”, “Run Calculation Calcs”)
making
an HTTP POST request to a particular endpoint (/relaxation/v3/functions/PCM/jobs/)
on a server (presumably “Localhost”).
request
features a JSON payload with numerous parameters for the job, such because the job
kind (“Calculation”), job title (“Run Calculation”), and different settings.
After sending
the request, you’re printing out the response acquired from the server.
Lastly,
there’s a name to awaitCompletion
Run the EPCM Clear job utilizing REST API & connection
/***********************************************************************************************/
/*
2. Clear Job
/***********************************************************************************************/
println “2a. CLR_PCM_01”
jsonResponse
=
operation.utility.getConnection(“Localhost”).submit(‘/relaxation/v3/functions/PCM/jobs’)
.header(“Content material-Kind”,
“utility/json”)
.physique(json([
“jobType” : “Clear
Cube”,
“jobName” : “CLR_PCM_01”
])
)
.asString();
println ‘Response Acquired’
println jsonResponse.physique
WaitforCompletion
= awaitCompletion(jsonResponse, “Localhost”, “CLR_PCM_01”)
Run the EPCM Merge jobs utilizing REST API & connection
/**********************************************************************************************/
/*
3. Merge Information Slices
*/
/*
Rule Identify: Merge Information Slices PCM.PCMRPT */
/**********************************************************************************************/
println “3. Merge Information Slices”
jsonResponse =
operation.utility.getConnection(“Localhost”).submit(‘/relaxation/v3/functions/PCM/jobs’)
.header(“Content material-Kind”,
“utility/json”)
.physique(json([
“jobType” : “Merge Data
Slices”,
“jobName” : “Merge Data
Slices ICPCM.ICPCMRPT”,
“parameters”: [
“cubeName”:
“ICPCMRPT”,
“mergeSliceType”:
“allIncrementalSlicesInMain”,
“keepZeroCells”:
“false”
]
])
)
.asString();
println ‘Response Acquired’
println jsonResponse.physique
WaitforCompletion =
awaitCompletion(jsonResponse, “Localhost”, “Merge Information
Slices”)
Calling the Jobfactory to invoke a Calculation
/***********************************************************************************************/
/*
4. Push to Reporting Dice */
/***********************************************************************************************/
JobFactory
jf = operation.utility.jobFactory
JobDefinition jobDef = jf.job(“1_Push to
Reporting Dice”, “Guidelines”, [:])
Job job = executeJob(jobDef)
println job.standing
//
Print a message indicating the consumer who executed the rule
println(“Rule
was executed by $operation.consumer.fullName”)
/*
Parameters to attend for DM Guidelines */
boolean
pushDataToRPT
HttpResponse
jsonResponse
def
payload
def
awaitCompletion(HttpResponse
String operation) {
last int IN_PROGRESS = -1
if
(!(200..299).comprises(jsonResponse.standing)) {
throwVetoException(“Error occured:
$jsonResponse.statusText”)
}
// Parse the JSON response to get the
standing of the operation. Hold polling the DM server till the operation
completes.
ReadContext ctx =
JsonPath.parse(jsonResponse.physique)
int standing = ctx.learn(‘$.standing’)
for(lengthy delay = 50; standing == IN_PROGRESS;
delay = Math.min(1000, delay * 2)) {
sleep(delay)
standing = getJobStatus(connectionName,
(String)ctx.learn(‘$.jobId’))
}
println(“$operation $.n”)
return standing == 0
}
int
getJobStatus(String connectionName, String jobId) {
HttpResponse
operation.utility.getConnection(connectionName).get(“/” +
jobId).asString()
return
JsonPath.parse(pingResponse.physique).learn(‘$.standing’)
}
Run the Information Administration guidelines utilizing REST API & connection
println “3a Run PCM_CLC to RPT”
jsonResponse
= operation.utility.getConnection(“DM-Localhost”).submit()
.header(“Content material-Kind”,
“utility/json”)
.physique(json([
“jobType”:”INTEGRATION”,
“jobName”:”PCM_CLC to RPT”,
“periodName”:”{$CurMth#$CurYr}”,
“importMode”:”REPLACE”,
“exportMode”:”STORE_DATA”
])
)
.asString();
pushDataToRPT =
awaitCompletion(jsonResponse, “DM-Localhost”, “Push Information to PCMRPT”)
Job Console Output