Refactored SDNCAdapterUtils (groovy)
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateVfModule.groovy
index 9ee8ff8..6b4fc84 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.so.bpmn.infrastructure.scripts
 
 import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
 import org.onap.so.client.HttpClientFactory
+import org.onap.so.logger.ErrorCode
 
 import javax.ws.rs.core.MediaType
 import javax.ws.rs.core.Response
@@ -62,7 +63,6 @@ import org.onap.so.client.graphinventory.entities.uri.Depth
 import org.onap.so.constants.Defaults
 import org.onap.so.db.catalog.beans.HomingInstance
 import org.onap.so.logger.MessageEnum
-import org.onap.so.logger.MsoLogger
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
 
@@ -84,7 +84,7 @@ public class DoCreateVfModule extends VfModuleBase {
        String Prefix="DCVFM_"
        ExceptionUtil exceptionUtil = new ExceptionUtil()
        JsonUtils jsonUtil = new JsonUtils()
-       SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
+       SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
        OofInfraUtils oofInfraUtils = new OofInfraUtils()
        CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
        DecomposeJsonUtil decomposeJsonUtils = new DecomposeJsonUtil()
@@ -568,8 +568,8 @@ public class DoCreateVfModule extends VfModuleBase {
                        String sdncCallbackUrl = (String) UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution)
                                if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
                                        def msg = 'Required variable \'mso.workflow.sdncadapter.callback\' is missing'
-                                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
-                                                       MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), msg);
+                                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN",
+                                                       ErrorCode.UnknownError.getValue(), msg);
 
                                        exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
                                }
@@ -598,7 +598,7 @@ public class DoCreateVfModule extends VfModuleBase {
         */
        public void validateWorkflowResponse(DelegateExecution execution, String responseVar,
                        String responseCodeVar, String errorResponseVar) {
-               SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
+               SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
                sdncAdapterUtils.validateSDNCResponse(execution, responseVar, responseCodeVar, errorResponseVar)
        }
 
@@ -620,9 +620,9 @@ public class DoCreateVfModule extends VfModuleBase {
                } catch (BpmnError e) {
                        throw e;
                } catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       'Caught exception in ' + method, "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
 
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Internal Error')
                }
@@ -668,8 +668,7 @@ public class DoCreateVfModule extends VfModuleBase {
                        rollbackData.put("VFMODULE", "rollbackPrepareUpdateVfModule", "true")
                        execution.setVariable("rollbackData", rollbackData)
                } catch (Exception ex) {
-                               ex.printStackTrace()
-                               logger.debug('Exception occurred while postProcessing CreateAAIVfModule request:' + ex.getMessage())
+                               logger.debug('Exception occurred while postProcessing CreateAAIVfModule request: {}', ex.getMessage(), ex)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Bad response from CreateAAIVfModule' + ex.getMessage())
                }
                logger.trace('Exited ' + method)
@@ -741,17 +740,16 @@ public class DoCreateVfModule extends VfModuleBase {
                                        }
                                }
                        } catch (Exception ex) {
-                               ex.printStackTrace()
-                               logger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
+                               logger.debug('Exception occurred while executing AAI GET: {}', ex.getMessage(), ex)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
                        }
                        logger.trace('Exited ' + method)
                } catch (BpmnError e) {
                        throw e;
                } catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       'Caught exception in ' + method, "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())
                }
        }
@@ -822,8 +820,7 @@ public class DoCreateVfModule extends VfModuleBase {
                                        }
                                }
                        } catch (Exception ex) {
-                               ex.printStackTrace()
-                               logger.debug('Exception occurred while executing AAI GET:' + ex.getMessage())
+                               logger.debug('Exception occurred while executing AAI GET: {}', ex.getMessage(), ex)
                                exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
                        }
                        logger.trace('Exited ' + method)
@@ -831,8 +828,8 @@ public class DoCreateVfModule extends VfModuleBase {
                        throw e;
                } catch (Exception e) {
                        logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                                       'Caught exception in ' + method, "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e, e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModuleForStatus(): ' + e.getMessage())
                }
        }
