summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main
diff options
context:
space:
mode:
authorByung-Woo Jun <byung-woo.jun@est.tech>2020-09-17 05:48:03 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-17 05:48:03 +0000
commit633af62e329892feb8c7a3354a9bdb37eaef3f3d (patch)
treed4a5e082ec3b2204e9f84b80605ab8ef1539a6e9 /bpmn/so-bpmn-infrastructure-common/src/main
parent4b7611ffa47492aa6080fc58c0d04c23f32804b3 (diff)
parent30c6bacb158f5446915a772745f33a28d8da5ea2 (diff)
Merge "Implement Subnet Capability query functionality"
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/main')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/QueryJobStatus.groovy141
1 files changed, 141 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/QueryJobStatus.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/QueryJobStatus.groovy
new file mode 100644
index 0000000000..5cdf540173
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/QueryJobStatus.groovy
@@ -0,0 +1,141 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+import groovy.json.JsonSlurper
+import org.json.JSONObject
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.onap.so.bpmn.core.UrnPropertiesReader
+
+public class QueryJobStatus extends AbstractServiceTaskProcessor{
+ private static final Logger logger = LoggerFactory.getLogger(QueryJobStatus.class)
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+
+ public void preProcessRequest(DelegateExecution execution) {
+ logger.debug("Start preProcessRequest")
+
+ try{
+ String requestId = execution.getVariable("msoRequestId")
+ logger.debug("RequestId :" + requestId)
+ String responseId = execution.getVariable("responseId")
+ String jobId = execution.getVariable("jobId")
+ def jsonSlurper = new JsonSlurper()
+
+ HashMap<String,?> esrInfo=jsonSlurper.parseText(execution.getVariable("esrInfo"))
+ logger.debug("esrInfo" + esrInfo.toString())
+
+ HashMap<String,?> serviceInfo=jsonSlurper.parseText(execution.getVariable("serviceInfo"))
+ logger.debug("serviceInfo" + serviceInfo.toString())
+
+ execution.setVariable("esrInfo", esrInfo)
+ execution.setVariable("serviceInfo", serviceInfo)
+
+ String nssmfEndpoint = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint",execution)
+ String endPoint = String.format("/api/rest/provMns/v1/NSS/jobs/%s", jobId)
+ String url = nssmfEndpoint + endPoint
+ execution.setVariable("NSSMF_AdapterEndpoint", url)
+
+ String payload = """
+ {
+ "responseId": "${responseId}",
+ "esrInfo": ${execution.getVariable("esrInfo") as JSONObject},
+ "serviceInfo": ${execution.getVariable("serviceInfo") as JSONObject}
+ }
+ """
+
+ execution.setVariable("NSSMF_AdapterRequest", payload.replaceAll("\\s+", ""))
+ execution.setVariable("startTime", System.currentTimeMillis())
+ logger.debug("Outgoing NSSMF_AdapterRequest: \n" + payload)
+ }catch(Exception e){
+ String msg = "Exception in QueryJobStatus.preProcessRequest " + ex.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug("exit preProcessRequest")
+ }
+
+ public void checkJobStatus(DelegateExecution execution) {
+ logger.debug(" *** checkJobStatus *** ")
+ def NSSMF_ResponseCode = execution.getVariable("NSSMF_ResponseCode") as Integer
+ logger.debug("NSSMF_ResponseCode:" + NSSMF_ResponseCode)
+ def NSSMF_Response = execution.getVariable("NSSMF_Response") as String
+ def status = jsonUtil.getJsonValue(NSSMF_Response, "responseDescriptor.status")
+ logger.debug("NSSMF_Response" + NSSMF_Response)
+
+ Long startTime = execution.getVariable("startTime") as Long
+ Long timeout = execution.getVariable("timeout") as Long
+ timeout = timeout == null ? 600000 : timeout * 60000
+
+ if(NSSMF_Response != null) {
+ if (status.equalsIgnoreCase("processing") && (System.currentTimeMillis() - startTime) > timeout) {
+ handleTimeOut(execution)
+ }
+ else if(status.equalsIgnoreCase("finished") || status.equalsIgnoreCase("failed")) {
+ execution.setVariable("JobStatusCompleted", "TRUE")
+ } else {
+ execution.setVariable("JobStatusCompleted", "FALSE")
+ }
+ } else {
+ Map<String, ?> responseDescriptorMap = new HashMap<>()
+ responseDescriptorMap.put("status","failed")
+ responseDescriptorMap.put("statusDescription","Exception while querying job status")
+ String responseDescriptor = """
+ {
+ "responseDescriptor": "${responseDescriptorMap}",
+ }
+ """
+ execution.setVariable("JobStatusCompleted", "TRUE")
+ execution.setVariable("NSSMF_Response",responseDescriptor.replaceAll("\\s+", ""))
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Response from NSSMF.")
+ }
+ logger.debug("exit checkJobStatus")
+ }
+
+ private handleTimeOut(DelegateExecution execution) {
+ Map<String, ?> responseDescriptorMap = new HashMap<>()
+ responseDescriptorMap.put("status","failed")
+ responseDescriptorMap.put("statusDescription","timeout")
+ String responseDescriptor = """
+ {
+ "responseDescriptor": "${responseDescriptorMap}",
+ }
+ """
+ execution.setVariable("JobStatusCompleted", "TRUE")
+ execution.setVariable("NSSMF_Response",responseDescriptor.replaceAll("\\s+", ""))
+ }
+
+ public void updateJobStatusDetails(DelegateExecution execution)
+ {
+ logger.debug("**updateJobStatusDetails**")
+ def NSSMF_Response = execution.getVariable("NSSMF_Response") as String
+ def responseDescriptor = jsonUtil.getJsonValue(NSSMF_Response, "responseDescriptor")
+ execution.setVariable("responseDescriptor",responseDescriptor)
+ logger.debug("**exit updateJobStatusDetails")
+ }
+}