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.infrastructure.scripts
22 import static org.apache.commons.lang3.StringUtils.*
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.runtime.Execution
26 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
29 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
30 import org.openecomp.mso.bpmn.common.scripts.VidUtils
31 import org.openecomp.mso.bpmn.core.WorkflowException
32 import org.openecomp.mso.bpmn.core.json.JsonUtils
36 * This class supports the DoCreateVnf building block subflow
37 * with the creation of a generic vnf for
41 class DoCreateVnf extends AbstractServiceTaskProcessor {
43 String Prefix="DoCVNF_"
44 ExceptionUtil exceptionUtil = new ExceptionUtil()
45 JsonUtils jsonUtil = new JsonUtils()
46 VidUtils vidUtils = new VidUtils(this)
49 * This method gets and validates the incoming
55 public void preProcessRequest(Execution execution) {
56 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
57 execution.setVariable("prefix",Prefix)
58 utils.log("DEBUG", " *** STARTED DoCreateVnf PreProcessRequest Process*** ", isDebugEnabled)
60 // DISABLE SDNC INTERACTION FOR NOW
61 execution.setVariable("SDNCInteractionEnabled", false)
68 String cloudConfiguration = execution.getVariable("cloudConfiguration")
69 String vnfModelInfo = execution.getVariable("vnfModelInfo")
71 String requestId = execution.getVariable("requestId")
72 execution.setVariable("DoCVNF_requestId", requestId)
73 execution.setVariable("mso-request-id", requestId)
74 utils.log("DEBUG", "Incoming Request Id is: " + requestId, isDebugEnabled)
76 String serviceInstanceId = execution.getVariable("serviceInstanceId")
77 execution.setVariable("DoCVNF_serviceInstanceId", serviceInstanceId)
78 utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
80 String vnfType = execution.getVariable("vnfType")
81 execution.setVariable("DoCVNF_vnfType", vnfType)
82 utils.log("DEBUG", "Incoming Vnf Type is: " + vnfType, isDebugEnabled)
84 String vnfName = execution.getVariable("vnfName")
85 execution.setVariable("DoCVNF_vnfName", vnfName)
86 utils.log("DEBUG", "Incoming Vnf Name is: " + vnfName, isDebugEnabled)
88 String serviceId = execution.getVariable("productFamilyId")
89 execution.setVariable("DoCVNF_serviceId", serviceId)
90 utils.log("DEBUG", "Incoming Service Id is: " + serviceId, isDebugEnabled)
93 execution.setVariable("DoCVNF_source", source)
94 utils.log("DEBUG", "Incoming Source is: " + source, isDebugEnabled)
96 String suppressRollback = execution.getVariable("disableRollback")
97 execution.setVariable("DoCVNF_suppressRollback", suppressRollback)
98 utils.log("DEBUG", "Incoming Suppress Rollback is: " + suppressRollback, isDebugEnabled)
100 String modelInvariantId = jsonUtil.getJsonValue(vnfModelInfo, "modelInvariantId")
101 execution.setVariable("DoCVNF_modelInvariantId", modelInvariantId)
102 utils.log("DEBUG", "Incoming Invariant Id is: " + modelInvariantId, isDebugEnabled)
104 String modelVersionId = jsonUtil.getJsonValue(vnfModelInfo, "modelVersionId")
105 if (modelVersionId == null) {
108 execution.setVariable("DoCVNF_modelVersionId", modelVersionId)
109 utils.log("DEBUG", "Incoming Version Id is: " + modelVersionId, isDebugEnabled)
111 String modelVersion = jsonUtil.getJsonValue(vnfModelInfo, "modelVersion")
112 execution.setVariable("DoCVNF_modelVersion", modelVersion)
113 utils.log("DEBUG", "Incoming Model Version is: " + modelVersion, isDebugEnabled)
115 String modelName = jsonUtil.getJsonValue(vnfModelInfo, "modelName")
116 execution.setVariable("DoCVNF_modelName", modelName)
117 utils.log("DEBUG", "Incoming Model Name is: " + modelName, isDebugEnabled)
119 String modelCustomizationId = jsonUtil.getJsonValue(vnfModelInfo, "modelCustomizationId")
120 if (modelCustomizationId == null) {
121 modelCustomizationId = ""
123 execution.setVariable("DoCVNF_modelCustomizationId", modelCustomizationId)
124 utils.log("DEBUG", "Incoming Model Customization Id is: " + modelCustomizationId, isDebugEnabled)
126 String cloudSiteId = jsonUtil.getJsonValue(cloudConfiguration, "lcpCloudRegionId")
127 execution.setVariable("DoCVNF_cloudSiteId", cloudSiteId)
128 utils.log("DEBUG", "Incoming Cloud Site Id is: " + cloudSiteId, isDebugEnabled)
130 String tenantId = jsonUtil.getJsonValue(cloudConfiguration, "tenantId")
131 execution.setVariable("DoCVNF_tenantId", tenantId)
132 utils.log("DEBUG", "Incoming Tenant Id is: " + tenantId, isDebugEnabled)
134 //For Completion Handler & Fallout Handler
136 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
137 <request-id>${requestId}</request-id>
138 <action>CREATE</action>
139 <source>${source}</source>
142 execution.setVariable("DoCVNF_requestInfo", requestInfo)
143 //TODO: Orch Status - TBD, will come from SDN-C Response in 1702
144 String orchStatus = "Created"
145 execution.setVariable("DoCVNF_orchStatus", orchStatus)
147 //TODO: Equipment Role - Should come from SDN-C Response in 1702
148 String equipmentRole = " "
149 execution.setVariable("DoCVNF_equipmentRole", equipmentRole)
150 String vnfId = execution.getVariable("testVnfId") // for junits
152 vnfId = execution.getVariable("vnfId")
153 if (isBlank(vnfId)) {
154 vnfId = UUID.randomUUID().toString()
155 utils.log("DEBUG", "Generated Vnf Id is: " + vnfId, isDebugEnabled)
158 execution.setVariable("DoCVNF_vnfId", vnfId)
160 // Setting for Sub Flow Calls
161 execution.setVariable("DoCVNF_type", "generic-vnf")
162 execution.setVariable("GENGS_type", "service-instance")
164 String sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
165 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
166 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
168 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
170 execution.setVariable("DoCVNF_sdncCallbackUrl", sdncCallbackUrl)
171 utils.logAudit("SDNC Callback URL: " + sdncCallbackUrl)
172 logDebug("SDNC Callback URL is: " + sdncCallbackUrl, isDebugEnabled)
175 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
178 utils.log("DEBUG", " Error Occured in DoCreateVnf PreProcessRequest method!" + e.getMessage(), isDebugEnabled)
179 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PreProcessRequest")
182 utils.log("DEBUG", "*** COMPLETED DoCreateVnf PreProcessRequest Process ***", isDebugEnabled)
186 public void prepareCreateGenericVnf (Execution execution) {
187 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
188 execution.setVariable("prefix",Prefix)
190 utils.log("DEBUG", " *** STARTED DoCreateVnf PrepareCreateGenericVnf Process *** ", isDebugEnabled)
193 String vnfId = execution.getVariable("DoCVNF_vnfId")
194 def vnfName = execution.getVariable("DoCVNF_vnfName")
195 def vnfType = execution.getVariable("DoCVNF_vnfType")
196 def serviceId = execution.getVariable("DoCVNF_serviceId")
197 def orchStatus = execution.getVariable("DoCVNF_orchStatus")
198 def modelInvariantId = execution.getVariable("DoCVNF_modelInvariantId")
199 def modelVersion = execution.getVariable("DoCVNF_modelVersion")
200 def modelCustomizationId = execution.getVariable("DoCVNF_modelCustomizationId")
201 // TODO: 1702 Variable
202 def equipmentRole = execution.getVariable("DoCVNF_equipmentRole")
204 //Get Service Instance Info
205 def serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
206 String siRelatedLink = execution.getVariable("GENGS_siResourceLink")
208 int custStart = siRelatedLink.indexOf("customer/")
209 int custEnd = siRelatedLink.indexOf("/service-subscriptions")
210 String globalCustId = siRelatedLink.substring(custStart + 9, custEnd)
211 int serviceStart = siRelatedLink.indexOf("service-subscription/")
212 int serviceEnd = siRelatedLink.indexOf("/service-instances/")
213 String serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
216 AaiUtil aaiUtil = new AaiUtil(this)
217 def aai_uri = aaiUtil.getNetworkGenericVnfUri(execution)
218 String namespace = aaiUtil.getNamespaceFromUri(aai_uri)
221 """<generic-vnf xmlns="${namespace}">
222 <vnf-id>${vnfId}</vnf-id>
223 <vnf-name>${vnfName}</vnf-name>
224 <service-id>${serviceId}</service-id>
225 <vnf-type>${vnfType}</vnf-type>
226 <orchestration-status>${orchStatus}</orchestration-status>
227 <persona-model-id>${modelInvariantId}</persona-model-id>
228 <persona-model-version>${modelVersion}</persona-model-version>
229 <persona-model-customization-id>${modelCustomizationId}</persona-model-customization-id>
232 <related-to>service-instance</related-to>
233 <related-link>${siRelatedLink}</related-link>
235 <relationship-key>customer.global-customer-id</relationship-key>
236 <relationship-value>${globalCustId}</relationship-value>
239 <relationship-key>service-subscription.service-type</relationship-key>
240 <relationship-value>${serviceType}</relationship-value>
243 <relationship-key>service-instance.service-instance-id</relationship-key>
244 <relationship-value>${serviceInstanceId}</relationship-value>
250 execution.setVariable("DoCVNF_genericVnfPayload", payload)
252 }catch(Exception ex) {
253 utils.log("DEBUG", "Error Occured in DoCreateVnf PrepareCreateGenericVnf Process " + ex.getMessage(), isDebugEnabled)
254 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoCreateVnf PrepareCreateGenericVnf Process")
256 utils.log("DEBUG", "*** COMPLETED DoCreateVnf PrepareCreateGenericVnf Process ***", isDebugEnabled)
259 public void preProcessSDNCAssignRequest(Execution execution){
260 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
261 execution.setVariable("prefix", Prefix)
262 logDebug(" ======== STARTED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
263 def vnfId = execution.getVariable("DoCVNF_vnfId")
264 def serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
265 logDebug("NEW VNF ID: " + vnfId, isDebugLogEnabled)
266 utils.logAudit("NEW VNF ID: " + vnfId)
271 String assignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "assign")
273 assignSDNCRequest = utils.formatXml(assignSDNCRequest)
274 execution.setVariable("DoCVNF_assignSDNCRequest", assignSDNCRequest)
275 logDebug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest, isDebugLogEnabled)
276 utils.logAudit("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
279 utils.log("ERROR", "Exception Occured Processing preProcessSDNCAssignRequest. Exception is:\n" + e, isDebugLogEnabled)
280 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareProvision Method:\n" + e.getMessage())
282 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
285 public void preProcessSDNCActivateRequest(Execution execution) {
286 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
287 'execution=' + execution.getId() +
289 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
290 logDebug('Entered ' + method, isDebugLogEnabled)
291 execution.setVariable("prefix", Prefix)
292 logDebug(" ======== STARTED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
294 String vnfId = execution.getVariable("DoCVNF_vnfId")
295 String serviceInstanceId = execution.getVariable("DoCVNF_serviceInstanceId")
297 String activateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "activate")
299 execution.setVariable("DoCVNF_activateSDNCRequest", activateSDNCRequest)
300 logDebug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest, isDebugLogEnabled)
301 utils.logAudit("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest)
304 log.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e, isDebugLogEnabled)
305 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
307 logDebug("======== COMPLETED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
310 public String buildSDNCRequest(Execution execution, String svcInstId, String action){
312 String uuid = execution.getVariable('testReqId') // for junits
314 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
316 def callbackURL = execution.getVariable("DoCVNF_sdncCallbackUrl")
317 def requestId = execution.getVariable("DoCVNF_requestId")
318 def serviceId = execution.getVariable("DoCVNF_serviceId")
319 def vnfType = execution.getVariable("DoCVNF_vnfType")
320 def vnfName = execution.getVariable("DoCVNF_vnfName")
321 def tenantId = execution.getVariable("DoCVNF_tenantId")
322 def source = execution.getVariable("DoCVNF_source")
323 def vnfId = execution.getVariable("DoCVNF_vnfId")
324 def cloudSiteId = execution.getVariable("DoCVNF_cloudSiteId")
325 def modelInvariantId = execution.getVariable("DoCVNF_modelInvariantId")
326 def modelVersionId = execution.getVariable("DoCVNF_modelVersionId")
327 def modelVersion = execution.getVariable("DoCVNF_modelVersion")
328 def modelName = execution.getVariable("DoCVNF_modelName")
330 String sdncVNFParamsXml = ""
332 if(execution.getVariable("DoCVNF_vnfParamsExistFlag") == true){
333 sdncVNFParamsXml = buildSDNCParamsXml(execution)
335 sdncVNFParamsXml = ""
339 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
340 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
341 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
342 <sdncadapter:RequestHeader>
343 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
344 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
345 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
346 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
347 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
348 </sdncadapter:RequestHeader>
349 <sdncadapterworkflow:SDNCRequestData>
350 <request-information>
351 <request-id>${requestId}</request-id>
352 <request-action>VNFActivateRequest</request-action>
353 <source>${source}</source>
357 </request-information>
358 <service-information>
359 <service-id>${serviceId}</service-id>
360 <service-type>${serviceId}</service-type>
361 <service-instance-id>${svcInstId}</service-instance-id>
362 <subscriber-name>notsurewecare</subscriber-name>
363 </service-information>
365 <vnf-id>${vnfId}</vnf-id>
366 <vnf-type>${vnfType}</vnf-type>
367 <ecomp-model-information>
368 <model-invariant-uuid>${modelInvariantId}</model-invariant-uuid>
369 <model-uuid>${modelVersionId}</model-uuid>
370 <model-version>${modelVersion}</model-version>
371 <model-name>${modelName}</model-name>
372 </ecomp-model-information>
374 <vnf-request-information>
375 <vnf-name>${vnfName}</vnf-name>
376 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
377 <tenant>${tenantId}</tenant>
379 </vnf-request-information>
380 </sdncadapterworkflow:SDNCRequestData>
381 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
383 utils.logAudit("sdncRequest: " + sdncRequest)
387 public void validateSDNCResponse(Execution execution, String response, String method){
388 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
389 execution.setVariable("prefix",Prefix)
390 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
392 WorkflowException workflowException = execution.getVariable("WorkflowException")
393 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
395 utils.logAudit("workflowException: " + workflowException)
397 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
398 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
400 utils.logAudit("SDNCResponse: " + response)
402 String sdncResponse = response
403 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
404 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
407 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
408 throw new BpmnError("MSOWorkflowException")
410 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)