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