@@ -866,9 +863,9 @@ public class DoCreateVfModule extends VfModuleBase {
                        logger.debug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
 
                }catch(Exception e){
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception Occurred Processing preProcessSDNCAssignRequest", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception Occurred Processing preProcessSDNCAssignRequest", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareProvision Method:\n" + e.getMessage())
                }
                logger.trace("COMPLETED preProcessSDNCAssignRequest")
@@ -960,9 +957,9 @@ public class DoCreateVfModule extends VfModuleBase {
                        logger.debug("Outgoing GetSDNCRequest is: \n" + SDNCGetRequest)
 
                }catch(Exception e){
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception Occurred Processing preProcessSDNCGetRequest", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception Occurred Processing preProcessSDNCGetRequest", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
                }
                logger.trace("COMPLETED preProcessSDNCGetRequest Process")
@@ -982,6 +979,8 @@ public class DoCreateVfModule extends VfModuleBase {
                //Get variables
                //cloudSiteId
                def cloudSiteId = execution.getVariable("DCVFM_cloudSiteId")
+               //cloudOwner
+               def cloudOwner = execution.getVariable("DCVFM_cloudOwner")
                //tenantId
                def tenantId = execution.getVariable("DCVFM_tenantId")
                //vnfType
@@ -1070,6 +1069,7 @@ public class DoCreateVfModule extends VfModuleBase {
                String createVnfARequest = """
                <createVfModuleRequest>
                <cloudSiteId>${MsoUtils.xmlEscape(cloudSiteId)}</cloudSiteId>
+               <cloudOwner>${MsoUtils.xmlEscape(cloudOwner)}</cloudOwner>
                <tenantId>${MsoUtils.xmlEscape(tenantId)}</tenantId>
                <vnfId>${MsoUtils.xmlEscape(vnfId)}</vnfId>
                <vnfName>${MsoUtils.xmlEscape(vnfName)}</vnfName>
@@ -1165,9 +1165,9 @@ public class DoCreateVfModule extends VfModuleBase {
                } catch (BpmnError e) {
                        throw e;
                } catch (Exception e) {
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       'Caught exception in ' + method, "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")
                }
        }
@@ -1233,6 +1233,7 @@ public class DoCreateVfModule extends VfModuleBase {
                def vfModuleModelName = execution.getVariable("DCVFM_vfModuleModelName")
                def vnfId = execution.getVariable("DCVFM_vnfId")
                def cloudSiteId = execution.getVariable("DCVFM_cloudSiteId")
+               def cloudOwner = execution.getVariable("DCVFM_cloudOwner")
                def sdncVersion = execution.getVariable("DCVFM_sdncVersion")
                def serviceModelInfo = execution.getVariable("serviceModelInfo")
                def vnfModelInfo = execution.getVariable("vnfModelInfo")
@@ -1555,9 +1556,9 @@ public class DoCreateVfModule extends VfModuleBase {
                        logger.debug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
 
                }catch(Exception e){
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
                                        "Exception Occured Processing preProcessUpdateAAIVfModuleRequestOrch", "BPMN",
-                                       MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestOrch Method:\n" + e.getMessage())
                }
                logger.trace("COMPLETED preProcessUpdateAAIVfModuleRequestOrch")
@@ -1585,9 +1586,9 @@ public class DoCreateVfModule extends VfModuleBase {
                        logger.debug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
 
                }catch(Exception e){
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
                                        "Exception Occured Processing preProcessUpdateAAIVfModuleStatus", "BPMN",
-                                       MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleStatus Method:\n" + e.getMessage())
                }
                logger.trace("COMPLETED preProcessUpdateAAIVfModuleStatus")
@@ -1615,9 +1616,9 @@ public class DoCreateVfModule extends VfModuleBase {
                        logger.debug("Outgoing UpdateAAIVfModuleRequest is: \n" + updateAAIVfModuleRequest)
 
                }catch(Exception e){
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
                                        "Exception Occured Processing preProcessUpdateAAIVfModuleRequestGroup", "BPMN",
-                                       MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessUpdateAAIVfModuleRequestGroup Method:\n" + e.getMessage())
                }
                logger.trace("COMPLETED  preProcessUpdateAAIVfModuleRequestGroup")
@@ -1634,7 +1635,7 @@ public class DoCreateVfModule extends VfModuleBase {
 
                logger.debug("workflowException: " + workflowException)
 
-               SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
+               SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
                sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
 
                String sdncResponse = response
@@ -1695,9 +1696,9 @@ public class DoCreateVfModule extends VfModuleBase {
                        logger.debug("Outgoing GetSDNCRequest is: \n" + SDNCGetRequest)
 
                }catch(Exception e){
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Exception Occured Processing preProcessSDNCGetRequest", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Exception Occured Processing preProcessSDNCGetRequest", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareProvision Method:\n" + e.getMessage())
                }
                logger.trace("COMPLETED preProcessSDNCGetRequest Process")
@@ -1817,16 +1818,16 @@ public class DoCreateVfModule extends VfModuleBase {
                        logger.debug(" is Cloud Region Good: " + execution.getVariable("DCVFM_isCloudRegionGood"))
 
                } catch(BpmnError b){
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "Rethrowing MSOWorkflowException", "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + b.getMessage());
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "Rethrowing MSOWorkflowException", "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + b.getMessage());
                        throw b
                }catch (Exception ex) {
                        // try error
                        String errorMessage = "Bpmn error encountered in CreateVfModule flow. Unexpected Response from AAI - " + ex.getMessage()
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                       "AAI Query Cloud Region Failed " + errorMessage, "BPMN", MsoLogger.getServiceName(),
-                                       MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                       "AAI Query Cloud Region Failed " + errorMessage, "BPMN",
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + ex);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Exception occured during queryCloudRegion method")
                }
        }
@@ -1887,9 +1888,9 @@ public class DoCreateVfModule extends VfModuleBase {
                        logger.debug("Outgoing CreateAAIVfModuleVolumeGroupRequest is: \n" + createAAIVfModuleVolumeGroupRequest)
 
                }catch(Exception e){
-                       logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                       logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
                                        'Exception Occured Processing prepareCreateAAIVfModuleVolumeGroupRequest', "BPMN",
-                                       MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                                       ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during prepareCreateAAIVfModuleVolumeGroupRequest Method:\n" + e.getMessage())
                }
                logger.trace("COMPLETED  prepareCreateAAIVfModuleVolumeGroupRequest")
@@ -2020,9 +2021,9 @@ public class DoCreateVfModule extends VfModuleBase {
           } catch (BpmnError e) {
                   throw e;
           } catch (Exception e) {
-                  logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                  "Exception Encountered in " + method, "BPMN", MsoLogger.getServiceName(),
-                                  MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                  logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                  "Exception Encountered in " + method, "BPMN",
+                                  ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
 
                   exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
           }
@@ -2065,9 +2066,9 @@ public class DoCreateVfModule extends VfModuleBase {
           } catch (BpmnError e) {
                   throw e;
           } catch (Exception e) {
-                  logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                  'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(),
-                                  MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                  logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                  'Caught exception in ' + method, "BPMN",
+                                  ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                   exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in postProcessUpdateAAIGenericVnf(): ' + e.getMessage())
           }
    }
@@ -2118,9 +2119,9 @@ public class DoCreateVfModule extends VfModuleBase {
           } catch (BpmnError e) {
                   throw e;
           } catch (Exception e) {
-                  logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
-                                  'Caught exception in queryCatalogDB', "BPMN", MsoLogger.getServiceName(),
-                                  MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
+                  logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+                                  'Caught exception in queryCatalogDB', "BPMN",
+                                  ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
                   exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryCatalogDB(): ' + e.getMessage())
           }
    }