Support more Generic workflow for voLTE
[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 postProcessAAIGET(Execution execution) {
181                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
182                 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
183                 String msg = ""
184
185                 try {
186                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
187                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
188                         if(succInAAI != true){
189                                 utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceName, isDebugEnabled)
190                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
191                                 utils.logAudit("workflowException: " + workflowException)
192                                 if(workflowException != null){
193                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
194                                 }
195                                 else
196                                 {
197                                         msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
198                                         utils.log("INFO", msg, isDebugEnabled)
199                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
200                                 }
201                         }
202                         else
203                         {
204                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
205                                 if(foundInAAI == true){
206                                         utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)
207                                         msg = "ServiceInstance already exists in AAI:" + serviceInstanceName
208                                         utils.log("INFO", msg, isDebugEnabled)
209                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
210                                 }
211                         }
212                 } catch (BpmnError e) {
213                         throw e;
214                 } catch (Exception ex) {
215                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage()
216                         utils.log("INFO", msg, isDebugEnabled)
217                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
218                 }
219                 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
220         }
221
222         public void postProcessAAIPUT(Execution execution) {
223                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
224                 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
225                 String msg = ""
226                 try {
227                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
228                         boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
229                         if(succInAAI != true){
230                                 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
231                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
232                                 utils.logAudit("workflowException: " + workflowException)
233                                 if(workflowException != null){
234                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
235                                 }
236                         }
237                         else
238                         {
239                                 //start rollback set up
240                                 RollbackData rollbackData = new RollbackData()
241                                 def disableRollback = execution.getVariable("disableRollback")
242                                 rollbackData.put("SERVICEINSTANCE", "disableRollback", disableRollback.toString())
243                                 rollbackData.put("SERVICEINSTANCE", "rollbackAAI", "true")
244                                 rollbackData.put("SERVICEINSTANCE", "serviceInstanceId", serviceInstanceId)
245                                 rollbackData.put("SERVICEINSTANCE", "subscriptionServiceType", execution.getVariable("subscriptionServiceType"))
246                                 rollbackData.put("SERVICEINSTANCE", "globalSubscriberId", execution.getVariable("globalSubscriberId"))
247                                 execution.setVariable("rollbackData", rollbackData)
248                         }
249
250                 } catch (BpmnError e) {
251                         throw e;
252                 } catch (Exception ex) {
253                         msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
254                         utils.log("INFO", msg, isDebugEnabled)
255                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
256                 }
257                 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
258         }
259         
260         public void postProcessAAIGET2(Execution execution) {
261                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
262                 utils.log("INFO"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
263                 String msg = ""
264
265                 try {
266                         String serviceInstanceName = execution.getVariable("serviceInstanceName")
267                         boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
268                         if(succInAAI != true){
269                                 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET2", + serviceInstanceName, isDebugEnabled)
270                                 WorkflowException workflowException = execution.getVariable("WorkflowException")
271                                 utils.logAudit("workflowException: " + workflowException)
272                                 if(workflowException != null){
273                                         exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
274                                 }
275                                 else
276                                 {
277                                         msg = "Failure in postProcessAAIGET2 GENGS_SuccessIndicator:" + succInAAI
278                                         utils.log("INFO", msg, isDebugEnabled)
279                                         exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
280                                 }
281                         }
282                         else
283                         {
284                                 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
285                                 if(foundInAAI == true){
286                                         String aaiService = execution.getVariable("GENGS_service")
287                                         if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "service-instance-name"))) {
288                                                 execution.setVariable("serviceInstanceName",  utils.getNodeText1(aaiService, "service-instance-name"))
289                                                 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
290                                         }
291                                 }
292                         }
293                 } catch (BpmnError e) {
294                         throw e;
295                 } catch (Exception ex) {
296                         msg = "Exception in DoCreateServiceInstance.postProcessAAIGET2 " + ex.getMessage()
297                         utils.log("INFO", msg, isDebugEnabled)
298                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
299                 }
300                 utils.log("INFO"," *** Exit postProcessAAIGET2 *** ", isDebugEnabled)
301         }
302
303         public void preProcessRollback (Execution execution) {
304                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
305                 utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled)
306                 try {
307                         
308                         Object workflowException = execution.getVariable("WorkflowException");
309
310                         if (workflowException instanceof WorkflowException) {
311                                 utils.log("INFO", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
312                                 execution.setVariable("prevWorkflowException", workflowException);
313                                 //execution.setVariable("WorkflowException", null);
314                         }
315                 } catch (BpmnError e) {
316                         utils.log("INFO", "BPMN Error during preProcessRollback", isDebugEnabled)
317                 } catch(Exception ex) {
318                         String msg = "Exception in preProcessRollback. " + ex.getMessage()
319                         utils.log("INFO", msg, isDebugEnabled)
320                 }
321                 utils.log("INFO"," *** Exit preProcessRollback *** ", isDebugEnabled)
322         }
323
324         public void postProcessRollback (Execution execution) {
325                 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
326                 utils.log("INFO"," ***** postProcessRollback ***** ", isDebugEnabled)
327                 String msg = ""
328                 try {
329                         Object workflowException = execution.getVariable("prevWorkflowException");
330                         if (workflowException instanceof WorkflowException) {
331                                 utils.log("INFO", "Setting prevException to WorkflowException: ", isDebugEnabled)
332                                 execution.setVariable("WorkflowException", workflowException);
333                         }
334                         execution.setVariable("rollbackData", null)
335                 } catch (BpmnError b) {
336                         utils.log("INFO", "BPMN Error during postProcessRollback", isDebugEnabled)
337                         throw b;
338                 } catch(Exception ex) {
339                         msg = "Exception in postProcessRollback. " + ex.getMessage()
340                         utils.log("INFO", msg, isDebugEnabled)
341                 }
342                 utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled)
343         }
344
345         public void preInitResourcesOperStatus(Execution execution){
346         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
347
348         utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
349         try{
350             String serviceId = execution.getVariable("serviceInstanceId")
351             String operationId = execution.getVariable("operationId")
352             String operationType = execution.getVariable("operationType")
353             String resourceTemplateUUIDs = ""
354             String result = "processing"
355             String progress = "0"
356             String reason = ""
357             String operationContent = "Prepare service creation"
358             utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
359             serviceId = UriUtils.encode(serviceId,"UTF-8")
360             execution.setVariable("serviceInstanceId", serviceId)
361             execution.setVariable("operationId", operationId)
362             execution.setVariable("operationType", operationType)
363             String incomingRequest = execution.getVariable("uuiRequest")
364             String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources")  
365             List<String> resourceList = jsonUtil.StringArrayToList(execution, resourcesStr)   
366             for(String resource : resourceList){
367                     resourceTemplateUUIDs  = resourceTemplateUUIDs + jsonUtil.getJsonValue(resource, "resourceId") + ":"
368             }           
369
370             def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter"
371             execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
372             utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled)
373
374             String payload =
375                 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
376                         xmlns:ns="http://org.openecomp.mso/requestsdb">
377                         <soapenv:Header/>
378                         <soapenv:Body>
379                             <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
380                             <serviceId>${serviceId}</serviceId>
381                             <operationId>${operationId}</operationId>
382                             <operationType>${operationType}</operationType>
383                             <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
384                         </ns:initResourceOperationStatus>
385                     </soapenv:Body>
386                 </soapenv:Envelope>"""
387
388             payload = utils.formatXml(payload)
389             execution.setVariable("CVFMI_initResOperStatusRequest", payload)
390             utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
391             utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
392
393         }catch(Exception e){
394             utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
395             execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
396         }
397         utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)  
398         }
399         
400         /**
401          * prepare resource create request
402          */
403         public void preResourceRequest(execution){
404             String resourceType = execution.getVariable("resourceType")
405             def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
406             String serviceInstanceName = execution.getVariable("serviceInstanceName")
407             String nsServiceName = resourceType + "_" + serviceInstanceName
408             execution.setVariable("nsServiceName", nsServiceName)
409             utils.log("INFO", "Prepare Resource Request nsServiceName:" + nsServiceName, isDebugEnabled)
410         String globalSubscriberId = execution.getVariable("globalSubscriberId")
411         String serviceType = execution.getVariable("serviceType")
412         String serviceId = execution.getVariable("serviceInstanceId")
413         execution.setVariable("serviceId", serviceId)
414         String operationId = execution.getVariable("operationId")
415         String incomingRequest = execution.getVariable("uuiRequest")
416         String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources")  
417         String nsServiceDescription = jsonUtil.getJsonValue(incomingRequest, "service.description")  
418         execution.setVariable("nsServiceDescription", nsServiceDescription)
419         utils.log("INFO", "Prepare Resource Request nsServiceDescription:" + nsServiceDescription, isDebugEnabled)
420         List<String> resourceList = jsonUtil.StringArrayToList(execution, resourcesStr) 
421         //reset the variables
422         execution.setVariable("resourceUUID", "")
423         execution.setVariable("resourceInvariantUUID", "")
424         execution.setVariable("resourceParameters", "")
425         for(String resource : resourceList){
426             String resourceName = jsonUtil.getJsonValue(resource, "resourceName")  
427             if(StringUtils.containsIgnoreCase(resourceName, resourceType)){
428                 String resourceUUID  = jsonUtil.getJsonValue(resource, "resourceId")
429                 String resourceInvariantUUID  = jsonUtil.getJsonValue(resource, "resourceDefId")
430                 String resourceParameters = jsonUtil.getJsonValue(resource, "nsParameters")                
431                 execution.setVariable("resourceUUID", resourceUUID)
432                 execution.setVariable("resourceInvariantUUID", resourceInvariantUUID)
433                 execution.setVariable("resourceParameters", resourceParameters)
434                 utils.log("INFO", "Prepare Resource Request resourceType:" + resourceType, isDebugEnabled)
435                 utils.log("INFO", "Prepare Resource Request resourceUUID:" + resourceUUID, isDebugEnabled)
436                 utils.log("INFO", "Prepare Resource Request resourceParameters:" + resourceParameters, isDebugEnabled)
437             } 
438         }
439             utils.log("INFO", "Prepare Controller Request finished", isDebugEnabled)
440         }
441         /**
442          * sequence resource. we should analyze resource sequence from service template
443          * Here we make VF first, and then network for E2E service.
444          */
445         public void sequenceResoure(execution){
446             def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
447         utils.log("INFO", "======== Start sequenceResoure Process ======== ", isDebugEnabled)  
448             String serviceModelUUID = execution.getVariable("modelUuid")
449         JSONArray networks = cutils.getAllNetworksByServiceModelUuid(execution, serviceModelUUID)
450         utils.log("DEBUG", "obtained Network list: " + networks, isDebugEnabled)            
451         if (networks == null) {
452             utils.log("INFO", "No matching networks in Catalog DB for serviceModelUUID=" + serviceModelUUID, isDebugEnabled)
453         }
454         String incomingRequest = execution.getVariable("uuiRequest")
455         String resourcesStr = jsonUtil.getJsonValue(incomingRequest, "service.parameters.resources")  
456         List<String> resourceList = jsonUtil.StringArrayToList(execution, resourcesStr) 
457         // Only one match herenetwork
458         List<String> nsResources = new ArrayList<String>()
459         List<String> wanResources = new ArrayList<String>()
460         List<String> resourceSequence = new  ArrayList<String>()
461         for(String resource : resourceList){
462             String resourceName = jsonUtil.getJsonValue(resource, "resourceName")  
463             String resourceUUID = jsonUtil.getJsonValue(resource, "resourceId")
464             //check is network.
465             boolean isNetwork = false;
466             if(networks != null){
467                 for(int i = 0; i < networks.size(); i++){
468                     String networkUUID = jsonUtil.getJsonValueForKey(networks.get(i), "modelVersionId")
469                     if(StringUtils.equals(resourceUUID, networkUUID)){
470                         isNetwork = true
471                         break
472                     }
473                 }
474             }
475             if(isNetwork){
476                 wanResources.add(resourceName)
477             }else{
478                 nsResources.add(resourceName)
479             }
480         }
481         resourceSequence.addAll(nsResources)
482         resourceSequence.addAll(wanResources)
483         String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
484         execution.setVariable("isContainsWanResource", isContainsWanResource)
485         execution.setVariable("currentResourceIndex", 0)
486         execution.setVariable("resourceSequence", resourceSequence)
487         utils.log("INFO", "resourceSequence: " + resourceSequence, isDebugEnabled)  
488         execution.setVariable("wanResources", wanResources)
489         utils.log("INFO", "======== COMPLETED sequenceResoure Process ======== ", isDebugEnabled)  
490         }
491         
492         public void getCurrentResoure(execution){
493             def isDebugEnabled=execution.getVariable("isDebugLogEnabled")   
494         utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled)    
495             def currentIndex = execution.getVariable("currentResourceIndex")
496             List<String> resourceSequence = execution.getVariable("resourceSequence")  
497             List<String> wanResources = execution.getVariable("wanResources")  
498             String resourceName =  resourceSequence.get(currentIndex)
499             execution.setVariable("resourceType",resourceName)
500             if(wanResources.contains(resourceName)){
501                 execution.setVariable("controllerInfo", "SDN-C")
502             }else{
503                 execution.setVariable("controllerInfo", "VF-C")
504             }
505         utils.log("INFO", "======== COMPLETED getCurrentResoure Process ======== ", isDebugEnabled)  
506     }
507
508            /**
509      * sequence resource
510      */
511     public void parseNextResource(execution){
512         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
513         utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)    
514         def currentIndex = execution.getVariable("currentResourceIndex")
515         def nextIndex =  currentIndex + 1
516         execution.setVariable("currentResourceIndex", nextIndex)
517         List<String> resourceSequence = execution.getVariable("resourceSequence")    
518         if(nextIndex >= resourceSequence.size()){
519             execution.setVariable("allResourceFinished", "true")
520         }else{
521             execution.setVariable("allResourceFinished", "false")
522         }
523         utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)       
524     }
525     
526       /**
527       * post config request.
528       */
529      public void postConfigRequest(execution){
530          //now do noting
531      } 
532 }