VoLTE groovy draft files 75/13075/2
authorSeshu-Kumar-M <seshu.kumar.m@huawei.com>
Mon, 18 Sep 2017 09:45:32 +0000 (15:15 +0530)
committerSeshu-Kumar-M <seshu.kumar.m@huawei.com>
Mon, 18 Sep 2017 10:51:27 +0000 (16:21 +0530)
Issue-Id: SO-142

Change-Id: I2adbf796f46cb400d32ada1d7f0ae671e58b00ad
Signed-off-by: Seshu-Kumar-M <seshu.kumar.m@huawei.com>
bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/CustomE2EGetService.groovy [new file with mode: 0644]
bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/CustomE2EPutService.groovy [new file with mode: 0644]
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateCustomE2EServiceInstance.groovy [new file with mode: 0644]
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy [new file with mode: 0644]
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstanceRollback.groovy [new file with mode: 0644]

diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/CustomE2EGetService.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/CustomE2EGetService.groovy
new file mode 100644 (file)
index 0000000..aece07e
--- /dev/null
@@ -0,0 +1,442 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.mso.bpmn.common.scripts\r
+\r
+import static org.apache.commons.lang3.StringUtils.*\r
+\r
+import org.apache.commons.lang3.*\r
+import org.camunda.bpm.engine.delegate.BpmnError\r
+import org.camunda.bpm.engine.runtime.Execution\r
+import org.openecomp.mso.rest.APIResponse\r
+import org.springframework.web.util.UriUtils\r
+\r
+\r
+/**\r
+ * This class supports the GenericGetService Sub Flow.\r
+ * This Generic sub flow can be used by any flow for accomplishing\r
+ * the goal of getting a Service-Instance or Service-Subscription (from AAI).\r
+ * The calling flow must set the GENGS_type variable as "service-instance"\r
+ * or "service-subscription".\r
+ *\r
+ * When using to Get a Service-Instance:\r
+ * If the global-customer-id and service-type are not provided\r
+ * this flow executes a query to get the service- Url using the\r
+ * Service  Id or Name (whichever is provided).\r
+ *\r
+ * When using to Get a Service-Subscription:\r
+ * The global-customer-id and service-type must be\r
+ * provided.\r
+ *\r
+ * Upon successful completion of this sub flow the\r
+ * GENGS_SuccessIndicator will be true and the query response payload\r
+ * will be set to GENGS_service.  An MSOWorkflowException will\r
+ * be thrown upon unsuccessful completion or if an error occurs\r
+ * at any time during this sub flow. Please map variables\r
+ * to the corresponding variable names below.\r
+ *\r
+ * Note - If this sub flow receives a Not Found (404) response\r
+ * from AAI at any time this will be considered an acceptable\r
+ * successful response however the GENGS_FoundIndicator\r
+ * will be set to false. This variable will allow the calling flow\r
+ * to distinguish between the two Success scenarios,\r
+ * "Success where service- is found" and\r
+ * "Success where service- is NOT found".\r
+ *\r
+ *\r
+ * Variable Mapping Below:\r
+ *\r
+ * In Mapping Variables:\r
+ *   For Allotted-Resource:\r
+ *     @param - GENGS_allottedResourceId\r
+ *     @param - GENGS_type\r
+ *     @param (Optional) - GENGS_serviceInstanceId\r
+ *     @param (Optional) - GENGS_serviceType\r
+ *     @param (Optional) - GENGS_globalCustomerId\r
+ *\r
+ *   For Service-Instance:\r
+ *     @param - GENGS_serviceInstanceId or @param - GENGS_serviceInstanceName\r
+ *     @param - GENGS_type\r
+ *     @param (Optional) - GENGS_serviceType\r
+ *     @param (Optional) - GENGS_globalCustomerId\r
+ *\r
+ *   For Service-Subscription:\r
+ *     @param - GENGS_type\r
+ *     @param - GENGS_serviceType\r
+ *     @param - GENGS_globalCustomerId\r
+ *\r
+ *\r
+ * Out Mapping Variables:\r
+ *    @param - GENGS_service\r
+ *    @param - GENGS_FoundIndicator\r
+ *    @param - WorkflowException\r
+ */\r
+class CustomE2EGetService extends AbstractServiceTaskProcessor{\r
+\r
+       String Prefix = "GENGS_"\r
+       ExceptionUtil exceptionUtil = new ExceptionUtil()\r
+\r
+       /**\r
+        * This method validates the incoming variables and\r
+        * determines the subsequent event based on which\r
+        * variables the calling flow provided.\r
+        *\r
+        * @param - execution\r
+        *\r
+        */\r
+       public void preProcessRequest(Execution execution) {\r
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+               execution.setVariable("prefix",Prefix)\r
+               utils.log("DEBUG", " *** STARTED GenericGetService PreProcessRequest Process*** ", isDebugEnabled)\r
+\r
+               execution.setVariable("GENGS_obtainObjectsUrl", false)\r
+               execution.setVariable("GENGS_obtainServiceInstanceUrlByName", false)\r
+               execution.setVariable("GENGS_SuccessIndicator", false)\r
+               execution.setVariable("GENGS_FoundIndicator", false)\r
+               execution.setVariable("GENGS_resourceLink", null)\r
+               execution.setVariable("GENGS_siResourceLink", null)\r
+\r
+               try{\r
+                       // Get Variables\r
+                       String allottedResourceId = execution.getVariable("GENGS_allottedResourceId")\r
+                       String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")\r
+                       String serviceInstanceName = execution.getVariable("GENGS_serviceInstanceName")\r
+                       String serviceType = execution.getVariable("GENGS_serviceType")\r
+                       String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
+                       String type = execution.getVariable("GENGS_type")\r
+\r
+                       if(type != null){\r
+                               utils.log("DEBUG", "Incoming GENGS_type is: " + type, isDebugEnabled)\r
+                               if(type.equalsIgnoreCase("allotted-resource")){\r
+                                       if(isBlank(allottedResourceId)){\r
+                                               utils.log("DEBUG", "Incoming allottedResourceId is null. Allotted Resource Id is required to Get an allotted-resource.", isDebugEnabled)\r
+                                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming allottedResourceId is null. Allotted Resource Id is required to Get an allotted-resource.")\r
+                                       }else{\r
+                                               utils.log("DEBUG", "Incoming Allotted Resource Id is: " + allottedResourceId, isDebugEnabled)\r
+                                               if(isBlank(globalCustomerId) || isBlank(serviceType) || isBlank(serviceInstanceId)){\r
+                                                       execution.setVariable("GENGS_obtainObjectsUrl", true)\r
+                                               }else{\r
+                                                       utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)\r
+                                                       utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)\r
+                                                       utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
+                                               }\r
+                                       }\r
+                               }else if(type.equalsIgnoreCase("service-instance")){\r
+                                       if(isBlank(serviceInstanceId) && isBlank(serviceInstanceName)){\r
+                                               utils.log("DEBUG", "Incoming serviceInstanceId and serviceInstanceName are null. ServiceInstanceId or ServiceInstanceName is required to Get a service-instance.", isDebugEnabled)\r
+                                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming serviceInstanceId and serviceInstanceName are null. ServiceInstanceId or ServiceInstanceName is required to Get a service-instance.")\r
+                                       }else{\r
+                                               utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)\r
+                                               utils.log("DEBUG", "Incoming Service Instance Name is: " + serviceInstanceName, isDebugEnabled)\r
+                                               if(isBlank(globalCustomerId) || isBlank(serviceType)){\r
+                                                       execution.setVariable("GENGS_obtainObjectsUrl", true)\r
+                                                       if(isBlank(serviceInstanceId)){\r
+                                                               execution.setVariable("GENGS_obtainServiceInstanceUrlByName", true)\r
+                                                       }\r
+                                               }else{\r
+                                                       utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
+                                                       utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)\r
+                                               }\r
+                                       }\r
+                               }else if(type.equalsIgnoreCase("service-subscription")){\r
+                                       if(isBlank(serviceType) || isBlank(globalCustomerId)){\r
+                                               utils.log("DEBUG", "Incoming ServiceType or GlobalCustomerId is null. These variables are required to Get a service-subscription.", isDebugEnabled)\r
+                                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming ServiceType or GlobalCustomerId is null. These variables are required to Get a service-subscription.")\r
+                                       }else{\r
+                                               utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)\r
+                                               utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
+                                       }\r
+                               }else{\r
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Type is Invalid. Please Specify Type as service-instance or service-subscription")\r
+                               }\r
+                       }else{\r
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Incoming GENGS_type is null. Variable is Required.")\r
+                       }\r
+\r
+               }catch(BpmnError b){\r
+                       utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
+                       throw b\r
+               }catch(Exception e){\r
+                       utils.log("DEBUG", "Internal Error encountered within GenericGetService PreProcessRequest method!" + e, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in GenericGetService PreProcessRequest")\r
+\r
+               }\r
+               utils.log("DEBUG", "*** COMPLETED GenericGetService PreProcessRequest Process ***", isDebugEnabled)\r
+       }\r
+\r
+       /**\r
+        * This method obtains the Url to the provided service instance\r
+        * using the Service Instance Id.\r
+        *\r
+        * @param - execution\r
+        */\r
+       public void obtainServiceInstanceUrlById(Execution execution){\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               execution.setVariable("prefix",Prefix)\r
+               utils.log("DEBUG", " *** STARTED GenericGetService ObtainServiceInstanceUrlById Process*** ", isDebugEnabled)\r
+               try {\r
+                       AaiUtil aaiUriUtil = new AaiUtil(this)\r
+                       String aai_uri = aaiUriUtil.getSearchNodesQueryEndpoint(execution)\r
+                       String aai_endpoint = execution.getVariable("URN_aai_endpoint")\r
+\r
+                       String type = execution.getVariable("GENGS_type")\r
+                       String path = ""\r
+                       if(type.equalsIgnoreCase("service-instance")){\r
+                               String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")\r
+                               utils.log("DEBUG", " Querying Node for Service-Instance URL by using Service-Instance Id: " + serviceInstanceId, isDebugEnabled)\r
+                               path = "${aai_uri}?search-node-type=service-instance&filter=service-instance-id:EQUALS:${serviceInstanceId}"\r
+                               utils.logAudit("Service Instance Node Query Url is: " + path)\r
+                               utils.log("DEBUG", "Service Instance Node Query Url is: " + path, isDebugEnabled)\r
+                       }else if(type.equalsIgnoreCase("allotted-resource")){\r
+                               String allottedResourceId = execution.getVariable("GENGS_allottedResourceId")\r
+                               utils.log("DEBUG", " Querying Node for Service-Instance URL by using Allotted Resource Id: " + allottedResourceId, isDebugEnabled)\r
+                               path = "${aai_uri}?search-node-type=allotted-resource&filter=id:EQUALS:${allottedResourceId}"\r
+                               utils.logAudit("Allotted Resource Node Query Url is: " + path)\r
+                               utils.log("DEBUG", "Allotted Resource Node Query Url is: " + path, isDebugEnabled)\r
+                       }\r
+\r
+                       //String url = "${aai_endpoint}${path}"  host name needs to be removed from property\r
+                       String url = "${path}"\r
+                       execution.setVariable("GENGS_genericQueryPath", url)\r
+\r
+                       APIResponse response = aaiUriUtil.executeAAIGetCall(execution, url)\r
+                       int responseCode = response.getStatusCode()\r
+                       execution.setVariable("GENGS_genericQueryResponseCode", responseCode)\r
+                       utils.log("DEBUG", "  GET Service Instance response code is: " + responseCode, isDebugEnabled)\r
+                       utils.logAudit("GenericGetService AAI GET Response Code: " + responseCode)\r
+\r
+                       String aaiResponse = response.getResponseBodyAsString()\r
+                       execution.setVariable("GENGS_obtainSIUrlResponseBeforeUnescaping", aaiResponse)\r
+                       utils.log("DEBUG", "GenericGetService AAI Response before unescaping: " + aaiResponse, isDebugEnabled)\r
+                       aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)\r
+                       execution.setVariable("GENGS_genericQueryResponse", aaiResponse)\r
+                       utils.logAudit("GenericGetService AAI Response: " + aaiResponse)\r
+                       utils.log("DEBUG", "GenericGetService AAI Response: " + aaiResponse, isDebugEnabled)\r
+\r
+                       //Process Response\r
+                       if(responseCode == 200){\r
+                               utils.log("DEBUG", "Generic Query Received a Good Response Code", isDebugEnabled)\r
+                               execution.setVariable("GENGS_SuccessIndicator", true)\r
+                               if(utils.nodeExists(aaiResponse, "result-data")){\r
+                                       utils.log("DEBUG", "Generic Query Response Does Contain Data" , isDebugEnabled)\r
+                                       execution.setVariable("GENGS_FoundIndicator", true)\r
+                                       String resourceLink = utils.getNodeText1(aaiResponse, "resource-link")\r
+                                       execution.setVariable("GENGS_resourceLink", resourceLink)\r
+                                       execution.setVariable("GENGS_siResourceLink", resourceLink)\r
+                               }else{\r
+                                       utils.log("DEBUG", "Generic Query Response Does NOT Contains Data" , isDebugEnabled)\r
+                                       execution.setVariable("WorkflowResponse", "  ") //for junits\r
+                               }\r
+                       }else if(responseCode == 404){\r
+                               utils.log("DEBUG", "Generic Query Received a Not Found (404) Response", isDebugEnabled)\r
+                               execution.setVariable("GENGS_SuccessIndicator", true)\r
+                               execution.setVariable("WorkflowResponse", "  ") //for junits\r
+                       }else{\r
+                               utils.log("DEBUG", "Generic Query Received a BAD REST Response: \n" + aaiResponse, isDebugEnabled)\r
+                               exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)\r
+                               throw new BpmnError("MSOWorkflowException")\r
+                       }\r
+               }catch(BpmnError b){\r
+                       utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
+                       throw b\r
+               }catch(Exception e){\r
+                       utils.log("ERROR", " Error encountered within GenericGetService ObtainServiceInstanceUrlById method!" + e, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During ObtainServiceInstanceUrlById")\r
+               }\r
+               utils.log("DEBUG", " *** COMPLETED GenericGetService ObtainServiceInstanceUrlById Process*** ", isDebugEnabled)\r
+       }\r
+\r
+       /**\r
+        * This method obtains the Url to the provided service instance\r
+        * using the Service Instance Name.\r
+        *\r
+        * @param - execution\r
+        */\r
+       public void obtainServiceInstanceUrlByName(Execution execution){\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               execution.setVariable("prefix",Prefix)\r
+               utils.log("DEBUG", " *** STARTED GenericGetService ObtainServiceInstanceUrlByName Process*** ", isDebugEnabled)\r
+               try {\r
+                       String serviceInstanceName = execution.getVariable("GENGS_serviceInstanceName")\r
+                       utils.log("DEBUG", " Querying Node for Service-Instance URL by using Service-Instance Name " + serviceInstanceName, isDebugEnabled)\r
+\r
+                       AaiUtil aaiUriUtil = new AaiUtil(this)\r
+                       String aai_uri = aaiUriUtil.getSearchNodesQueryEndpoint(execution)\r
+                       String aai_endpoint = execution.getVariable("URN_aai_endpoint")\r
+                       String path = "${aai_uri}?search-node-type=service-instance&filter=service-instance-name:EQUALS:${serviceInstanceName}"\r
+\r
+                       //String url = "${aai_endpoint}${path}"  host name needs to be removed from property\r
+                       String url = "${path}"\r
+                       execution.setVariable("GENGS_obtainSIUrlPath", url)\r
+\r
+                       utils.logAudit("GenericGetService AAI Endpoint: " + aai_endpoint)\r
+                       APIResponse response = aaiUriUtil.executeAAIGetCall(execution, url)\r
+                       int responseCode = response.getStatusCode()\r
+                       execution.setVariable("GENGS_obtainSIUrlResponseCode", responseCode)\r
+                       utils.log("DEBUG", "  GET Service Instance response code is: " + responseCode, isDebugEnabled)\r
+                       utils.logAudit("GenericGetService AAI Response Code: " + responseCode)\r
+\r
+                       String aaiResponse = response.getResponseBodyAsString()\r
+                       aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)\r
+                       execution.setVariable("GENGS_obtainSIUrlResponse", aaiResponse)\r
+                       utils.logAudit("GenericGetService AAI Response: " + aaiResponse)\r
+                       //Process Response\r
+                       if(responseCode == 200){\r
+                               utils.log("DEBUG", "  Query for Service Instance Url Received a Good Response Code", isDebugEnabled)\r
+                               execution.setVariable("GENGS_SuccessIndicator", true)\r
+                               if(utils.nodeExists(aaiResponse, "result-data")){\r
+                                       utils.log("DEBUG", "Query for Service Instance Url Response Does Contain Data" , isDebugEnabled)\r
+                                       execution.setVariable("GENGS_FoundIndicator", true)\r
+                                       String resourceLink = utils.getNodeText1(aaiResponse, "resource-link")\r
+                                       execution.setVariable("GENGS_resourceLink", resourceLink)\r
+                                       execution.setVariable("GENGS_siResourceLink", resourceLink)\r
+                               }else{\r
+                                       utils.log("DEBUG", "Query for Service Instance Url Response Does NOT Contains Data" , isDebugEnabled)\r
+                                       execution.setVariable("WorkflowResponse", "  ") //for junits\r
+                               }\r
+                       }else if(responseCode == 404){\r
+                               utils.log("DEBUG", "  Query for Service Instance Received a Not Found (404) Response", isDebugEnabled)\r
+                               execution.setVariable("GENGS_SuccessIndicator", true)\r
+                               execution.setVariable("WorkflowResponse", "  ") //for junits\r
+                       }else{\r
+                               utils.log("DEBUG", "Query for Service Instance Received a BAD REST Response: \n" + aaiResponse, isDebugEnabled)\r
+                               exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)\r
+                               throw new BpmnError("MSOWorkflowException")\r
+                       }\r
+               }catch(BpmnError b){\r
+                       utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
+                       throw b\r
+               }catch(Exception e){\r
+                       utils.log("ERROR", " Error encountered within GenericGetService ObtainServiceInstanceUrlByName method!" + e, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During ObtainServiceInstanceUrlByName")\r
+               }\r
+               utils.log("DEBUG", " *** COMPLETED GenericGetService ObtainServiceInstanceUrlByName Process*** ", isDebugEnabled)\r
+       }\r
+\r
+\r
+       /**\r
+        * This method executes a GET call to AAI to obtain the\r
+        * service-instance or service-subscription\r
+        *\r
+        * @param - execution\r
+        */\r
+       public void getServiceObject(Execution execution){\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               execution.setVariable("prefix",Prefix)\r
+               utils.log("DEBUG", " *** STARTED GenericGetService GetServiceObject Process*** ", isDebugEnabled)\r
+               try {\r
+                       String type = execution.getVariable("GENGS_type")\r
+                       AaiUtil aaiUriUtil = new AaiUtil(this)\r
+                       String aai_endpoint = execution.getVariable("URN_aai_endpoint")\r
+                       String serviceEndpoint = ""\r
+\r
+                       utils.logAudit("GenericGetService getServiceObject AAI Endpoint: " + aai_endpoint)\r
+                       if(type.equalsIgnoreCase("service-instance")){\r
+                               String siResourceLink = execution.getVariable("GENGS_resourceLink")\r
+                               if(isBlank(siResourceLink)){\r
+                                       String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")\r
+                                       utils.log("DEBUG", " Incoming GENGS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)\r
+                                       String serviceType = execution.getVariable("GENGS_serviceType")\r
+                                       utils.log("DEBUG", " Incoming GENGS_serviceType is: " + serviceType, isDebugEnabled)\r
+                                       String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
+                                       utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
+\r
+                                       String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
+                                       logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)\r
+                                       serviceEndpoint = "${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8")\r
+                               }else{\r
+                                       utils.log("DEBUG", "Incoming Service Instance Url is: " + siResourceLink, isDebugEnabled)\r
+                                       String[] split = siResourceLink.split("/aai/")\r
+                                       serviceEndpoint = "/aai/" + split[1]\r
+                               }\r
+                       }else if(type.equalsIgnoreCase("allotted-resource")){\r
+                               String siResourceLink = execution.getVariable("GENGS_resourceLink")\r
+                               if(isBlank(siResourceLink)){\r
+                                       String allottedResourceId = execution.getVariable("GENGS_allottedResourceId")\r
+                                       utils.log("DEBUG", " Incoming GENGS_allottedResourceId is: " + allottedResourceId, isDebugEnabled)\r
+                                       String serviceInstanceId = execution.getVariable("GENGS_serviceInstanceId")\r
+                                       utils.log("DEBUG", " Incoming GENGS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)\r
+                                       String serviceType = execution.getVariable("GENGS_serviceType")\r
+                                       utils.log("DEBUG", " Incoming GENGS_serviceType is: " + serviceType, isDebugEnabled)\r
+                                       String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
+                                       utils.log("DEBUG", "Incoming Global Customer Id is: " + globalCustomerId, isDebugEnabled)\r
+\r
+                                       String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
+                                       logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)\r
+                                       serviceEndpoint = "${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8") +  "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8")\r
+                               }else{\r
+                                       utils.log("DEBUG", "Incoming Allotted-Resource Url is: " + siResourceLink, isDebugEnabled)\r
+                                       String[] split = siResourceLink.split("/aai/")\r
+                                       serviceEndpoint = "/aai/" + split[1]\r
+                               }\r
+                       }else if(type.equalsIgnoreCase("service-subscription")){\r
+                               String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)\r
+                               String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
+                               String serviceType = execution.getVariable("GENGS_serviceType")\r
+                               serviceEndpoint = "${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8")\r
+                       }\r
+\r
+                       String serviceUrl = "${aai_endpoint}" + serviceEndpoint\r
+\r
+                       execution.setVariable("GENGS_getServiceUrl", serviceUrl)\r
+                       utils.log("DEBUG", "GET Service AAI Path is: \n" + serviceUrl, isDebugEnabled)\r
+\r
+                       APIResponse response = aaiUriUtil.executeAAIGetCall(execution, serviceUrl)\r
+                       int responseCode = response.getStatusCode()\r
+                       execution.setVariable("GENGS_getServiceResponseCode", responseCode)\r
+                       utils.log("DEBUG", "  GET Service response code is: " + responseCode, isDebugEnabled)\r
+                       utils.logAudit("GenericGetService AAI Response Code: " + responseCode)\r
+\r
+                       String aaiResponse = response.getResponseBodyAsString()\r
+                       aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)\r
+                       execution.setVariable("GENGS_getServiceResponse", aaiResponse)\r
+                       utils.logAudit("GenericGetService AAI Response: " + aaiResponse)\r
+                       //Process Response\r
+                       if(responseCode == 200 || responseCode == 202){\r
+                               utils.log("DEBUG", "GET Service Received a Good Response Code", isDebugEnabled)\r
+                               if(utils.nodeExists(aaiResponse, "service-instance") || utils.nodeExists(aaiResponse, "service-subscription")){\r
+                                       utils.log("DEBUG", "GET Service Response Contains a service-instance" , isDebugEnabled)\r
+                                       execution.setVariable("GENGS_FoundIndicator", true)\r
+                                       execution.setVariable("GENGS_service", aaiResponse)\r
+                                       execution.setVariable("WorkflowResponse", aaiResponse)\r
+\r
+                               }else{\r
+                                       utils.log("DEBUG", "GET Service Response Does NOT Contain Data" , isDebugEnabled)\r
+                               }\r
+                       }else if(responseCode == 404){\r
+                               utils.log("DEBUG", "GET Service Received a Not Found (404) Response", isDebugEnabled)\r
+                               execution.setVariable("WorkflowResponse", "  ") //for junits\r
+                       }\r
+                       else{\r
+                               utils.log("DEBUG", "  GET Service Received a Bad Response: \n" + aaiResponse, isDebugEnabled)\r
+                               exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)\r
+                               throw new BpmnError("MSOWorkflowException")\r
+                       }\r
+               }catch(BpmnError b){\r
+                       utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)\r
+                       throw b\r
+               }catch(Exception e){\r
+                       utils.log("DEBUG", " Error encountered within GenericGetService GetServiceObject method!" + e, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During GenericGetService")\r
+               }\r
+               utils.log("DEBUG", " *** COMPLETED GenericGetService GetServiceObject Process*** ", isDebugEnabled)\r
+       }\r
+\r
+}
\ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/CustomE2EPutService.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/CustomE2EPutService.groovy
new file mode 100644 (file)
index 0000000..eaccdc0
--- /dev/null
@@ -0,0 +1,280 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.openecomp.mso.bpmn.common.scripts
+
+import static org.apache.commons.lang3.StringUtils.*;
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.runtime.Execution;
+import org.apache.commons.codec.binary.Base64
+import org.apache.commons.lang3.*
+
+import org.openecomp.mso.bpmn.core.json.JsonUtils
+import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.rest.APIResponse;
+import org.openecomp.mso.rest.RESTClient
+import org.openecomp.mso.rest.RESTConfig
+
+import java.net.URLEncoder;
+import org.springframework.web.util.UriUtils
+
+/**
+ * This class supports the GenericPutService Sub Flow.
+ * This Generic sub flow can be used by any flow for the
+ * goal of creating a Service Instance or Service-Subscription in AAI. Upon successful completion of
+ * this sub flow the GENPS_SuccessIndicator will be true.
+ * The calling flow must set the GENPS_type variable as "service-instance"
+ * or "service-subscription".
+ *  A MSOWorkflowException will be thrown Upon unsuccessful
+ * completion or if an error occurs within this flow.
+ * Please map variables to the corresponding variable names
+ * below.
+ *
+ *
+ * Incoming Required Variables:
+ * @param - GENPS_requestId
+ * @param - GENPS_type - Required field. This will be required field populated as service-instance or service-subscription
+ * @param - GENPS_globalSubscriberId - Required field
+ * @param - GENPS_serviceType - Required Field
+ * @param - GENPS_payload - Required Field This will be the payload that needs to be sent.
+ *
+ * @param - GENPS_serviceInstanceId - Conditional Field. Required for service-instance.
+ * @param - GENPS_allottedResourceId - Conditional Field. Required for allotted-resource.
+ * @param - GENPS_tunnelXconnectId - Conditional Field. Required for tunnel-xconnect.
+ *
+ * @param - GENPS_serviceResourceVersion - Conditional Field. Needs to be provided only in case of update for both service-instance and service subscription. The calling flows
+ *          should check if a service-instance or servic-subscription exists by calling the subflow GenericGetService. if it exists then resourceversion should be
+ *          obtained from aai and sent as an input parameter.
+ *
+ * Outgoing Variables:
+ * @param - GENPS_SuccessIndicator
+ * @param - WorkflowException
+ *
+ *
+ */
+
+
+class CustomE2EPutService extends AbstractServiceTaskProcessor{
+
+       String Prefix = "GENPS_"
+       ExceptionUtil exceptionUtil = new ExceptionUtil()
+
+
+       public void preProcessRequest(Execution execution) {
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+               execution.setVariable("prefix",Prefix)
+               utils.log("DEBUG", " *** STARTED GenericPutService PreProcessRequest Process*** ", isDebugEnabled)
+
+               execution.setVariable("GENPS_SuccessIndicator", false)
+
+               try{
+                       // Get Variables
+                       String requestId = execution.getVariable("GENPS_requestId")
+                       utils.log("DEBUG", "Incoming GENPS_requestId is: " + requestId, isDebugEnabled)
+
+                       String globalSubscriberId = execution.getVariable("GENPS_globalSubscriberId")
+                       String serviceInstanceId = execution.getVariable("GENPS_serviceInstanceId")
+                       String serviceType = execution.getVariable("GENPS_serviceType")
+                       String allottedResourceId = execution.getVariable("GENPS_allottedResourceId")
+                       String tunnelXconnectId = execution.getVariable("GENPS_tunnelXconnectId")
+                       String type = execution.getVariable("GENPS_type")
+
+                       if(type != null){
+                               utils.log("DEBUG", "Incoming GENPS_type is: " + type, isDebugEnabled)
+                               if(type.equalsIgnoreCase("service-instance")){
+                                       if(isBlank(globalSubscriberId) || isBlank(serviceType) || isBlank(serviceInstanceId)){
+                                               utils.log("DEBUG", "Incoming Required Variable is missing or null!", isDebugEnabled)
+                                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Required Variable is Missing or Null!")
+                                       }else{
+                                               utils.log("DEBUG", "Incoming Global Subscriber Id is: " + globalSubscriberId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
+                                       }
+                               }else if(type.equalsIgnoreCase("service-subscription")){
+                                       if(isBlank(serviceType) || isBlank(globalSubscriberId)){
+                                               utils.log("DEBUG", "Incoming ServiceType or GlobalSubscriberId is null. These variables are required to create a service-subscription.", isDebugEnabled)
+                                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming ServiceType or GlobalCustomerId is null. These variables are required to Get a service-subscription.")
+                                       }else{
+                                               utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Global Subscriber Id is: " + globalSubscriberId, isDebugEnabled)
+                                       }
+                               }else if(type.equalsIgnoreCase("allotted-resource")){
+                                       if(isBlank(globalSubscriberId) || isBlank(serviceType) || isBlank(serviceInstanceId) || isBlank(allottedResourceId)){
+                                               utils.log("DEBUG", "Incoming Global Subscriber Id is: " + globalSubscriberId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Allotted Resource Id is: " + allottedResourceId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Required Variable is missing or null!", isDebugEnabled)
+                                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Required Variable is Missing or Null!")
+                                       }else{
+                                               utils.log("DEBUG", "Incoming Global Subscriber Id is: " + globalSubscriberId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Allotted Resource Id is: " + allottedResourceId, isDebugEnabled)
+                                       }
+                               }else if(type.equalsIgnoreCase("tunnel-xconnect")){
+                                       if(isBlank(globalSubscriberId) || isBlank(serviceType) || isBlank(serviceInstanceId) || isBlank(allottedResourceId) || isBlank(tunnelXconnectId)){
+                                               utils.log("DEBUG", "Incoming Global Subscriber Id is: " + globalSubscriberId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Allotted Resource Id is: " + allottedResourceId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Tunnel Xconnect Id is: " + tunnelXconnectId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Required Variable is missing or null!", isDebugEnabled)
+                                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Required Variable is Missing or Null!")
+                                       }else{
+                                               utils.log("DEBUG", "Incoming Global Subscriber Id is: " + globalSubscriberId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Service Type is: " + serviceType, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Allotted Resource Id is: " + allottedResourceId, isDebugEnabled)
+                                               utils.log("DEBUG", "Incoming Tunnel Xconnect Id is: " + tunnelXconnectId, isDebugEnabled)
+                                       }
+                               }else{
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Type is Invalid. Please Specify Type as service-instance or service-subscription")
+                               }
+                       }else{
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Incoming GENPS_type is null. Variable is Required.")
+                       }
+
+               }catch(BpmnError b){
+                       utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
+                       throw b
+               }catch(Exception e){
+                       utils.log("ERROR", " Error encountered within GenericPutService PreProcessRequest method!" + e, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in GenericPutService PreProcessRequest")
+
+               }
+               utils.log("DEBUG", "*** COMPLETED GenericPutService PreProcessRequest Process ***", isDebugEnabled)
+
+       }
+
+
+
+       /**
+        * This method executes a Put call to AAI for the provided
+        * service instance.
+        *
+        * @param - execution
+        *
+        */
+       public void putServiceInstance(Execution execution){
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               execution.setVariable("prefix",Prefix)
+               utils.log("DEBUG", " *** STARTED GenericPutService PutServiceInstance method*** ", isDebugEnabled)
+               try {
+                       String type = execution.getVariable("GENPS_type")
+
+                       AaiUtil aaiUriUtil = new AaiUtil(this)
+                       String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
+                       logDebug('AAI URI is: ' + aai_uri, isDebugEnabled)
+                       String namespace = aaiUriUtil.getNamespaceFromUri(execution, aai_uri)
+                       logDebug('AAI namespace is: ' + namespace, isDebugEnabled)
+
+                       String aai_endpoint = execution.getVariable("URN_aai_endpoint")
+                       String serviceAaiPath = ""
+                       String payload = execution.getVariable("GENPS_payload")
+                       execution.setVariable("GENPS_payload", payload)
+                       utils.log("DEBUG", "Incoming GENPS_payload is: " + payload, isDebugEnabled)
+                       utils.logAudit(payload)
+
+                       String serviceType = execution.getVariable("GENPS_serviceType")
+                       utils.log("DEBUG", " Incoming GENPS_serviceType is: " + serviceType, isDebugEnabled)
+                       String globalSubscriberId = execution.getVariable("GENPS_globalSubscriberId")
+                       utils.log("DEBUG", "Incoming Global Subscriber Id is: " + globalSubscriberId, isDebugEnabled)
+
+                       // This IF clause is if we need to create a new Service Instance
+                       if(type.equalsIgnoreCase("service-instance")){
+
+                               String serviceInstanceId = execution.getVariable("GENPS_serviceInstanceId")
+                               utils.log("DEBUG", " Incoming GENPS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)
+
+                               //      serviceAaiPath = "${aai_endpoint}${aai_uri}/"  + URLEncoder.encode(globalSubscriberId,"UTF-8") + "/service-subscriptions/service-subscription/" + URLEncoder.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + URLEncoder.encode(serviceInstanceId,"UTF-8")
+                               serviceAaiPath = "${aai_endpoint}${aai_uri}/"  + UriUtils.encode(globalSubscriberId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8")
+
+                       }else if(type.equalsIgnoreCase("service-subscription")){
+
+                               //      serviceAaiPath = "${aai_endpoint}${aai_uri}/"  + URLEncoder.encode(globalSubscriberId,"UTF-8") + "/service-subscriptions/service-subscription/" + URLEncoder.encode(serviceType,"UTF-8")
+                               serviceAaiPath = "${aai_endpoint}${aai_uri}/"  + UriUtils.encode(globalSubscriberId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8")
+                       }else if(type.equalsIgnoreCase("allotted-resource")){
+
+                               String serviceInstanceId = execution.getVariable("GENPS_serviceInstanceId")
+                               utils.log("DEBUG", " Incoming GENPS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)
+                               String allottedResourceId = execution.getVariable("GENPS_allottedResourceId")
+                               utils.log("DEBUG", " Incoming GENPS_allottedResourceId is: " + allottedResourceId, isDebugEnabled)
+
+                               //      serviceAaiPath = "${aai_endpoint}${aai_uri}/"  + URLEncoder.encode(globalSubscriberId,"UTF-8") + "/service-subscriptions/service-subscription/" + URLEncoder.encode(serviceType,"UTF-8")
+                               serviceAaiPath = "${aai_endpoint}${aai_uri}/"  + UriUtils.encode(globalSubscriberId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8") + "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8")
+                       }else if(type.equalsIgnoreCase("tunnel-xconnect")){
+
+                               String serviceInstanceId = execution.getVariable("GENPS_serviceInstanceId")
+                               utils.log("DEBUG", " Incoming GENPS_serviceInstanceId is: " + serviceInstanceId, isDebugEnabled)
+                               String allottedResourceId = execution.getVariable("GENPS_allottedResourceId")
+                               utils.log("DEBUG", " Incoming GENPS_allottedResourceId is: " + allottedResourceId, isDebugEnabled)
+                               String tunnelXconnectId = execution.getVariable("GENPS_tunnelXconnectId")
+                               utils.log("DEBUG", " Incoming GENPS_tunnelXconnectId is: " + tunnelXconnectId, isDebugEnabled)
+
+                               //      serviceAaiPath = "${aai_endpoint}${aai_uri}/"  + URLEncoder.encode(globalSubscriberId,"UTF-8") + "/service-subscriptions/service-subscription/" + URLEncoder.encode(serviceType,"UTF-8")
+                               serviceAaiPath = "${aai_endpoint}${aai_uri}/"  + UriUtils.encode(globalSubscriberId,"UTF-8") + "/service-subscriptions/service-subscription/" + UriUtils.encode(serviceType,"UTF-8") + "/service-instances/service-instance/" + UriUtils.encode(serviceInstanceId,"UTF-8") + "/allotted-resources/allotted-resource/" + UriUtils.encode(allottedResourceId,"UTF-8") + "/tunnel-xconnects/tunnel-xconnect/" + UriUtils.encode(tunnelXconnectId,"UTF-8")
+                       }
+
+                       String resourceVersion = execution.getVariable("GENPS_serviceResourceVersion")
+                       utils.log("DEBUG", "Incoming Resource Version is: " + resourceVersion, isDebugEnabled)
+                       if(resourceVersion !=null){
+                               serviceAaiPath = serviceAaiPath +'?resource-version=' + UriUtils.encode(resourceVersion,"UTF-8")
+                       }
+
+                       execution.setVariable("GENPS_putServiceInstanceAaiPath", serviceAaiPath)
+                       utils.log("DEBUG", "PUT Service Instance AAI Path is: " + "\n" + serviceAaiPath, isDebugEnabled)
+
+                       APIResponse response = aaiUriUtil.executeAAIPutCall(execution, serviceAaiPath, payload)
+                       int responseCode = response.getStatusCode()
+                       execution.setVariable("GENPS_putServiceInstanceResponseCode", responseCode)
+                       utils.log("DEBUG", "  Put Service Instance response code is: " + responseCode, isDebugEnabled)
+
+                       String aaiResponse = response.getResponseBodyAsString()
+                       aaiResponse = StringEscapeUtils.unescapeXml(aaiResponse)
+                       execution.setVariable("GENPS_putServiceInstanceResponse", aaiResponse)
+
+
+                       //Process Response
+                       if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
+                               //200 OK 201 CREATED 202 ACCEPTED
+                       {
+                               utils.log("DEBUG", "PUT Service Instance Received a Good Response", isDebugEnabled)
+                               execution.setVariable("GENPS_SuccessIndicator", true)
+                       }
+
+                       else{
+                               utils.log("DEBUG", "Put Generic Service Instance Received a Bad Response Code. Response Code is: " + responseCode, isDebugEnabled)
+                               exceptionUtil.MapAAIExceptionToWorkflowExceptionGeneric(execution, aaiResponse, responseCode)
+                               throw new BpmnError("MSOWorkflowException")
+                       }
+               }catch(BpmnError b){
+                       utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
+                       throw b
+               }catch(Exception e){
+                       utils.log("ERROR", " Error encountered within GenericPutService PutServiceInstance method!" + e, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured During Put Service Instance")
+               }
+               utils.log("DEBUG", " *** COMPLETED GenericPutService PutServiceInstance Process*** ", isDebugEnabled)
+       }
+
+
+
+}
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateCustomE2EServiceInstance.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/CreateCustomE2EServiceInstance.groovy
new file mode 100644 (file)
index 0000000..f376c44
--- /dev/null
@@ -0,0 +1,327 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.openecomp.mso.bpmn.infrastructure.scripts;
+
+import static org.apache.commons.lang3.StringUtils.*;
+import groovy.xml.XmlUtil
+import groovy.json.*
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
+import org.openecomp.mso.bpmn.common.scripts.VidUtils
+import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.bpmn.core.json.JsonUtils
+import org.openecomp.mso.rest.APIResponse
+
+import java.util.UUID;
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.runtime.Execution
+import org.apache.commons.lang3.*
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.web.util.UriUtils
+
+/**
+ * This groovy class supports the <class>CreateServiceInstance.bpmn</class> process.
+ * AlaCarte flow for 1702 ServiceInstance Create
+ *
+ */
+public class CreateCustomE2EServiceInstance extends AbstractServiceTaskProcessor {
+       String Prefix="CRESI_"
+       ExceptionUtil exceptionUtil = new ExceptionUtil()
+       JsonUtils jsonUtil = new JsonUtils()
+       VidUtils vidUtils = new VidUtils()
+
+       public void preProcessRequest (Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               execution.setVariable("prefix",Prefix)
+               String msg = ""
+               utils.log("DEBUG", " *** preProcessRequest() *** ", isDebugEnabled)
+
+               try {
+
+                       String siRequest = execution.getVariable("bpmnRequest")
+                       utils.logAudit(siRequest)
+
+                       String requestId = execution.getVariable("mso-request-id")
+                       execution.setVariable("msoRequestId", requestId)
+                       utils.log("DEBUG", "Input Request:" + siRequest + " reqId:" + requestId, isDebugEnabled)
+
+                       String serviceInstanceId = execution.getVariable("serviceInstanceId")
+                       if (isBlank(serviceInstanceId)) {
+                               serviceInstanceId = UUID.randomUUID().toString()
+                       }
+                       utils.log("DEBUG", "Generated new Service Instance:" + serviceInstanceId, isDebugEnabled)
+                       serviceInstanceId = UriUtils.encode(serviceInstanceId,"UTF-8")
+                       execution.setVariable("serviceInstanceId", serviceInstanceId)
+
+                       //parameters
+                       String p_domainHost = jsonUtil.getJsonValue(siRequest, "service.parameters.domainHost")
+                       if (isBlank(p_domainHost)) {
+                               msg = "Input parameters domainHost is null"
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else {
+                               execution.setVariable("p_domainHost", p_domainHost)
+                       }
+
+                       String p_nodeTemplateName = jsonUtil.getJsonValue(siRequest, "service.parameters.nodeTemplateName")
+                       if (isBlank(p_nodeTemplateName)) {
+                               msg = "Input parameters nodeTemplateName is null"
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else {
+                               execution.setVariable("p_nodeTemplateName", p_nodeTemplateName)
+                       }
+                       
+                       String p_nodeType = jsonUtil.getJsonValue(siRequest, "service.parameters.nodeType")
+                       if (isBlank(p_nodeType)) {
+                               msg = "Input parameters nodeType is null"
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else {
+                               execution.setVariable("p_nodeType", p_nodeType)
+                       }
+
+                       //segments
+                       def jsonSlurper = new JsonSlurper()
+                       //def jsonOutput = new JsonOutput()
+
+                       Map reqMap = jsonSlurper.parseText(siRequest)           
+                       
+                       def p_segments = reqMap.service?.parameters?.segments
+                       
+                       //List<Segment> segList = []
+                       //if (p_segments) {
+                       //    p_segments.each {
+                       //              p_segment -> segList.add(p_segment)
+                       //              //p_segment.domainHost
+                       //      }
+                       //}
+                       //execution.setVariable("segments", segList)
+                       
+                       //location Constraints
+                       def p_locationConstraints = reqMap.service?.parameters?.nsParameters?.locationConstraints
+                       if(p_locationConstraints){
+                       //Copy data. no data available now so ignoring
+                       }
+                       
+                       //additionalParamForNs
+                       String p_param1 = jsonUtil.getJsonValue(siRequest, "service.parameters.nsParameters.additionalParamForNs.E2EServcie.param1")
+                       if (isBlank(p_param1)) {
+                               msg = "Input parameters p_param1 is null"
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else {
+                               execution.setVariable("p_param1", p_param1)
+                       }
+                       
+                       String p_param2 = jsonUtil.getJsonValue(siRequest, "service.parameters.nsParameters.additionalParamForNs.E2EServcie.param2")
+                       if (isBlank(p_param2)) {
+                               msg = "Input parameters p_param2 is null"
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else {
+                               execution.setVariable("p_param2", p_param2)
+                       }
+
+                       //subscriberInfo
+                       String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId")
+                       if (isBlank(globalSubscriberId)) {
+                               msg = "Input globalSubscriberId' is null"
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else {
+                               execution.setVariable("globalSubscriberId", globalSubscriberId)
+                       }
+
+                       //requestInfo
+                       execution.setVariable("source", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.source"))
+                       execution.setVariable("serviceInstanceName", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.instanceName"))
+                       execution.setVariable("disableRollback", jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.suppressRollback"))
+                       String productFamilyId = jsonUtil.getJsonValue(siRequest, "requestDetails.requestInfo.productFamilyId")
+                       if (isBlank(productFamilyId))
+                       {
+                               msg = "Input productFamilyId is null"
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               //exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else {
+                               execution.setVariable("productFamilyId", productFamilyId)
+                       }
+
+                       //modelInfo
+                       String serviceModelInfo = jsonUtil.getJsonValue(siRequest, "requestDetails.modelInfo")
+                       if (isBlank(serviceModelInfo)) {
+                               msg = "Input serviceModelInfo is null"
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else
+                       {
+                               execution.setVariable("serviceModelInfo", serviceModelInfo)
+                       }
+
+                       utils.log("DEBUG", "modelInfo" + serviceModelInfo,  isDebugEnabled)
+
+                       //requestParameters
+                       String subscriptionServiceType = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.subscriptionServiceType")
+                       if (isBlank(subscriptionServiceType)) {
+                               msg = "Input subscriptionServiceType is null"
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       } else {
+                               execution.setVariable("subscriptionServiceType", subscriptionServiceType)
+                       }
+
+                       //TODO
+                       //execution.setVariable("serviceInputParams", jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams"))
+                       //execution.setVariable("failExists", true)
+
+               } catch (BpmnError e) {
+                       throw e;
+               } catch (Exception ex){
+                       msg = "Exception in preProcessRequest " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
+       }
+
+       public void sendSyncResponse (Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG", " *** sendSyncResponse *** ", isDebugEnabled)
+
+               try {
+                       String requestId = execution.getVariable("msoRequestId")
+                       String serviceInstanceId = execution.getVariable("serviceInstanceId")
+                       // RESTResponse for API Handler (APIH) Reply Task
+                       String createServiceRestRequest = """{"service":{"serviceId":"${serviceInstanceId}","operationId":"${requestId}"}}""".trim()
+                       utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + createServiceRestRequest, isDebugEnabled)
+                       sendWorkflowResponse(execution, 202, createServiceRestRequest)
+                       execution.setVariable("sentSyncResponse", true)
+
+               } catch (Exception ex) {
+                       String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," ***** Exit sendSyncResopnse *****",  isDebugEnabled)
+       }
+
+
+       public void sendSyncError (Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG", " *** sendSyncError *** ", isDebugEnabled)
+
+               try {
+                       String errorMessage = ""
+                       if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
+                               WorkflowException wfe = execution.getVariable("WorkflowException")
+                               errorMessage = wfe.getErrorMessage()
+                       } else {
+                               errorMessage = "Sending Sync Error."
+                       }
+
+                       String buildworkflowException =
+                                       """<aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
+                                       <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
+                                       <aetgt:ErrorCode>7000</aetgt:ErrorCode>
+                                  </aetgt:WorkflowException>"""
+
+                       utils.logAudit(buildworkflowException)
+                       sendWorkflowResponse(execution, 500, buildworkflowException)
+
+               } catch (Exception ex) {
+                       utils.log("DEBUG", " Sending Sync Error Activity Failed. " + "\n" + ex.getMessage(), isDebugEnabled)
+               }
+
+       }
+
+       public void prepareCompletionRequest (Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG", " *** prepareCompletion *** ", isDebugEnabled)
+
+               try {
+                       String requestId = execution.getVariable("msoRequestId")
+                       String serviceInstanceId = execution.getVariable("serviceInstanceId")
+                       String source = execution.getVariable("source")
+                       
+                       String msoCompletionRequest =
+                                       """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
+                                                               xmlns:ns="http://org.openecomp/mso/request/types/v1">\r
+                                               <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
+                                                       <request-id>${requestId}</request-id>
+                                                       <action>CREATE</action>
+                                                       <source>${source}</source>
+                                               </request-info>
+                                               <status-message>Service Instance was created successfully.</status-message>
+                                               <serviceInstanceId>${serviceInstanceId}</serviceInstanceId>
+                                               <mso-bpel-name>CreateGenericALaCarteServiceInstance</mso-bpel-name>
+                                       </aetgt:MsoCompletionRequest>"""
+
+                       // Format Response
+                       String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
+
+                       execution.setVariable("completionRequest", xmlMsoCompletionRequest)
+                       utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
+
+               } catch (Exception ex) {
+                       String msg = " Exception in prepareCompletion:" + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG", "*** Exit prepareCompletionRequest ***", isDebugEnabled)
+       }
+
+       public void prepareFalloutRequest(Execution execution){
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG", " *** prepareFalloutRequest *** ", isDebugEnabled)
+
+               try {
+                       WorkflowException wfex = execution.getVariable("WorkflowException")
+                       utils.log("DEBUG", " Input Workflow Exception: " + wfex.toString(), isDebugEnabled)
+                       String requestId = execution.getVariable("msoRequestId")
+                       String source = execution.getVariable("source")
+                       String requestInfo =
+                                       """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
+                                       <request-id>${requestId}</request-id>
+                                       <action>CREATE</action>
+                                       <source>${source}</source>
+                                  </request-info>"""
+
+                       String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
+                       execution.setVariable("falloutRequest", falloutRequest)
+               } catch (Exception ex) {
+                       utils.log("DEBUG", "Exception prepareFalloutRequest:" + ex.getMessage(), isDebugEnabled)
+                       String errorException = "  Bpmn error encountered in CreateGenericALaCarteServiceInstance flow. FalloutHandlerRequest,  buildErrorResponse() - " + ex.getMessage()
+                       String requestId = execution.getVariable("msoRequestId")
+                       String falloutRequest =
+                                       """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
+                                                                    xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
+                                                                    xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">\r
+                                          <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
+                                             <request-id>${requestId}</request-id>
+                                             <action>CREATE</action>
+                                             <source>VID</source>
+                                          </request-info>
+                                               <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
+                                                       <aetgt:ErrorMessage>${errorException}</aetgt:ErrorMessage>
+                                                       <aetgt:ErrorCode>7000</aetgt:ErrorCode>
+                                               </aetgt:WorkflowException>
+                                       </aetgt:FalloutHandlerRequest>"""
+
+                       execution.setVariable("falloutRequest", falloutRequest)
+               }
+               utils.log("DEBUG", "*** Exit prepareFalloutRequest ***", isDebugEnabled)
+       }
+}
\ No newline at end of file
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy
new file mode 100644 (file)
index 0000000..518c30b
--- /dev/null
@@ -0,0 +1,654 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.openecomp.mso.bpmn.infrastructure.scripts;
+
+import static org.apache.commons.lang3.StringUtils.*;
+import groovy.xml.XmlUtil
+import groovy.json.*
+
+import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
+import org.openecomp.mso.bpmn.core.domain.ServiceInstance
+import org.openecomp.mso.bpmn.core.domain.ModelInfo
+import org.openecomp.mso.bpmn.core.json.JsonUtils
+import org.openecomp.mso.bpmn.common.scripts.AaiUtil
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
+import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
+import org.openecomp.mso.bpmn.core.RollbackData
+import org.openecomp.mso.bpmn.core.WorkflowException
+import org.openecomp.mso.rest.APIResponse;
+import org.openecomp.mso.rest.RESTClient
+import org.openecomp.mso.rest.RESTConfig
+
+import java.util.UUID;
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.runtime.Execution
+import org.json.JSONObject;
+import org.apache.commons.lang3.*
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.web.util.UriUtils;
+
+/**
+ * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
+ *
+ * Inputs:
+ * @param - msoRequestId
+ * @param - globalSubscriberId
+ * @param - subscriptionServiceType
+ * @param - serviceInstanceId
+ * @param - serviceInstanceName - O
+ * @param - serviceModelInfo
+ * @param - productFamilyId
+ * @param - disableRollback
+ * @param - failExists - TODO
+ * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
+ * @param - sdncVersion ("1610")
+ * @param - serviceDecomposition - Decomposition for R1710 
+ * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
+ *
+ * Outputs:
+ * @param - rollbackData (localRB->null)
+ * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
+ * @param - WorkflowException
+ * @param - serviceInstanceName - (GET from AAI if null in input)
+ *
+ */
+public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
+
+       String Prefix="DCRESI_"
+       ExceptionUtil exceptionUtil = new ExceptionUtil()
+       JsonUtils jsonUtil = new JsonUtils()
+
+       public void preProcessRequest (Execution execution) {
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+               String msg = ""
+               utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)
+
+               try {
+                       String requestId = execution.getVariable("msoRequestId")
+                       execution.setVariable("prefix", Prefix)
+                       
+                       //Inputs
+                       //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
+                       String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
+
+                       //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
+                       String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
+
+                       //requestDetails.requestParameters. for SDNC assignTopology
+                       String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
+
+                       if (isBlank(globalSubscriberId)) {
+                               msg = "Input globalSubscriberId is null"
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       }
+                       
+                       if (isBlank(subscriptionServiceType)) {
+                               msg = "Input subscriptionServiceType is null"
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       }
+                       
+                       if (productFamilyId == null) {
+                               execution.setVariable("productFamilyId", "")
+                       }
+                       
+                       String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
+                       if (isBlank(sdncCallbackUrl)) {
+                               msg = "URN_mso_workflow_sdncadapter_callback is null"
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       }
+                       execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
+                       utils.log("DEBUG","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
+
+                       //requestDetails.modelInfo.for AAI PUT servieInstanceData & SDNC assignTopology
+                       String modelInvariantUuid = ""
+                       String modelVersion = ""
+                       String modelUuid = ""
+                       String modelName = ""
+                       String serviceInstanceName = "" 
+                       //Generated in parent.for AAI PUT
+                       String serviceInstanceId = ""
+                       String serviceType = ""
+                       String serviceRole = ""
+                       
+                       ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
+                       if (serviceDecomp != null)
+                       {
+                               serviceType = serviceDecomp.getServiceType()
+                               if (serviceType == null)
+                               {
+                                       utils.log("DEBUG", "null serviceType", isDebugEnabled)
+                                       serviceType = ""
+                               }
+                               else
+                               {
+                                       utils.log("DEBUG", "serviceType:" + serviceType, isDebugEnabled)
+                               }
+                               serviceRole = serviceDecomp.getServiceRole()
+                               if (serviceRole == null)
+                               {
+                                       serviceRole = ""
+                               }
+                               
+                               ServiceInstance serviceInstance = serviceDecomp.getServiceInstance()
+                               if (serviceInstance != null)
+                               {
+                                       serviceInstanceId = serviceInstance.getInstanceId()
+                                       serviceInstanceName = serviceInstance.getInstanceName()
+                                       execution.setVariable("serviceInstanceId", serviceInstanceId)
+                                       execution.setVariable("serviceInstanceName", serviceInstanceName)
+                               }
+                               
+                               ModelInfo modelInfo = serviceDecomp.getModelInfo()
+                               if (modelInfo != null)
+                               {
+                                       modelInvariantUuid = modelInfo.getModelInvariantUuid()
+                                       modelVersion = modelInfo.getModelVersion()
+                                       modelUuid = modelInfo.getModelUuid()
+                                       modelName = modelInfo.getModelName()
+                               }
+                               else 
+                               {
+                                       msg = "Input serviceModelInfo is null"
+                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                               }
+                       }
+                       else
+                       {
+                               //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology
+                               serviceInstanceName = execution.getVariable("serviceInstanceName")
+                               serviceInstanceId = execution.getVariable("serviceInstanceId")
+                               
+                               String serviceModelInfo = execution.getVariable("serviceModelInfo")
+                               if (isBlank(serviceModelInfo)) {
+                                       msg = "Input serviceModelInfo is null"
+                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                               }
+                               modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
+                               modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
+                               modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
+                               modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
+                               //modelCustomizationUuid NA for SI
+       
+                       }
+                       execution.setVariable("serviceType", serviceType)
+                       execution.setVariable("serviceRole", serviceRole)
+                       
+                       if (serviceInstanceName == null) {
+                               execution.setVariable("serviceInstanceName", "")
+                               serviceInstanceName = ""
+                       }
+                       if (isBlank(serviceInstanceId)){
+                               msg = "Input serviceInstanceId is null"
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       }
+                       
+                       if (modelInvariantUuid == null) {
+                               modelInvariantUuid = ""
+                       }
+                       if (modelUuid == null) {
+                               modelUuid = ""
+                       }
+                       if (modelVersion == null) {
+                               modelVersion = ""
+                       }
+                       if (modelName == null) {
+                               modelName = ""
+                       }
+                       
+                       execution.setVariable("modelInvariantUuid", modelInvariantUuid)
+                       execution.setVariable("modelVersion", modelVersion)
+                       execution.setVariable("modelUuid", modelUuid)
+                       execution.setVariable("modelName", modelName)
+                       
+                       StringBuilder sbParams = new StringBuilder()
+                       Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
+                       if (paramsMap != null)
+                       {
+                               sbParams.append("<service-input-parameters>")
+                               for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
+                                       String paramsXml
+                                       String paramName = entry.getKey()
+                                       String paramValue = entry.getValue()
+                                       paramsXml =
+                                                       """     <param>
+                                                       <name>${paramName}</name>
+                                                       <value>${paramValue}</value>
+                                                       </param>
+                                                       """
+                                       sbParams.append(paramsXml)
+                               }
+                               sbParams.append("</service-input-parameters>")
+                       }
+                       String siParamsXml = sbParams.toString()
+                       if (siParamsXml == null)
+                               siParamsXml = ""
+                       execution.setVariable("siParamsXml", siParamsXml)
+
+                       //AAI PUT
+                       String oStatus = execution.getVariable("initialStatus") ?: ""
+                       if ("TRANSPORT".equalsIgnoreCase(serviceType))
+                       {
+                               oStatus = "Created"
+                       }
+
+                       String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${oStatus}</orchestration-status>"
+                               
+                       AaiUtil aaiUriUtil = new AaiUtil(this)
+                       String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
+                       String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
+                       String serviceInstanceData =
+                                       """<service-instance xmlns=\"${namespace}\">
+                                       <service-instance-name>${serviceInstanceName}</service-instance-name>
+                                       <service-type>${serviceType}</service-type>
+                                       <service-role>${serviceRole}</service-role>
+                                       ${statusLine}
+                                   <model-invariant-id>${modelInvariantUuid}</model-invariant-id>
+                                   <model-version-id>${modelUuid}</model-version-id>
+                                       </service-instance>""".trim()
+
+                       execution.setVariable("serviceInstanceData", serviceInstanceData)
+                       utils.logAudit(serviceInstanceData)
+                       utils.log("DEBUG", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
+
+               } catch (BpmnError e) {
+                       throw e;
+               } catch (Exception ex){
+                       msg = "Exception in preProcessRequest " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)
+       }
+
+       //TODO: Will be able to replace with call to GenericGetService
+       public void getAAICustomerById (Execution execution) {
+               // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId}
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+               String msg = ""
+               try {
+
+                       String globalCustomerId = execution.getVariable("globalSubscriberId") //VID to AAI name map
+                       utils.log("DEBUG"," ***** getAAICustomerById ***** globalCustomerId:" + globalCustomerId, isDebugEnabled)
+
+                       String aai_endpoint = execution.getVariable("URN_aai_endpoint")
+                       AaiUtil aaiUriUtil = new AaiUtil(this)
+                       String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
+                       if (isBlank(aai_endpoint) || isBlank(aai_uri))
+                       {
+                               msg = "AAI URL is invalid. Endpoint:" + aai_endpoint + aai_uri
+                               utils.log("DEBUG", msg, isDebugEnabled)
+                               exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+                       }
+                       String getAAICustomerUrl = "${aai_endpoint}${aai_uri}/" + UriUtils.encode(globalCustomerId,"UTF-8")
+
+                       utils.logAudit(getAAICustomerUrl)
+                       utils.log("DEBUG", "getAAICustomerById Url:" + getAAICustomerUrl, isDebugEnabled)
+                       APIResponse response = aaiUriUtil.executeAAIGetCall(execution, getAAICustomerUrl)
+                       String returnCode = response.getStatusCode()
+                       String aaiResponseAsString = response.getResponseBodyAsString()
+
+                       msg = "getAAICustomerById ResponseCode:" + returnCode + " ResponseString:" + aaiResponseAsString
+                       utils.log("DEBUG",msg, isDebugEnabled)
+                       utils.logAudit(msg)
+
+                       if (returnCode=='200') {
+                               // Customer found by ID. FLow to proceed.
+                               utils.log("DEBUG",msg, isDebugEnabled)
+
+                               //TODO Deferred
+                               //we might verify that service-subscription with matching name exists
+                               //and throw error if not. If not checked, we will get exception in subsequent step on Create call
+                               //in 1610 we assume both customer & service subscription were pre-created
+
+                       } else {
+                               if (returnCode=='404') {
+                                       msg = "GlobalCustomerId:" + globalCustomerId + " not found (404) in AAI"
+                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+
+                               } else {
+                                       if (aaiResponseAsString.contains("RESTFault")) {
+                                               utils.log("ERROR", aaiResponseAsString)
+                                               WorkflowException workflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
+                                               execution.setVariable("WorkflowException", workflowException)
+                                               throw new BpmnError("MSOWorkflowException")
+
+                                       } else {
+                                               // aai all errors
+                                               msg = "Error in getAAICustomerById ResponseCode:" + returnCode
+                                               utils.log("DEBUG", msg, isDebugEnabled)
+                                               exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+                                       }
+                               }
+                       }
+
+               } catch (BpmnError e) {
+                       throw e;
+               } catch (Exception ex) {
+                       msg = "Exception in getAAICustomerById. " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," *****Exit getAAICustomerById *****", isDebugEnabled)
+
+       }
+
+       public void postProcessAAIGET(Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG"," ***** postProcessAAIGET ***** ", isDebugEnabled)
+               String msg = ""
+
+               try {
+                       String serviceInstanceName = execution.getVariable("serviceInstanceName")
+                       boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
+                       if(succInAAI != true){
+                               utils.log("DEBUG","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)
+                               WorkflowException workflowException = execution.getVariable("WorkflowException")
+                               utils.logAudit("workflowException: " + workflowException)
+                               if(workflowException != null){
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
+                               }
+                               else
+                               {
+                                       msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
+                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+                               }
+                       }
+                       else
+                       {
+                               boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
+                               if(foundInAAI == true){
+                                       utils.log("DEBUG","Found Service-instance in AAI", isDebugEnabled)
+                                       msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
+                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+                               }
+                       }
+               } catch (BpmnError e) {
+                       throw e;
+               } catch (Exception ex) {
+                       msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
+       }
+
+       public void postProcessAAIPUT(Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
+               String msg = ""
+               try {
+                       String serviceInstanceId = execution.getVariable("serviceInstanceId")
+                       boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
+                       if(succInAAI != true){
+                               utils.log("DEBUG","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
+                               WorkflowException workflowException = execution.getVariable("WorkflowException")
+                               utils.logAudit("workflowException: " + workflowException)
+                               if(workflowException != null){
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
+                               }
+                       }
+                       else
+                       {
+                               //start rollback set up
+                               RollbackData rollbackData = new RollbackData()
+                               def disableRollback = execution.getVariable("disableRollback")
+                               rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
+                               rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
+                               rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
+                               rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
+                               rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
+                               execution.setVariable("rollbackData", rollbackData)
+                       }
+
+               } catch (BpmnError e) {
+                       throw e;
+               } catch (Exception ex) {
+                       msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
+       }
+
+       public void preProcessSDNCAssignRequest(Execution execution) {
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
+               String msg = ""
+               utils.log("DEBUG"," ***** preProcessSDNCAssignRequest *****", isDebugEnabled)
+
+               try {
+                       def serviceInstanceId = execution.getVariable("serviceInstanceId")
+                       def serviceInstanceName = execution.getVariable("serviceInstanceName")
+                       def callbackURL = execution.getVariable("sdncCallbackUrl")
+                       def requestId = execution.getVariable("msoRequestId")
+                       def serviceId = execution.getVariable("productFamilyId")
+                       def subscriptionServiceType = execution.getVariable("subscriptionServiceType")
+                       def globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
+                       def serviceType = execution.getVariable("serviceType")
+
+                       def modelInvariantUuid = execution.getVariable("modelInvariantUuid")
+                       def modelVersion = execution.getVariable("modelVersion")
+                       def modelUuid = execution.getVariable("modelUuid")
+                       def modelName = execution.getVariable("modelName")
+                       
+                       def sdncRequestId = UUID.randomUUID().toString()
+                       
+                       def siParamsXml = execution.getVariable("siParamsXml")
+                       
+                       String sdncAssignRequest =
+                                       """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
+                                                                                                       xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
+                                                                                                       xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
+                                  <sdncadapter:RequestHeader>
+                                                       <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
+                                                       <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
+                                                       <sdncadapter:SvcAction>assign</sdncadapter:SvcAction>
+                                                       <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
+                                                       <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
+                                                       <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>
+                                       </sdncadapter:RequestHeader>
+                               <sdncadapterworkflow:SDNCRequestData>
+                                       <request-information>
+                                               <request-id>${requestId}</request-id>
+                                               <source>MSO</source>
+                                               <notification-url/>
+                                               <order-number/>
+                                               <order-version/>
+                                               <request-action>CreateServiceInstance</request-action>
+                                       </request-information>
+                                       <service-information>
+                                               <service-id>${serviceId}</service-id>
+                                               <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
+                                               <ecomp-model-information>
+                                                <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
+                                                <model-uuid>${modelUuid}</model-uuid>
+                                                <model-version>${modelVersion}</model-version>
+                                                <model-name>${modelName}</model-name>
+                                           </ecomp-model-information>
+                                               <service-instance-id>${serviceInstanceId}</service-instance-id>
+                                               <subscriber-name/>
+                                               <global-customer-id>${globalSubscriberId}</global-customer-id>
+                                       </service-information>
+                                       <service-request-input>
+                                               <service-instance-name>${serviceInstanceName}</service-instance-name>
+                                               ${siParamsXml}
+                                       </service-request-input>
+                               </sdncadapterworkflow:SDNCRequestData>
+                               </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
+
+                       utils.log("DEBUG","sdncAssignRequest:\n" + sdncAssignRequest, isDebugEnabled)
+                       sdncAssignRequest = utils.formatXml(sdncAssignRequest)
+                       execution.setVariable("sdncAssignRequest", sdncAssignRequest)
+                       utils.logAudit("sdncAssignRequest:  " + sdncAssignRequest)
+
+                       def sdncRequestId2 = UUID.randomUUID().toString()
+                       String sdncDelete = sdncAssignRequest.replace(">assign<", ">delete<").replace(">CreateServiceInstance<", ">DeleteServiceInstance<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
+                       def sdncRequestId3 = UUID.randomUUID().toString()
+                       String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId2}<", ">${sdncRequestId3}<")
+                       def rollbackData = execution.getVariable("rollbackData")
+                       rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate)
+                       rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete)
+                       execution.setVariable("rollbackData", rollbackData)
+                       
+                       utils.log("DEBUG","rollbackData:\n" + rollbackData.toString(), isDebugEnabled)
+
+               } catch (BpmnError e) {
+                       throw e;
+               } catch(Exception ex) {
+                       msg = "Exception in preProcessSDNCAssignRequest. " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," *****Exit preProcessSDNCAssignRequest *****", isDebugEnabled)
+       }
+       
+       public void postProcessSDNCAssign (Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG"," ***** postProcessSDNCAssign ***** ", isDebugEnabled)
+               try {
+                       WorkflowException workflowException = execution.getVariable("WorkflowException")
+                       utils.logAudit("workflowException: " + workflowException)
+
+                       boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
+
+                       String response = execution.getVariable("sdncAdapterResponse")
+                       utils.logAudit("SDNCResponse: " + response)
+
+                       SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
+                       sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
+
+                       if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
+                               utils.log("DEBUG","Good response from SDNC Adapter for service-instance  topology assign: \n" + response, isDebugEnabled)
+
+                               def rollbackData = execution.getVariable("rollbackData")
+                               rollbackData.put("SERVICEINSTANCE", "rollbackSDNC", "true")
+                               execution.setVariable("rollbackData", rollbackData)
+
+                       }else{
+                               utils.log("DEBUG","Bad Response from SDNC Adapter for service-instance assign", isDebugEnabled)
+                               throw new BpmnError("MSOWorkflowException")
+                       }
+
+               } catch (BpmnError e) {
+                       throw e;
+               } catch(Exception ex) {
+                       msg = "Exception in postProcessSDNCAssign. " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," *** Exit postProcessSDNCAssign *** ", isDebugEnabled)
+       }
+       
+       public void postProcessAAIGET2(Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
+               String msg = ""
+
+               try {
+                       String serviceInstanceName = execution.getVariable("serviceInstanceName")
+                       boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
+                       if(succInAAI != true){
+                               utils.log("DEBUG","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)
+                               WorkflowException workflowException = execution.getVariable("WorkflowException")
+                               utils.logAudit("workflowException: " + workflowException)
+                               if(workflowException != null){
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
+                               }
+                               else
+                               {
+                                       msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
+                                       utils.log("DEBUG", msg, isDebugEnabled)
+                                       exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+                               }
+                       }
+                       else
+                       {
+                               boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
+                               if(foundInAAI == true){
+                                       String aaiService = execution.getVariable("GENGS_service")
+                                       if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
+                                               execution.setVariable("serviceInstanceName",  utils.getNodeText1(aaiService, "service-instance-name"))
+                                               utils.log("DEBUG","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
+                                       }
+                               }
+                       }
+               } catch (BpmnError e) {
+                       throw e;
+               } catch (Exception ex) {
+                       msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+               }
+               utils.log("DEBUG"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)
+       }
+
+       public void preProcessRollback (Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled)
+               try {
+                       
+                       Object workflowException = execution.getVariable("WorkflowException");
+
+                       if (workflowException instanceof WorkflowException) {
+                               utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
+                               execution.setVariable("prevWorkflowException", workflowException);
+                               //execution.setVariable("WorkflowException", null);
+                       }
+               } catch (BpmnError e) {
+                       utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
+               } catch(Exception ex) {
+                       String msg = "Exception in preProcessRollback. " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+               }
+               utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled)
+       }
+
+       public void postProcessRollback (Execution execution) {
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
+               utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled)
+               String msg = ""
+               try {
+                       Object workflowException = execution.getVariable("prevWorkflowException");
+                       if (workflowException instanceof WorkflowException) {
+                               utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
+                               execution.setVariable("WorkflowException", workflowException);
+                       }
+                       execution.setVariable("rollbackData", null)
+               } catch (BpmnError b) {
+                       utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
+                       throw b;
+               } catch(Exception ex) {
+                       msg = "Exception in postProcessRollback. " + ex.getMessage()
+                       utils.log("DEBUG", msg, isDebugEnabled)
+               }
+               utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled)
+       }
+
+}
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstanceRollback.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateE2EServiceInstanceRollback.groovy
new file mode 100644 (file)
index 0000000..9fa6664
--- /dev/null
@@ -0,0 +1,237 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.openecomp.mso.bpmn.infrastructure.scripts\r
+\r
+\r
+import static org.apache.commons.lang3.StringUtils.*;\r
+import groovy.xml.XmlUtil\r
+import groovy.json.*\r
+\r
+import org.openecomp.mso.bpmn.core.json.JsonUtils\r
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
+import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils\r
+import org.openecomp.mso.bpmn.core.RollbackData\r
+import org.openecomp.mso.bpmn.core.WorkflowException\r
+import org.openecomp.mso.rest.APIResponse;\r
+import org.openecomp.mso.rest.RESTClient\r
+import org.openecomp.mso.rest.RESTConfig\r
+\r
+import java.util.UUID;\r
+\r
+import org.camunda.bpm.engine.delegate.BpmnError\r
+import org.camunda.bpm.engine.runtime.Execution\r
+import org.json.JSONObject;\r
+import org.apache.commons.lang3.*\r
+import org.apache.commons.codec.binary.Base64;\r
+import org.springframework.web.util.UriUtils;\r
+/**\r
+ * This groovy class supports the <class>DoCreateServiceInstanceRollback.bpmn</class> process.\r
+ *\r
+ * Inputs:\r
+ * @param - msoRequestId\r
+ * @param - rollbackData with\r
+ *          globalCustomerId\r
+ *                     subscriptionServiceType\r
+ *                     serviceInstanceId\r
+ *                     disableRollback\r
+ *                     rollbackAAI\r
+ *                     rollbackSDNC\r
+ *                     sdncRollbackRequest\r
+ * \r
+ *\r
+ * Outputs:\r
+ * @param - rollbackError\r
+ * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)\r
+ *\r
+ */\r
+public class DoCreateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{\r
+\r
+       String Prefix="DCRESIRB_"\r
+\r
+       public void preProcessRequest(Execution execution) {\r
+               def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+               execution.setVariable("prefix",Prefix)\r
+               String msg = ""\r
+               utils.log("DEBUG"," ***** preProcessRequest *****",  isDebugEnabled)\r
+               execution.setVariable("rollbackAAI",false)\r
+               execution.setVariable("rollbackSDNC",false)\r
+\r
+               try {\r
+                       def rollbackData = execution.getVariable("rollbackData")\r
+                       utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)\r
+\r
+                       if (rollbackData != null) {\r
+                               if (rollbackData.hasType("SERVICEINSTANCE")) {\r
+\r
+                                       def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")\r
+                                       execution.setVariable("serviceInstanceId", serviceInstanceId)\r
+\r
+                                       def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")\r
+                                       execution.setVariable("subscriptionServiceType", subscriptionServiceType)\r
+\r
+                                       def globalSubscriberId  = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")\r
+                                       execution.setVariable("globalSubscriberId", globalSubscriberId)\r
+\r
+                                       def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")\r
+                                       if ("true".equals(rollbackAAI))\r
+                                       {\r
+                                               execution.setVariable("rollbackAAI",true)\r
+                                       }\r
+\r
+                                       def rollbackSDNC = rollbackData.get("SERVICEINSTANCE", "rollbackSDNC")\r
+                                       if ("true".equals(rollbackSDNC))\r
+                                       {\r
+                                               execution.setVariable("rollbackSDNC", true)\r
+                                       }\r
+\r
+                                       if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackSDNC") != true)\r
+                                       {\r
+                                               execution.setVariable("skipRollback", true)\r
+                                       }\r
+\r
+                                       def sdncDelete = rollbackData.get("SERVICEINSTANCE", "sdncDelete")\r
+                                       execution.setVariable("sdncDelete", sdncDelete)\r
+                                       def sdncDeactivate = rollbackData.get("SERVICEINSTANCE", "sdncDeactivate")\r
+                                       execution.setVariable("sdncDeactivate", sdncDeactivate)\r
+                                       utils.log("DEBUG","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)\r
+                                       utils.log("DEBUG","sdncDelete:\n" + sdncDelete, isDebugEnabled)\r
+                               }\r
+                               else {\r
+                                       execution.setVariable("skipRollback", true)\r
+                               }\r
+                       }\r
+                       else {\r
+                               execution.setVariable("skipRollback", true)\r
+                       }\r
+                       if (execution.getVariable("disableRollback").equals("true" ))\r
+                       {\r
+                               execution.setVariable("skipRollback", true)\r
+                       }\r
+\r
+               } catch (BpmnError e) {\r
+                       throw e;\r
+               } catch (Exception ex){\r
+                       msg = "Exception in Create ServiceInstance Rollback preProcessRequest " + ex.getMessage()\r
+                       utils.log("DEBUG", msg, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+               }\r
+               utils.log("DEBUG"," ***** Exit preProcessRequest *****",  isDebugEnabled)\r
+       }\r
+\r
+       public void validateSDNCResponse(Execution execution, String response, String method) {\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("DEBUG"," ***** validateSDNCResponse ***** ", isDebugEnabled)\r
+               String msg = ""\r
+               try {\r
+                       WorkflowException workflowException = execution.getVariable("WorkflowException")\r
+                       boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")\r
+                       utils.log("DEBUG", "SDNCResponse: " + response, isDebugEnabled)\r
+                       utils.log("DEBUG", "workflowException: " + workflowException, isDebugEnabled)\r
+                       \r
+                       SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)\r
+                       sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)\r
+\r
+                       if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){\r
+                               msg = "SDNC Adapter service-instance rollback successful for " + method\r
+                               utils.log("DEBUG", msg, isDebugEnabled)\r
+                       }else{\r
+                               execution.setVariable("rolledBack", false)\r
+                               msg =  "Error Response from SDNC Adapter service-instance rollback for " + method\r
+                               execution.setVariable("rollbackError", msg)\r
+                               utils.log("DEBUG", msg, isDebugEnabled)\r
+                               throw new BpmnError("MSOWorkflowException")\r
+                       }\r
+               } catch (BpmnError e) {\r
+                       throw e;\r
+               } catch (Exception ex){\r
+                       msg = "Exception in Create ServiceInstance rollback for "  + method  + " Exception:" + ex.getMessage()\r
+                       utils.log("DEBUG", msg, isDebugEnabled)\r
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+               }\r
+               utils.log("DEBUG"," ***** Exit validateSDNCResponse ***** ", isDebugEnabled)\r
+       }\r
+\r
+       public void postProcessRequest(Execution execution) {\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)\r
+               String msg = ""\r
+               try {\r
+                       execution.setVariable("rollbackData", null)\r
+                       String serviceInstanceId = execution.getVariable("serviceInstanceId")\r
+                       boolean rollbackAAI = execution.getVariable("rollbackAAI")\r
+                       boolean rollbackSDNC = execution.getVariable("rollbackSDNC")\r
+                       if (rollbackAAI == true || rollbackSDNC == true)\r
+                       {\r
+                               execution.setVariable("rolledBack", true)\r
+                       }\r
+                       if (rollbackAAI == true)\r
+                       {\r
+                               boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")\r
+                               if(succInAAI != true){\r
+                                       execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful\r
+                                       execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")\r
+                                       utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)\r
+                               }\r
+                       }\r
+                       utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)\r
+\r
+               } catch (BpmnError e) {\r
+                       msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()\r
+                       utils.log("DEBUG", msg, isDebugEnabled)\r
+               } catch (Exception ex) {\r
+                       msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()\r
+                       utils.log("DEBUG", msg, isDebugEnabled)\r
+               }\r
+\r
+       }\r
+\r
+       public void processRollbackException(Execution execution){\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)\r
+               try{\r
+                       utils.log("DEBUG", "Caught an Exception in DoCreateServiceInstanceRollback", isDebugEnabled)\r
+                       execution.setVariable("rollbackData", null)\r
+                       execution.setVariable("rollbackError", "Caught exception in ServiceInstance Create Rollback")\r
+                       execution.setVariable("WorkflowException", null)\r
+\r
+               }catch(BpmnError b){\r
+                       utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)\r
+               }catch(Exception e){\r
+                       utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)\r
+               }\r
+\r
+               utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)\r
+       }\r
+\r
+       public void processRollbackJavaException(Execution execution){\r
+               def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+               utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)\r
+               try{\r
+                       execution.setVariable("rollbackData", null)\r
+                       execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Create Rollback")\r
+                       utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)\r
+\r
+               }catch(Exception e){\r
+                       utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)\r
+               }\r
+               utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)\r
+       }\r
+\r
+}\r