887eb7456d109514d7e57053da4bec8f99dd6566
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.mso.bpmn.common.scripts
21
22 import org.openecomp.mso.bpmn.core.WorkflowException
23 import org.openecomp.mso.rest.APIResponse;
24
25 import org.camunda.bpm.engine.runtime.Execution;
26 import org.camunda.bpm.engine.delegate.BpmnError
27
28 /**
29  * Please describe the CreateGenericVNFUtils.groovy class
30  *
31  */
32 class CreateGenericVNFUtils{
33
34         String Prefix="CRTGVNF_"
35
36         def utils=new MsoUtils()
37
38         private AbstractServiceTaskProcessor taskProcessor
39         
40         public CreateGenericVNFUtils(AbstractServiceTaskProcessor taskProcessor) {
41                 this.taskProcessor = taskProcessor
42         }
43
44         /**
45          * This method is executed during the Initialization task of the process.
46          *
47          * @param execution
48          *
49          */
50
51         public APIResponse queryAAI(Execution execution, String path){
52
53         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
54         execution.setVariable("prefix", Prefix)
55         utils.log("DEBUG", " ======== STARTED queryAAI Process ======== ", isDebugEnabled)
56
57         def uuid = execution.getVariable("CRTGVNF_uuid")
58         utils.log("DEBUG", "UUID is: " + uuid, isDebugEnabled)
59
60         //Setting request path
61         String queryAAIRequestPath = execution.getVariable("URN_aai_endpoint")+path
62 //      execution.setVariable("CRTGVNF_queryAAIRequestPath", queryAAIRequestPath)
63         utils.log("DEBUG", "QueryAAIRequest Path is: " + "\n" + queryAAIRequestPath, isDebugEnabled)
64
65         try {
66                 AaiUtil aaiUtil = new AaiUtil(taskProcessor)
67                 return aaiUtil.executeAAIGetCall(execution, queryAAIRequestPath)
68         }catch(Exception e){
69                 utils.log("ERROR", "Exception Occured Processing queryAAI. Exception is:\n" + e, isDebugEnabled)
70                 execution.setVariable("CRTGVNF_dataValidationFlag", false)
71                 execution.setVariable("CRTGVNF_ErrorResponse", "Error Occured during queryAAI Method:\n" + e.getMessage())
72         }
73         utils.log("DEBUG", "======== COMPLETED queryAAI Process ======== ", isDebugEnabled)
74 }
75
76         public String buildSDNCRequest(Execution execution, String svcInstId, String action){
77
78                 String uuid = execution.getVariable('testReqId') // for junits
79                 if(uuid==null){
80                         uuid = execution.getVariable("mso-request-id") + "-" +          System.currentTimeMillis()
81                 }
82                 def callbackURL = execution.getVariable("CRTGVNF_sdncCallbackUrl")
83                 def requestId = execution.getVariable("CRTGVNF_requestId")
84                 def serviceType = execution.getVariable("CRTGVNF_serviceType")
85                 def vnfType = execution.getVariable("CRTGVNF_vnfType")
86                 def vnfName = execution.getVariable("CRTGVNF_vnfName")
87                 def tenantId = execution.getVariable("CRTGVNF_tenantId")
88                 def source = execution.getVariable("CRTGVNF_source")
89                 String vnfId = svcInstId
90                 String sdncVNFParamsXml = ""
91
92                 if(execution.getVariable("CRTGVNF_vnfParamsExistFlag") == true){
93                         sdncVNFParamsXml = buildSDNCParamsXml(execution)
94                 }else{
95                         sdncVNFParamsXml = ""
96                 }
97
98                 String sdncRequest =
99                 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
100                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
101                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
102            <sdncadapter:RequestHeader>
103                                 <sdncadapter:RequestId>${uuid}</sdncadapter:RequestId>
104                                 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
105                                 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
106                                 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
107                                 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
108                 </sdncadapter:RequestHeader>
109         <sdncadapterworkflow:SDNCRequestData>
110                 <request-information>
111                         <request-id>${requestId}</request-id>
112                         <request-action>VNFActivateRequest</request-action>
113                         <source>${source}</source>
114                 </request-information>
115                 <service-information>
116                         <service-type>${serviceType}</service-type>
117                         <service-instance-id>${vnfId}</service-instance-id>
118                         <subscriber-name>notsurewecare</subscriber-name>
119                 </service-information>
120                 <vnf-request-information>
121                         <vnf-id>${vnfId}</vnf-id>
122                         <vnf-type>${vnfType}</vnf-type>
123                         <vnf-name>${vnfName}</vnf-name>
124                         <tenant>${tenantId}</tenant>
125 ${sdncVNFParamsXml}
126                 </vnf-request-information>
127         </sdncadapterworkflow:SDNCRequestData>
128         </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
129
130         return sdncRequest
131
132         }
133
134         public String buildSDNCParamsXml(Execution execution){
135
136                 String params = ""
137                 StringBuilder sb = new StringBuilder()
138                 Map<String, String> paramsMap = execution.getVariable("CRTGVNF_vnfParamsMap")
139
140                 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
141                         String paramsXml
142                         String key = entry.getKey();
143                         if(key.endsWith("_network")){
144                                 String requestKey = key.substring(0, key.indexOf("_network"))
145                                 String requestValue = entry.getValue()
146                                 paramsXml =
147 """<vnf-networks>
148         <network-role>{ functx:substring-before-match(data($param/@name), '_network') }</network-role>
149         <network-name>{ $param/text() }</network-name>
150 </vnf-networks>"""
151                         }else{
152                         paramsXml = ""
153                         }
154                         params = sb.append(paramsXml)
155                 }
156                 return params
157         }
158         
159 }
160
161
162
163
164