Merge "Add execute resource recipe task script"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateE2EServiceInstance.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. 
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.openecomp.mso.bpmn.infrastructure.scripts;
22
23 import static org.apache.commons.lang3.StringUtils.*;
24 import org.apache.http.HttpResponse
25 import groovy.xml.XmlUtil
26 import groovy.json.*
27
28 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
29 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
30 import org.openecomp.mso.bpmn.core.domain.ModelInfo
31 import org.openecomp.mso.bpmn.core.domain.Resource
32 import org.openecomp.mso.bpmn.core.domain.AllottedResource
33 import org.openecomp.mso.bpmn.core.domain.NetworkResource
34 import org.openecomp.mso.bpmn.core.domain.VnfResource
35 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
36 import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder;
37 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
38 import org.openecomp.mso.bpmn.core.json.JsonUtils
39 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
40 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
41 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
42 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
43 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
44 import org.openecomp.mso.bpmn.core.RollbackData
45 import org.openecomp.mso.bpmn.core.WorkflowException
46 import org.openecomp.mso.rest.APIResponse;
47 import org.openecomp.mso.rest.RESTClient
48 import org.openecomp.mso.rest.RESTConfig
49
50 import java.util.List;
51 import java.util.UUID;
52
53 import javax.mail.Quota.Resource;
54
55 import org.camunda.bpm.engine.delegate.BpmnError
56 import org.camunda.bpm.engine.delegate.DelegateExecution
57 import org.json.JSONObject;
58 import org.json.JSONArray;
59 import org.apache.commons.lang3.*
60 import org.apache.commons.codec.binary.Base64;
61 import org.springframework.web.util.UriUtils;
62
63 /**
64  * This groovy class supports the <class>DoCreateServiceInstance.bpmn</class> process.
65  *
66  * Inputs:
67  * @param - msoRequestId
68  * @param - globalSubscriberId
69  * @param - subscriptionServiceType
70  * @param - serviceInstanceId
71  * @param - serviceInstanceName - O
72  * @param - serviceModelInfo
73  * @param - productFamilyId
74  * @param - disableRollback
75  * @param - failExists - TODO
76  * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
77  * @param - sdncVersion ("1610")
78  * @param - serviceDecomposition - Decomposition for R1710 
79  * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored)
80  *
81  * Outputs:
82  * @param - rollbackData (localRB->null)
83  * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
84  * @param - WorkflowException
85  * @param - serviceInstanceName - (GET from AAI if null in input)
86  *
87  */
88 public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
89
90         String Prefix="DCRESI_"
91         ExceptionUtil exceptionUtil = new ExceptionUtil()
92         JsonUtils jsonUtil = new JsonUtils()
93         CatalogDbUtils cutils = new CatalogDbUtils()
94
95         public void preProcessRequest (DelegateExecution execution) {
96                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
97                 String msg = ""
98                 utils.log("INFO"," ***** preProcessRequest *****",  isDebugEnabled)
99
100                 try {
101                         execution.setVariable("prefix", Prefix)
102                         //Inputs
103                         //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
104                         String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
105                         utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId,  isDebugEnabled)
106                         //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
107                         String serviceType = execution.getVariable("serviceType")
108                         utils.log("INFO"," ***** serviceType *****" + serviceType,  isDebugEnabled)
109                         //requestDetails.requestParameters. for SDNC assignTopology
110                         String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId
111
112                         if (isBlank(globalSubscriberId)) {
113                                 msg = "Input globalSubscriberId is null"
114                                 utils.log("INFO", msg, isDebugEnabled)
115                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
116                         }
117                         
118                         if (isBlank(serviceType)) {
119                                 msg = "Input serviceType is null"
120                                 utils.log("INFO", msg, isDebugEnabled)
121                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
122                         }
123                         
124                         if (productFamilyId == null) {
125                                 execution.setVariable("productFamilyId", "")
126                         }
127                         
128                         String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
129                         if (isBlank(sdncCallbackUrl)) {
130                                 msg = "URN_mso_workflow_sdncadapter_callback is null"
131                                 utils.log("INFO", msg, isDebugEnabled)
132                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
133                         }
134                         execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
135                         utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
136
137                         //requestDetails.modelInfo.for AAI PUT servieInstanceData                       
138                         //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData 
139                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
140                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
141                         String uuiRequest = execution.getVariable("uuiRequest")
142                         String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceDefId")
143                         String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.templateId")
144                         String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName")
145                         execution.setVariable("serviceModelName", serviceModelName)
146                         //aai serviceType and Role can be setted as fixed value now.
147                         String aaiServiceType = "E2E Service"
148                         String aaiServiceRole = "E2E Service"
149                         
150                         execution.setVariable("modelInvariantUuid", modelInvariantUuid)
151                         execution.setVariable("modelUuid", modelUuid)
152
153                         //AAI PUT
154                         String oStatus = execution.getVariable("initialStatus") ?: ""
155                         if ("TRANSPORT".equalsIgnoreCase(serviceType))
156                         {
157                                 oStatus = "Created"
158                         }
159
160                         String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${oStatus}</orchestration-status>"
161                                 
162                         AaiUtil aaiUriUtil = new AaiUtil(this)
163                         String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
164                         String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
165                         String serviceInstanceData =
166                                         """<service-instance xmlns=\"${namespace}\">
167                                 <service-instance-id>${serviceInstanceId}</service-instance-id>
168                                 <service-instance-name>${serviceInstanceName}</service-instance-name>
169                                         <service-type>${aaiServiceType}</service-type>
170                                         <service-role>${aaiServiceRole}</service-role>
171                                         ${statusLine}
172                                     <model-invariant-id>${modelInvariantUuid}</model-invariant-id>
173                                     <model-version-id>${modelUuid}</model-version-id>
174                                         </service-instance>""".trim()                                   
175                         execution.setVariable("serviceInstanceData", serviceInstanceData)
176                         utils.logAudit(serviceInstanceData)
177                         utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
178                         utils.log("INFO", " 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
179
180                 } catch (BpmnError e) {
181                         throw e;
182                 } catch (Exception ex){
183                         msg = "Exception in preProcessRequest " + ex.getMessage()
184                         utils.log("INFO", msg, isDebugEnabled)
185                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
186                 }
187                 utils.log("INFO"," ***** Exit preProcessRequest *****",  isDebugEnabled)
188         }
189         
190    public void prepareDecomposeService(DelegateExecution execution) {
191         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
192
193         try {
194             utils.log("DEBUG", " ***** Inside prepareDecomposeService of create generic e2e service ***** ", isDebugEnabled)
195             String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
196             String modelUuid = execution.getVariable("modelUuid")
197             //here modelVersion is not set, we use modelUuid to decompose the service.
198             String serviceModelInfo = """{
199             "modelInvariantUuid":"${modelInvariantUuid}",
200             "modelUuid":"${modelUuid}",
201             "modelVersion":""
202              }"""
203             execution.setVariable("serviceModelInfo", serviceModelInfo)
204
205             utils.log("DEBUG", " ***** Completed prepareDecomposeService of  create generic e2e service ***** ", isDebugEnabled)
206         } catch (Exception ex) {
207             // try error in method block
208             String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. Unexpected Error from method prepareDecomposeService() - " + ex.getMessage()
209             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
210         }
211      }
212
213     public void processDecomposition(DelegateExecution execution) {
214         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
215     
216         utils.log("DEBUG", " ***** Inside processDecomposition() of  create generic e2e service flow ***** ", isDebugEnabled)    
217         try {
218             ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
219         } catch (Exception ex) {
220             String exceptionMessage = "Bpmn error encountered in  create generic e2e service flow. processDecomposition() - " + ex.getMessage()
221             utils.log("DEBUG", exceptionMessage, isDebugEnabled)
222             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
223         }
224     }
225     
226     public void doServiceHoming(DelegateExecution execution) {
227         //Now Homing is not clear. So to be implemented.
228     }
229     
230         public void postProcessAAIGET(DelegateExecution execution) {
231                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
232                 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
233                 String msg = ""
234
235                 try {
236                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
237                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
238                         if(!succInAAI){
239                                 utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)
240                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
241                                 utils.logAudit("workflowException: " + workflowException)
242                                 if(workflowException != null){
243                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
244                                 }
245                                 else
246                                 {
247                                         msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
248                                         utils.log("INFO", msg, isDebugEnabled)
249                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
250                                 }
251                         }
252                         else
253                         {
254                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
255                                 if(foundInAAI){
256                                         utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)
257                                         msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
258                                         utils.log("INFO", msg, isDebugEnabled)
259                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
260                                 }
261                         }
262                 } catch (BpmnError e) {
263                         throw e;
264                 } catch (Exception ex) {
265                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
266                         utils.log("INFO", msg, isDebugEnabled)
267                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
268                 }
269                 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
270         }
271
272         public void postProcessAAIPUT(DelegateExecution execution) {
273                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
274                 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
275                 String msg = ""
276                 try {
277                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
278                         boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
279                         if(!succInAAI){
280                                 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
281                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
282                                 utils.logAudit("workflowException: " + workflowException)
283                                 if(workflowException != null){
284                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
285                                 }
286                         }
287                         else
288                         {
289                                 //start rollback set up
290                                 RollbackData rollbackData = new RollbackData()
291                                 def disableRollback = execution.getVariable("disableRollback")
292                                 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
293                                 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
294                                 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
295                                 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
296                                 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
297                                 execution.setVariable("rollbackData", rollbackData)
298                         }
299
300                 } catch (BpmnError e) {
301                         throw e;
302                 } catch (Exception ex) {
303                         msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
304                         utils.log("INFO", msg, isDebugEnabled)
305                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
306                 }
307                 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
308         }
309         
310         public void postProcessAAIGET2(DelegateExecution execution) {
311                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
312                 utils.log("INFO"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
313                 String msg = ""
314
315                 try {
316                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
317                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
318                         if(!succInAAI){
319                                 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)
320                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
321                                 utils.logAudit("workflowException: " + workflowException)
322                                 if(workflowException != null){
323                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
324                                 }
325                                 else
326                                 {
327                                         msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
328                                         utils.log("INFO", msg, isDebugEnabled)
329                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
330                                 }
331                         }
332                         else
333                         {
334                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
335                                 if(foundInAAI){
336                                         String aaiService = execution.getVariable("GENGS_service")
337                                         if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
338                                                 execution.setVariable("serviceInstanceName",  utils.getNodeText1(aaiService, "service-instance-name"))
339                                                 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
340                                         }
341                                 }
342                         }
343                 } catch (BpmnError e) {
344                         throw e;
345                 } catch (Exception ex) {
346                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
347                         utils.log("INFO", msg, isDebugEnabled)
348                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
349                 }
350                 utils.log("INFO"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)
351         }
352
353         public void preProcessRollback (DelegateExecution execution) {
354                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
355                 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
356                 try {
357                         
358                         Object workflowException = execution.getVariable("WorkflowException");
359
360                         if (workflowException instanceof WorkflowException) {
361                                 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
362                                 execution.setVariable("prevWorkflowException", workflowException);
363                                 //execution.setVariable("WorkflowException", null);
364                         }
365                 } catch (BpmnError e) {
366                         utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
367                 } catch(Exception ex) {
368                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
369                         utils.log("INFO", msg, isDebugEnabled)
370                 }
371                 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
372         }
373
374         public void postProcessRollback (DelegateExecution execution) {
375                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
376                 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
377                 String msg = ""
378                 try {
379                         Object workflowException = execution.getVariable("prevWorkflowException");
380                         if (workflowException instanceof WorkflowException) {
381                                 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
382                                 execution.setVariable("WorkflowException", workflowException);
383                         }
384                         execution.setVariable("rollbackData", null)
385                 } catch (BpmnError b) {
386                         utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
387                         throw b;
388                 } catch(Exception ex) {
389                         msg = "Exception in postProcessRollback. " + ex.getMessage()
390                         utils.log("INFO", msg, isDebugEnabled)
391                 }
392                 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
393         }
394
395         public void preInitResourcesOperStatus(DelegateExecution execution){
396         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
397
398         utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
399         try{
400             String serviceId = execution.getVariable("serviceInstanceId")
401             String operationId = execution.getVariable("operationId")
402             String operationType = execution.getVariable("operationType")
403             String resourceTemplateUUIDs = ""
404             String result = "processing"
405             String progress = "0"
406             String reason = ""
407             String operationContent = "Prepare service creation"
408             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
409             serviceId = UriUtils.encode(serviceId,"UTF-8")
410             execution.setVariable("serviceInstanceId", serviceId)
411             execution.setVariable("operationId", operationId)
412             execution.setVariable("operationType", operationType)
413             ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
414             List<Resource>  resourceList = serviceDecomposition.getServiceResources()
415             
416             for(String resource : resourceList){
417                     resourceTemplateUUIDs  = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":"                            
418             }           
419
420             def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
421             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
422             utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
423
424             String payload =
425                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
426                         xmlns:ns="http://org.openecomp.mso/requestsdb">
427                         <soapenv:Header/>
428                         <soapenv:Body>
429                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
430                             <serviceId>${serviceId}</serviceId>
431                             <operationId>${operationId}</operationId>
432                             <operationType>${operationType}</operationType>
433                             <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
434                         </ns:initResourceOperationStatus>
435                     </soapenv:Body>
436                 </soapenv:Envelope>"""
437
438             payload = utils.formatXml(payload)
439             execution.setVariable("CVFMI_initResOperStatusRequest", payload)
440             utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
441             utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
442
443         }catch(Exception e){
444             utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
445             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
446         }
447         utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  
448         }
449         
450
451         /**
452          * sequence resource. we should analyze resource sequence from service template
453          * Here we make VF first, and then network for E2E service.
454          */
455         public void sequenceResoure(execution){
456             def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
457         utils.log("INFO", "======== Start sequenceResoure Process ======== ", isDebugEnabled)  
458             String serviceModelUUID = execution.getVariable("modelUuid")
459         JSONArray networks = cutils.getAllNetworksByServiceModelUuid(execution, serviceModelUUID)
460         utils.log("DEBUG", "obtained Network list: " + networks, isDebugEnabled)            
461         if (networks == null) {
462             utils.log("INFO", "No matching networks in Catalog DB for serviceModelUUID=" + serviceModelUUID, isDebugEnabled)
463         }
464         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
465                 
466         //we use VF to define a network service
467         List<VnfResource>  vnfResourceList= serviceDecomposition.getServiceVnfs()
468         
469         //here wan is defined as a network resource        
470         List<NetworkResource> networkResourceList = serviceDecomposition.getServiceNetworks()
471
472         //allotted resource
473         List<AllottedResource> arResourceList= serviceDecomposition.getServiceAllottedResources()
474         //define sequenced resource list, we deploy vf first and then network and then ar
475         //this is defaule sequence
476         List<Resource>  sequencedResourceList = new ArrayList<Resource>();
477         if(null != vnfResourceList){
478             sequencedResourceList.addAll(vnfResourceList)
479         }
480         if(null != networkResourceList){
481             sequencedResourceList.addAll(networkResourceList)
482         }
483         if(null != arResourceList){
484             sequencedResourceList.addAll(arResourceList)
485         }
486
487         String isContainsWanResource = networkResourceList.isEmpty() ? "false" : "true"
488         execution.setVariable("isContainsWanResource", isContainsWanResource)
489         execution.setVariable("currentResourceIndex", 0)
490         execution.setVariable("sequencedResourceList", sequencedResourceList)
491         utils.log("INFO", "sequencedResourceList: " + sequencedResourceList, isDebugEnabled)  
492         utils.log("INFO", "======== COMPLETED sequenceResoure Process ======== ", isDebugEnabled)  
493         }
494         
495         public void getCurrentResoure(execution){
496             def isDebugEnabled=execution.getVariable("isDebugLogEnabled")   
497         utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled)    
498             def currentIndex = execution.getVariable("currentResourceIndex")
499             List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")  
500             Resource currentResource = sequencedResourceList.get(currentIndex)
501             utils.log("INFO", "Now we deal with resouce:" + currentResource.getModelInfo().getModelName(), isDebugEnabled)  
502         utils.log("INFO", "======== COMPLETED getCurrentResoure Process ======== ", isDebugEnabled)  
503     }
504
505            /**
506      * sequence resource
507      */
508     public void parseNextResource(execution){
509         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
510         utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)    
511         def currentIndex = execution.getVariable("currentResourceIndex")
512         def nextIndex =  currentIndex + 1
513         execution.setVariable("currentResourceIndex", nextIndex)
514         List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")    
515         if(nextIndex >= sequencedResourceList.size()){
516             execution.setVariable("allResourceFinished", "true")
517         }else{
518             execution.setVariable("allResourceFinished", "false")
519         }
520         utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)       
521     }
522     
523       /**
524       * post config request.
525       */
526      public void postConfigRequest(execution){
527          //now do noting
528      } 
529      
530      public void prepareResourceRecipeRequest(execution){
531          def isDebugEnabled=execution.getVariable("isDebugLogEnabled")                 
532          utils.log("INFO", "======== Start prepareResourceRecipeRequest Process ======== ", isDebugEnabled) 
533          ResourceInput resourceInput = new ResourceInput()         
534          String serviceInstanceName = execution.getVariable("serviceInstanceName")
535          String resourceInstanceName = resourceType + "_" + serviceInstanceName
536          resourceInput.setResourceInstanceName(resourceInstanceName)
537          utils.log("INFO", "Prepare Resource Request resourceInstanceName:" + resourceInstanceName, isDebugEnabled)
538          String globalSubscriberId = execution.getVariable("globalSubscriberId")
539          String serviceType = execution.getVariable("serviceType")
540          String serviceInstanceId = execution.getVariable("serviceInstanceId")
541          String operationId = execution.getVariable("operationId")
542          String operationType = execution.getVariable("operationType")
543          resourceInput.setGlobalSubscriberId(globalSubscriberId)
544          resourceInput.setServiceType(serviceType)
545          resourceInput.setServiceInstanceId(serviceInstanceId)
546          resourceInput.setOperationId(operationId)
547          resourceInput.setOperationType(operationType);
548          def currentIndex = execution.getVariable("currentResourceIndex")
549          List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")  
550          Resource currentResource = sequencedResourceList.get(currentIndex)
551          String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid()
552          resourceInput.setResourceCustomizationUuid(resourceCustomizationUuid);
553          String resourceInvariantUuid = currentResource.getModelInfo().getModelInvariantUuid()
554          resourceInput.setResourceInvariantUuid(resourceInvariantUuid)
555          String resourceUuid = currentResource.getModelInfo().getModelUuid()
556          resourceInput.setResourceUuid(resourceUuid)
557          
558          String incomingRequest = execution.getVariable("uuiRequest")
559          //set the requestInputs from tempalte  To Be Done
560          String serviceModelUuid = execution.getVariable("modelUuid")
561          String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
562          String resourceParameters = ResourceRequestBuilder.buildResourceRequestParameters(execution, serviceModelUuid, resourceCustomizationUuid, serviceParameters)
563          resourceInput.setResourceParameters(resourceParameters)
564          execution.setVariable("resourceInput", resourceInput)
565          utils.log("INFO", "======== COMPLETED prepareResourceRecipeRequest Process ======== ", isDebugEnabled)      
566      }
567      
568      public void executeResourceRecipe(Execution execution){
569          def isDebugEnabled=execution.getVariable("isDebugLogEnabled")                 
570          utils.log("INFO", "======== Start executeResourceRecipe Process ======== ", isDebugEnabled) 
571          String requestId = execution.getVariable("msoRequestId")
572          String serviceInstanceId = execution.getVariable("serviceInstanceId")
573          String serviceType = execution.getVariable("serviceType")
574          ResourceInput resourceInput = execution.getVariable("resourceInput")
575          String requestAction = resourceInput.getOperationType()
576          JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceUuid(), requestAction)
577          String recipeUri = resourceRecipe.getString("orchestrationUri")
578          String recipeTimeOut = resourceRecipe.getString("recipeTimeout")
579          String recipeParamXsd = resourceRecipe.get("paramXSD")
580          HttpResponse resp = BpmnRestClient.post(recipeUri, requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
581          
582      }
583 }