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