Merge "Enhanced List Level flow with backward support"
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / VnfAdapterRestV1.groovy
index d8b2c4f..866229f 100644 (file)
@@ -22,7 +22,9 @@
 
 package org.onap.so.bpmn.common.scripts
 
+import org.onap.so.logger.LoggingAnchor
 import org.onap.so.client.HttpClientFactory
+import org.onap.so.logger.ErrorCode
 
 import javax.ws.rs.core.Response
 import org.apache.commons.lang3.*
@@ -31,7 +33,6 @@ import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.client.HttpClient
 import org.onap.so.logger.MessageEnum
-import org.onap.so.logger.MsoLogger
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 import org.onap.so.utils.TargetEntity
@@ -39,7 +40,6 @@ import java.util.UUID
 
 
 
-
 class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
     private static final Logger logger = LoggerFactory.getLogger( VnfAdapterRestV1.class);
 
@@ -78,9 +78,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                        if (messageId == null || messageId.isEmpty()) {
                                String msg = getProcessKey(execution) + ': no messageId in ' + requestType
-                               logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                               MsoLogger.ErrorCode.UnknownError.getValue());
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                               logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                               ErrorCode.UnknownError.getValue());
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                        }
 
                        execution.setVariable('VNFAResponse_CORRELATOR', messageId)
@@ -92,9 +92,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                        if (notificationUrl == null || notificationUrl.isEmpty()) {
                                String msg = getProcessKey(execution) + ': no notificationUrl in ' + requestType
-                               logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                               MsoLogger.ErrorCode.UnknownError.getValue());
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                               logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                               ErrorCode.UnknownError.getValue());
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                        }
 
                        execution.setVariable(prefix + 'notificationUrl', notificationUrl)
@@ -106,9 +106,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                        if (vnfAdapterEndpoint == null || vnfAdapterEndpoint.isEmpty()) {
                                String msg = getProcessKey(execution) + ': mso:adapters:vnf:rest:endpoint URN mapping is not defined'
-                               logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                               MsoLogger.ErrorCode.UnknownError.getValue());
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                               logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                               ErrorCode.UnknownError.getValue());
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                        }
 
                        while (vnfAdapterEndpoint.endsWith('/')) {
@@ -124,9 +124,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                                if (vnfId == null || vnfId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no vnfId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                vnfAdapterMethod = 'POST'
@@ -137,18 +137,18 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                                if (vnfId == null || vnfId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no vnfId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                String vfModuleId = getChildText(root, 'vfModuleId')
 
                                if (vfModuleId == null || vfModuleId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                vnfAdapterMethod = 'PUT'
@@ -160,18 +160,18 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                                if (vnfId == null || vnfId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no vnfId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                String vfModuleId = getChildText(root, 'vfModuleId')
 
                                if (vfModuleId == null || vfModuleId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                vnfAdapterMethod = 'DELETE'
@@ -183,27 +183,27 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                                if (vfModuleRollbackNode == null) {
                                        String msg = getProcessKey(execution) + ': no vfModuleRollback in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                String vnfId = getChildText(vfModuleRollbackNode, 'vnfId')
 
                                if (vnfId == null || vnfId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no vnfId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                String vfModuleId = getChildText(vfModuleRollbackNode, 'vfModuleId')
 
                                if (vfModuleId == null || vfModuleId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no vfModuleId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                vnfAdapterMethod = 'DELETE'
@@ -222,9 +222,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                                if (volumeGroupId == null || volumeGroupId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                vnfAdapterMethod = 'PUT'
@@ -238,9 +238,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                                if (volumeGroupId == null || volumeGroupId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                vnfAdapterMethod = 'DELETE'
@@ -254,9 +254,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                                if (volumeGroupId == null || volumeGroupId.isEmpty()) {
                                        String msg = getProcessKey(execution) + ': no volumeGroupId in ' + requestType
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue());
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                                }
 
                                vnfAdapterMethod = 'DELETE'
@@ -267,9 +267,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
 
                        } else {
                                String msg = getProcessKey(execution) + ': Unsupported request type: ' + requestType
-                               logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                               MsoLogger.ErrorCode.UnknownError.getValue());
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                               logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                               ErrorCode.UnknownError.getValue());
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                        }
 
                        execution.setVariable(prefix + 'vnfAdapterMethod', vnfAdapterMethod)
@@ -284,17 +284,17 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
                        String basicAuthValue = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
 
                        if (basicAuthValue == null || basicAuthValue.isEmpty()) {
-                               logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                               logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
                                                getProcessKey(execution) + ": mso:adapters:po:auth URN mapping is not defined", "BPMN",
-                                               MsoLogger.ErrorCode.UnknownError.getValue());
+                                               ErrorCode.UnknownError.getValue());
                        } else {
                                try {
                                        def encodedString = utils.getBasicAuth(basicAuthValue, UrnPropertiesReader.getVariable("mso.msoKey", execution))
                                        execution.setVariable(prefix + 'basicAuthHeaderValue', encodedString)
                                } catch (IOException ex) {
-                                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
                                                        getProcessKey(execution) + ": Unable to encode BasicAuth credentials for VnfAdapter",
-                                                       "BPMN", MsoLogger.ErrorCode.UnknownError.getValue());
+                                                       "BPMN", ErrorCode.UnknownError.getValue(), ex);
                                }
                        }
 
@@ -303,10 +303,10 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
                        throw e
                } catch (Exception e) {
                        String msg = 'Caught exception in ' + method + ": " + e
-                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                       MsoLogger.ErrorCode.UnknownError.getValue());
+                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                       ErrorCode.UnknownError.getValue());
                        logger.debug(msg)
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                }
        }
 
