summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/groovy/org
diff options
context:
space:
mode:
authorsanket12345 <SX00562924@techmahindra.com>2021-08-25 17:27:59 +0530
committersanket12345 <SX00562924@techmahindra.com>2021-08-25 17:29:03 +0530
commit834a687fc5d277dd95cb4a40441f4c65076822e1 (patch)
treef2db2dbae40f65a946088accad76a9cfff36b361 /bpmn/MSOCommonBPMN/src/main/groovy/org
parent9e597da1e74ab81a27879f6100335e6815ff1702 (diff)
Implementation of HealthCheckBB
Code changes to implement HealthCheckBB Issue-ID: SO-3691 Change-Id: I88d22f125c122d813f42f0b800aeb6530d7c6acf Signed-off-by: sanket12345 <SX00562924@techmahindra.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/groovy/org')
-rwxr-xr-xbpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CNFAdapterAsync.groovy80
1 files changed, 80 insertions, 0 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CNFAdapterAsync.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CNFAdapterAsync.groovy
new file mode 100755
index 0000000000..9de40b4e69
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CNFAdapterAsync.groovy
@@ -0,0 +1,80 @@
+package org.onap.so.bpmn.common.scripts
+
+import javax.ws.rs.core.Response
+
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import com.fasterxml.jackson.databind.ObjectMapper
+
+import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.logging.filter.base.ONAPComponents
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+
+import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank
+
+public class CNFAdapterAsync extends AbstractServiceTaskProcessor {
+ private static final Logger logger = LoggerFactory.getLogger(CNFAdapterAsync.class)
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ ObjectMapper mapper = new ObjectMapper();
+
+ @Override
+ public void preProcessRequest(DelegateExecution execution) {
+ logger.debug("Start preProcessRequest");
+
+ String apiPath = execution.getVariable("apiPath")
+ if (isBlank(apiPath)) {
+ String msg = "Cannot process CNF adapter call : API PATH is null"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+
+ //Object cnfRequestPayloadFromExecutionVariable = execution.getVariable("cnfRequestPayload")
+
+ String cnfRequestPayload = execution.getVariable("cnfRequestPayload")
+ if (isBlank(cnfRequestPayload)) {
+ String msg = "Cannot process CNF adapter call : cnfRequestPayload is null"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+
+ String correlator = execution.getVariable("correlator")
+ if (isBlank(correlator)) {
+ String msg = "Cannot process CNF adapter call : correlator is null"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+
+ String messageType = execution.getVariable("messageType")
+ if (isBlank(messageType)) {
+ String msg = "Cannot process CNF adapter call : messageType is null"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+
+ String timeout = UrnPropertiesReader.getVariable("mso.adapters.cnf.timeout", execution);
+ if (isBlank(timeout)) {
+ logger.debug("Setting CNF Adapter timeout to default : PT30M")
+ timeout = "PT30M"
+ }
+
+ execution.setVariable("timeout",timeout)
+
+ logger.debug("Enter preProcessRequest: {}",execution.getVariable("messageType"));
+ }
+
+ void callCnfAdapter(DelegateExecution execution) {
+ logger.debug("Start callCnfAdapter")
+ String cnfAdapterEndpoint = execution.getVariable("apiPath")
+ URL requestUrl = new URL(cnfAdapterEndpoint)
+ String cnfRequest = execution.getVariable("cnfRequestPayload")
+ logger.debug("cnfRequest : " + cnfRequest)
+ HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.EXTERNAL)
+ Response httpResponse = httpClient.post(cnfRequest)
+ int responseCode = httpResponse.getStatus()
+ logger.debug("CNF sync response code is: " + responseCode)
+ if(responseCode < 200 || responseCode >= 300){
+ exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CNF.")
+ }
+ logger.debug("End callCnfAdapter")
+ }
+}