2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.openecomp.mso.bpmn.common.scripts
22 import org.openecomp.mso.bpmn.core.WorkflowException
23 import org.openecomp.mso.rest.APIResponse;
25 import org.camunda.bpm.engine.runtime.Execution;
26 import org.camunda.bpm.engine.delegate.BpmnError
29 * Please describe the CreateGenericVNFUtils.groovy class
32 class CreateGenericVNFUtils{
34 String Prefix="CRTGVNF_"
36 def utils=new MsoUtils()
38 private AbstractServiceTaskProcessor taskProcessor
40 public CreateGenericVNFUtils(AbstractServiceTaskProcessor taskProcessor) {
41 this.taskProcessor = taskProcessor
45 * This method is executed during the Initialization task of the process.
51 public APIResponse queryAAI(Execution execution, String path){
53 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
54 execution.setVariable("prefix", Prefix)
55 utils.log("DEBUG", " ======== STARTED queryAAI Process ======== ", isDebugEnabled)
57 def uuid = execution.getVariable("CRTGVNF_uuid")
58 utils.log("DEBUG", "UUID is: " + uuid, isDebugEnabled)
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)
66 AaiUtil aaiUtil = new AaiUtil(taskProcessor)
67 return aaiUtil.executeAAIGetCall(execution, queryAAIRequestPath)
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())
73 utils.log("DEBUG", "======== COMPLETED queryAAI Process ======== ", isDebugEnabled)
76 public String buildSDNCRequest(Execution execution, String svcInstId, String action){
78 String uuid = execution.getVariable('testReqId') // for junits
80 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
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 = ""
92 if(execution.getVariable("CRTGVNF_vnfParamsExistFlag") == true){
93 sdncVNFParamsXml = buildSDNCParamsXml(execution)
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>
126 </vnf-request-information>
127 </sdncadapterworkflow:SDNCRequestData>
128 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
134 public String buildSDNCParamsXml(Execution execution){
137 StringBuilder sb = new StringBuilder()
138 Map<String, String> paramsMap = execution.getVariable("CRTGVNF_vnfParamsMap")
140 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
142 String key = entry.getKey();
143 if(key.endsWith("_network")){
144 String requestKey = key.substring(0, key.indexOf("_network"))
145 String requestValue = entry.getValue()
148 <network-role>{ functx:substring-before-match(data($param/@name), '_network') }</network-role>
149 <network-name>{ $param/text() }</network-name>
154 params = sb.append(paramsXml)