Merge changes Id0369478,I82d8306f
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / UpdateCustomE2EServiceInstance.groovy
index 20ced72..4e3517e 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * 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
@@ -36,12 +38,15 @@ import org.onap.so.bpmn.common.scripts.MsoUtils
 import org.onap.so.bpmn.core.WorkflowException
 import org.onap.so.bpmn.core.domain.Resource
 import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.client.aai.AAIObjectType
 import org.onap.so.client.aai.AAIResourcesClient
 import org.onap.so.client.aai.entities.AAIResultWrapper
 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 import org.onap.so.client.aai.entities.uri.AAIUriFactory
 import org.springframework.web.util.UriUtils
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
 
 import groovy.json.*
 
@@ -51,6 +56,8 @@ import groovy.json.*
  *
  */
 public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
+       private static final Logger logger = LoggerFactory.getLogger( UpdateCustomE2EServiceInstance.class);
+
        String Prefix="UPDSI_"
        ExceptionUtil exceptionUtil = new ExceptionUtil()
        JsonUtils jsonUtil = new JsonUtils()
@@ -60,7 +67,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
                execution.setVariable("prefix",Prefix)
                String msg = ""
-               utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)
+               logger.info( " *** preProcessRequest() *** ")
 
                try {
 
@@ -69,7 +76,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
                        String requestId = execution.getVariable("mso-request-id")
                        execution.setVariable("msoRequestId", requestId)
-                       utils.log("INFO", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
+                       logger.info( "Input Request:" + siRequest + " reqId:" + requestId)
 
                        String serviceInstanceId = execution.getVariable("serviceInstanceId")
                        if (isBlank(serviceInstanceId)) {
@@ -94,32 +101,32 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        if (isBlank(productFamilyId))
                        {
                                msg = "Input productFamilyId is null"
-                               utils.log("INFO", msg, isDebugEnabled)
+                               logger.info( msg)
                        } else {
                                execution.setVariable("productFamilyId", productFamilyId)
                        }
 
                         //user params
                 String userParams = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams")
-             utils.log("INFO", "userParams:" + userParams, isDebugEnabled)
+             logger.info( "userParams:" + userParams)
                 List<String> paramList = jsonUtil.StringArrayToList(execution, userParams)
                 String uuiRequest = jsonUtil.getJsonValue(paramList.get(0), "UUIRequest")
                        if (isBlank(uuiRequest)) {
                                msg = "Input uuiRequest is null"
-                               utils.log("INFO", msg, isDebugEnabled)
+                               logger.info( msg)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        } else
                        {
                                execution.setVariable("uuiRequest", uuiRequest)
                        }
 
-                       utils.log("INFO", "uuiRequest:\n" + uuiRequest,  isDebugEnabled)
+                       logger.info( "uuiRequest:\n" + uuiRequest)
 
                        //serviceType for aai
                        String serviceType = jsonUtil.getJsonValue(uuiRequest, "service.serviceType")
                        if (isBlank(serviceType)) {
                                msg = "Input serviceType is null"
-                               utils.log("INFO", msg, isDebugEnabled)
+                               logger.info( msg)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
                        } else {
                                execution.setVariable("serviceType", serviceType)
@@ -127,17 +134,17 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
                        // target model info
                        String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid")
-                       utils.log("INFO","modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled)
+                       logger.info("modelInvariantUuid: " + modelInvariantUuid)
                        execution.setVariable("modelInvariantUuid", modelInvariantUuid)
                        execution.setVariable("model-invariant-id-target", modelInvariantUuid)
 
                        String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid")
-                       utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled)
+                       logger.info("modelUuid: " + modelUuid)
                        execution.setVariable("modelUuid", modelUuid)
                        execution.setVariable("model-version-id-target", modelUuid)
 
                        String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
-                       utils.log("INFO","serviceModelName: " + serviceModelName, isDebugEnabled)
+                       logger.info("serviceModelName: " + serviceModelName)
                        if(serviceModelName == null) {
                                serviceModelName = ""
                        }
@@ -152,16 +159,14 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        execution.setVariable("operationType", "update")
                        execution.setVariable("hasResourcetoUpdate", false)
 
-                       execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
-
                } catch (BpmnError e) {
                        throw e;
                } catch (Exception ex){
                        msg = "Exception in preProcessRequest " + ex.getMessage()
-                       utils.log("INFO", msg, isDebugEnabled)
+                       logger.info( msg)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)
+               logger.info(" ***** Exit preProcessRequest *****")
        }
 
        /**
@@ -204,7 +209,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
        public void postCompareModelVersions(DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG", " ======== STARTED postCompareModelVersions Process ======== ", isDebugEnabled)
+               logger.debug( " ======== STARTED postCompareModelVersions Process ======== ")
 
                def hasResourcetoUpdate = false
                def hasResourcetoAdd = false
@@ -223,7 +228,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                hasResourcetoUpdate = hasResourcetoAdd || hasResourcetoDelete
                execution.setVariable("hasResourcetoUpdate", hasResourcetoUpdate)
 
-               utils.log("DEBUG", "======== COMPLETED postCompareModelVersions Process ======== ", isDebugEnabled)
+               logger.debug( "======== COMPLETED postCompareModelVersions Process ======== ")
        }
 
        /**
@@ -231,7 +236,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
         */
        public void prepareInitServiceOperationStatus(DelegateExecution execution){
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-               utils.log("DEBUG", " ======== STARTED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
+               logger.debug( " ======== STARTED prepareInitServiceOperationStatus Process ======== ")
                try{
                        String serviceId = execution.getVariable("serviceInstanceId")
                        String operationId = execution.getVariable("operationId")
@@ -241,15 +246,15 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        String progress = "0"
                        String reason = ""
                        String operationContent = "Prepare service updating"
-                       utils.log("DEBUG", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
+                       logger.debug( "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
                        serviceId = UriUtils.encode(serviceId,"UTF-8")
                        execution.setVariable("serviceInstanceId", serviceId)
                        execution.setVariable("operationId", operationId)
                        execution.setVariable("operationType", operationType)
 
-                       def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
+                       def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
                        execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
-                       utils.log("DEBUG", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
+                       logger.debug( "DB Adapter Endpoint is: " + dbAdapterEndpoint)
 
                        String payload =
                                """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
@@ -271,14 +276,14 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
                        payload = utils.formatXml(payload)
                        execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
-                       utils.log("DEBUG", "Outgoing updateServiceOperStatusRequest: \n" + payload, isDebugEnabled)
+                       logger.error( "Outgoing updateServiceOperStatusRequest: \n" + payload)
                        utils.logAudit("CreateVfModuleInfra Outgoing updateServiceOperStatusRequest Request: " + payload)
 
                }catch(Exception e){
-                       utils.log("ERROR", "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
+                       logger.debug( "Exception Occured Processing prepareInitServiceOperationStatus. Exception is:\n" + e)
                        execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
                }
-               utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled)
+               logger.debug( "======== COMPLETED prepareInitServiceOperationStatus Process ======== ")
        }
 
        /**
@@ -287,7 +292,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
        public void preUpdateServiceOperationStatus(DelegateExecution execution){
                def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')'
                def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
-               utils.log("INFO","Entered " + method, isDebugEnabled)
+               logger.info("Entered " + method)
 
                try{
                        String serviceId = execution.getVariable("serviceInstanceId")
@@ -298,21 +303,20 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        String progress = execution.getVariable("progress")
                        String reason = execution.getVariable("operationReason")
                        String userId = ""
-                       utils.log("INFO", "progress: " + progress , isDebugEnabled)
+                       logger.info( "progress: " + progress )
 
                        String operationContent = "Prepare service : " + execution.getVariable("operationStatus")
 
-                       utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled)
+                       logger.info( "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
                        serviceId = UriUtils.encode(serviceId,"UTF-8")
                        execution.setVariable("serviceInstanceId", serviceId)
                        execution.setVariable("operationId", operationId)
                        execution.setVariable("operationType", operationType)
 
-                       def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
-                       execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
-                       utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
+            def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
+            execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
+                       logger.info( "DB Adapter Endpoint is: " + dbAdapterEndpoint)
 
-                       execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
                        String payload =
                                """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                         xmlns:ns="http://org.onap.so/requestsdb">
@@ -333,20 +337,20 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
                        payload = utils.formatXml(payload)
                        execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
-                       utils.log("INFO", "Outgoing preUpdateServiceOperationStatus: \n" + payload, isDebugEnabled)
+                       logger.error( "Outgoing preUpdateServiceOperationStatus: \n" + payload)
 
 
                }catch(Exception e){
-                       utils.log("ERROR", "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e, isDebugEnabled)
+                       logger.info( "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e)
                        execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preUpdateServiceOperationStatus Method:\n" + e.getMessage())
                }
-               utils.log("INFO", "======== COMPLETED preUpdateServiceOperationStatus Process ======== ", isDebugEnabled)
-               utils.log("INFO", "Exited " + method, isDebugEnabled)
+               logger.info( "======== COMPLETED preUpdateServiceOperationStatus Process ======== ")
+               logger.info( "Exited " + method)
        }
 
        public void sendSyncResponse (DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("INFO", " *** sendSyncResponse *** ", isDebugEnabled)
+               logger.info( " *** sendSyncResponse *** ")
 
                try {
                        String operationId = execution.getVariable("operationId")
@@ -361,21 +365,21 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                                updateServiceResp =  """{"OperationResult":"No Resource to Add or Delete or Service Instance not found in AAI."}"""
                        }
 
-                       utils.log("INFO", " sendSyncResponse to APIH:" + "\n" + updateServiceResp, isDebugEnabled)
+                       logger.info( " sendSyncResponse to APIH:" + "\n" + updateServiceResp)
                        sendWorkflowResponse(execution, 202, updateServiceResp)
                        execution.setVariable("sentSyncResponse", true)
 
                } catch (Exception ex) {
                        String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
-                       utils.log("INFO", msg, isDebugEnabled)
+                       logger.info( msg)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("INFO"," ***** Exit sendSyncResopnse *****",  isDebugEnabled)
+               logger.info(" ***** Exit sendSyncResopnse *****")
        }
 
        public void sendSyncError (DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("INFO", " *** sendSyncError *** ", isDebugEnabled)
+               logger.info( " *** sendSyncError *** ")
 
                try {
                        String errorMessage = ""
@@ -398,14 +402,14 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        sendWorkflowResponse(execution, 500, buildworkflowException)
 
                } catch (Exception ex) {
-                       utils.log("INFO", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
+                       logger.info( " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
                }
 
        }
 
        public void prepareCompletionRequest (DelegateExecution execution) {
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("INFO", " *** prepareCompletion *** ", isDebugEnabled)
+               logger.info( " *** prepareCompletion *** ")
 
                try {
                        String requestId = execution.getVariable("msoRequestId")
@@ -429,23 +433,23 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
 
                        execution.setVariable("completionRequest", xmlMsoCompletionRequest)
-                       utils.log("INFO", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
+                       logger.info( " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest)
 
                } catch (Exception ex) {
                        String msg = " Exception in prepareCompletion:" + ex.getMessage()
-                       utils.log("INFO", msg, isDebugEnabled)
+                       logger.info( msg)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
                }
-               utils.log("INFO", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
+               logger.info( "*** Exit prepareCompletionRequest ***")
        }
 
        public void prepareFalloutRequest(DelegateExecution execution){
                def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
-               utils.log("INFO", " *** prepareFalloutRequest *** ", isDebugEnabled)
+               logger.info( " *** prepareFalloutRequest *** ")
 
                try {
                        WorkflowException wfex = execution.getVariable("WorkflowException")
-                       utils.log("INFO", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
+                       logger.info( " Input Workflow Exception: " + wfex.toString())
                        String requestId = execution.getVariable("msoRequestId")
                        String source = execution.getVariable("source")
                        String requestInfo =
@@ -458,7 +462,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
                        String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
                        execution.setVariable("falloutRequest", falloutRequest)
                } catch (Exception ex) {
-                       utils.log("INFO", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
+                       logger.info( "Exception prepareFalloutRequest:" + ex.getMessage())
                        String errorException = "  Bpmn error encountered in UpdateCustomE2EServiceInstance flow. FalloutHandlerRequest,  buildErrorResponse() - " + ex.getMessage()
                        String requestId = execution.getVariable("msoRequestId")
                        String falloutRequest =
@@ -478,6 +482,6 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
 
                        execution.setVariable("falloutRequest", falloutRequest)
                }
-               utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
+               logger.info( "*** Exit prepareFalloutRequest ***")
        }
 }