@@ -355,9 +355,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
                                response = httpClient.delete(vnfAdapterRequest)
                        } else {
                                String msg = 'Unsupported HTTP method "' + vnfAdapterMethod + '" in ' + method + ": " + e
-                               logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                               MsoLogger.ErrorCode.UnknownError.getValue());
-                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                               logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                               ErrorCode.UnknownError.getValue());
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                        }
 
                        execution.setVariable(prefix + "vnfAdapterStatusCode", response.getStatus())
@@ -368,9 +368,9 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
                        throw e
                } catch (Exception e) {
                        String msg = 'Caught exception in ' + method + ": " + e
-                       logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                       MsoLogger.ErrorCode.UnknownError.getValue());
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
+                       logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                       ErrorCode.UnknownError.getValue());
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg, TargetEntity.SO)
                }
        }
 
@@ -398,8 +398,8 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
                                vnfAdapterWorkflowException(execution, callback)
                        }
                } catch (Exception e) {
-                       logger.debug("Error encountered within VnfAdapterRest ProcessCallback method", e)
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 7020, "Error encountered within VnfAdapterRest ProcessCallback method")
+                       logger.debug("Error encountered within VnfAdapterRest ProcessCallback method: {}", e.getMessage(), e)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7020, "Error encountered within VnfAdapterRest ProcessCallback method", TargetEntity.SO)
                }
        }
 
@@ -418,10 +418,10 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
                        String rolledBack = getChildText(root, "rolledBack")
                        rolledBack = rolledBack == null || rolledBack.isEmpty() ? "" : " rolledBack='" + rolledBack + "'"
                        exceptionUtil.buildWorkflowException(execution, 7020, "Received " + root.name() +
-                               " from VnfAdapter:" + category + message + rolledBack);
+                               " from VnfAdapter:" + category + message + rolledBack, TargetEntity.OPENSTACK);
                } catch (Exception e) {
                        response = response == null || String.valueOf(response).isEmpty() ? "NONE" : response
-                       exceptionUtil.buildWorkflowException(execution, 7020, "Received error from VnfAdapter: " + response)
+                       exceptionUtil.buildWorkflowException(execution, 7020, "Received error from VnfAdapter: " + response, TargetEntity.OPENSTACK)
                }
        }
 
@@ -450,4 +450,8 @@ class VnfAdapterRestV1 extends AbstractServiceTaskProcessor {
                Node child = getChild(node, name)
                return child == null ? null : child.text()
        }
+       
+       public Logger getLogger() {
+               return logger;
+       }
 }