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=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.scripts
23 import java.util.UUID;
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.runtime.Execution;
28 import static org.apache.commons.lang3.StringUtils.*;
30 import org.openecomp.mso.bpmn.common.scripts.AaiUtil;
31 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
32 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
33 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils;
34 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
35 import org.openecomp.mso.bpmn.core.WorkflowException
36 import org.openecomp.mso.bpmn.core.json.JsonUtils;
40 * This class supports the CreateVnfInfra Flow
41 * with the creation of a generic vnf for
44 class CreateVnfInfra extends AbstractServiceTaskProcessor {
46 String Prefix="CREVI_"
47 ExceptionUtil exceptionUtil = new ExceptionUtil()
48 JsonUtils jsonUtil = new JsonUtils()
49 VidUtils vidUtils = new VidUtils(this)
52 * This method gets and validates the incoming
58 public void preProcessRequest(Execution execution) {
59 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
60 execution.setVariable("prefix",Prefix)
61 utils.log("DEBUG", " *** STARTED CreateVnfInfra PreProcessRequest Process*** ", isDebugEnabled)
63 execution.setVariable("CREVI_sentSyncResponse", false)
67 String createVnfRequest = execution.getVariable("bpmnRequest")
68 execution.setVariable("CREVI_createVnfRequest", createVnfRequest)
69 utils.logAudit("Incoming CreateVnfInfra Request is: \n" + createVnfRequest)
71 if(createVnfRequest != null){
73 String requestId = execution.getVariable("mso-request-id")
74 execution.setVariable("CREVI_requestId", requestId)
75 utils.log("DEBUG", "Incoming Request Id is: " + requestId, isDebugEnabled)
77 String serviceInstanceId = execution.getVariable("serviceInstanceId")
78 execution.setVariable("CREVI_serviceInstanceId", serviceInstanceId)
79 utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
81 String vnfType = execution.getVariable("vnfType")
82 execution.setVariable("CREVI_vnfType", vnfType)
83 utils.log("DEBUG", "Incoming Vnf Type is: " + vnfType, isDebugEnabled)
85 String vnfName = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.instanceName")
86 execution.setVariable("CREVI_vnfName", vnfName)
87 utils.log("DEBUG", "Incoming Vnf Name is: " + vnfName, isDebugEnabled)
89 String serviceId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.productFamilyId")
90 execution.setVariable("CREVI_serviceId", serviceId)
91 utils.log("DEBUG", "Incoming Service Id is: " + serviceId, isDebugEnabled)
93 String source = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.source")
94 execution.setVariable("CREVI_source", source)
95 utils.log("DEBUG", "Incoming Source is: " + source, isDebugEnabled)
97 String suppressRollback = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.suppressRollback")
98 execution.setVariable("CREVI_suppressRollback", suppressRollback)
99 utils.log("DEBUG", "Incoming Suppress Rollback is: " + suppressRollback, isDebugEnabled)
101 def vnfModelInfo = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo")
102 execution.setVariable("CREVI_vnfModelInfo", vnfModelInfo)
104 String modelInvariantId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo.modelInvariantId")
105 execution.setVariable("CREVI_modelInvariantId", modelInvariantId)
106 utils.log("DEBUG", "Incoming Invariant Id is: " + modelInvariantId, isDebugEnabled)
108 String modelVersion = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo.modelVersion")
109 execution.setVariable("CREVI_modelVersion", modelVersion)
110 utils.log("DEBUG", "Incoming Model Version is: " + modelVersion, isDebugEnabled)
112 def cloudConfiguration = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.cloudConfiguration")
113 execution.setVariable("CREVI_cloudConfiguration", cloudConfiguration)
115 String cloudSiteId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.cloudConfiguration.lcpCloudRegionId")
116 execution.setVariable("CREVI_cloudSiteId", cloudSiteId)
117 utils.log("DEBUG", "Incoming Cloud Site Id is: " + cloudSiteId, isDebugEnabled)
119 String tenantId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.cloudConfiguration.tenantId")
120 execution.setVariable("CREVI_tenantId", tenantId)
121 utils.log("DEBUG", "Incoming Tenant Id is: " + tenantId, isDebugEnabled)
123 //For Completion Handler & Fallout Handler
125 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
126 <request-id>${requestId}</request-id>
127 <action>CREATE</action>
128 <source>${source}</source>
131 execution.setVariable("CREVI_requestInfo", requestInfo)
133 //TODO: Orch Status - TBD, will come from SDN-C Response in 1702
134 String orchStatus = "Created"
135 execution.setVariable("CREVI_orchStatus", orchStatus)
137 //TODO: Equipment Role - Should come from SDN-C Response in 1702
138 String equipmentRole = " "
139 execution.setVariable("CREVI_equipmentRole", equipmentRole)
141 String vnfId = execution.getVariable("testVnfId") // for junits
143 vnfId = UUID.randomUUID().toString()
144 utils.log("DEBUG", "Generated Vnf Id is: " + vnfId, isDebugEnabled)
146 execution.setVariable("CREVI_vnfId", vnfId)
148 // Setting for Sub Flow Calls
149 execution.setVariable("CREVI_type", "generic-vnf")
150 execution.setVariable("GENGS_type", "service-instance")
152 String sdncCallbackUrl = (String) execution.getVariable('URN_mso_workflow_sdncadapter_callback')
153 if (sdncCallbackUrl == null || sdncCallbackUrl.trim().isEmpty()) {
154 def msg = 'Required variable \'URN_mso_workflow_sdncadapter_callback\' is missing'
156 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
158 execution.setVariable("CREVI_sdncCallbackUrl", sdncCallbackUrl)
160 def vnfInputParameters = jsonUtil.getJsonValue(createVnfRequest, "requestParameters.userParams")
161 execution.setVariable("CREVI_vnfInputParameters", vnfInputParameters)
164 utils.logAudit("SDNC Callback URL: " + sdncCallbackUrl)
165 logDebug("SDNC Callback URL is: " + sdncCallbackUrl, isDebugEnabled)
168 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Bpmn Request is Null.")
172 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
175 utils.log("DEBUG", " Error Occured in CreateVnfInfra PreProcessRequest method!" + e.getMessage(), isDebugEnabled)
176 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PreProcessRequest")
179 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PreProcessRequest Process ***", isDebugEnabled)
182 public void sendSyncResponse (Execution execution) {
183 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
184 execution.setVariable("prefix",Prefix)
186 utils.log("DEBUG", " *** STARTED CreateVnfInfra SendSyncResponse Process *** ", isDebugEnabled)
189 String requestId = execution.getVariable("CREVI_requestId")
190 String vnfId = execution.getVariable("CREVI_vnfId")
192 String createVnfResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
194 utils.log("DEBUG", " CreateVnfInfra Sync Response is: \n" + createVnfResponse, isDebugEnabled)
196 sendWorkflowResponse(execution, 202, createVnfResponse)
198 execution.setVariable("CREVI_sentSyncResponse", true)
200 } catch (Exception ex) {
201 utils.log("DEBUG", "Error Occured in CreateVnfInfra SendSyncResponse Process " + ex.getMessage(), isDebugEnabled)
202 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra SendSyncResponse Process")
205 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra SendSyncResponse Process ***", isDebugEnabled)
208 public void prepareCreateGenericVnf (Execution execution) {
209 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
210 execution.setVariable("prefix",Prefix)
212 utils.log("DEBUG", " *** STARTED CreateVnfInfra PrepareCreateGenericVnf Process *** ", isDebugEnabled)
215 String vnfId = execution.getVariable("CREVI_vnfId")
216 def vnfName = execution.getVariable("CREVI_vnfName")
217 def vnfType = execution.getVariable("CREVI_vnfType")
218 def serviceId = execution.getVariable("CREVI_serviceId")
219 def orchStatus = execution.getVariable("CREVI_orchStatus")
220 def modelInvariantId = execution.getVariable("CREVI_modelInvariantId")
221 def modelVersion = execution.getVariable("CREVI_modelVersion")
222 // TODO: 1702 Variable
223 def equipmentRole = execution.getVariable("CREVI_equipmentRole")
225 //Get Service Instance Info
226 def serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
227 String siRelatedLink = execution.getVariable("GENGS_siResourceLink")
229 int custStart = siRelatedLink.indexOf("customer/")
230 int custEnd = siRelatedLink.indexOf("/service-subscriptions")
231 String globalCustId = siRelatedLink.substring(custStart + 9, custEnd)
232 int serviceStart = siRelatedLink.indexOf("service-subscription/")
233 int serviceEnd = siRelatedLink.indexOf("/service-instances/")
234 String serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
237 AaiUtil aaiUtil = new AaiUtil(this)
238 def aai_uri = aaiUtil.getNetworkGenericVnfUri(execution)
239 String namespace = aaiUtil.getNamespaceFromUri(aai_uri)
242 """<generic-vnf xmlns="${namespace}">
243 <vnf-id>${vnfId}</vnf-id>
244 <vnf-name>${vnfName}</vnf-name>
245 <service-id>${serviceId}</service-id>
246 <vnf-type>${vnfType}</vnf-type>
247 <orchestration-status>${orchStatus}</orchestration-status>
248 <persona-model-id>${modelInvariantId}</persona-model-id>
249 <persona-model-version>${modelVersion}</persona-model-version>
252 <related-to>service-instance</related-to>
253 <related-link>${siRelatedLink}</related-link>
255 <relationship-key>customer.global-customer-id</relationship-key>
256 <relationship-value>${globalCustId}</relationship-value>
259 <relationship-key>service-subscription.service-type</relationship-key>
260 <relationship-value>${serviceType}</relationship-value>
263 <relationship-key>service-instance.service-instance-id</relationship-key>
264 <relationship-value>${serviceInstanceId}</relationship-value>
270 execution.setVariable("CREVI_genericVnfPayload", payload)
272 }catch(Exception ex) {
273 utils.log("DEBUG", "Error Occured in CreateVnfInfra PrepareCreateGenericVnf Process " + ex.getMessage(), isDebugEnabled)
274 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PrepareCreateGenericVnf Process")
276 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCreateGenericVnf Process ***", isDebugEnabled)
279 public void preProcessSDNCAssignRequest(Execution execution){
280 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
281 execution.setVariable("prefix", Prefix)
282 logDebug(" ======== STARTED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
283 def vnfId = execution.getVariable("CREVI_vnfId")
284 def serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
285 logDebug("NEW VNF ID: " + vnfId, isDebugLogEnabled)
286 utils.logAudit("NEW VNF ID: " + vnfId)
291 String assignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "assign")
293 assignSDNCRequest = utils.formatXml(assignSDNCRequest)
294 execution.setVariable("CREVI_assignSDNCRequest", assignSDNCRequest)
295 logDebug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest, isDebugLogEnabled)
296 utils.logAudit("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
299 utils.log("ERROR", "Exception Occured Processing preProcessSDNCAssignRequest. Exception is:\n" + e, isDebugLogEnabled)
300 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareProvision Method:\n" + e.getMessage())
302 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
305 public void preProcessSDNCActivateRequest(Execution execution) {
306 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
307 'execution=' + execution.getId() +
309 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
310 logDebug('Entered ' + method, isDebugLogEnabled)
311 execution.setVariable("prefix", Prefix)
312 logDebug(" ======== STARTED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
314 String vnfId = execution.getVariable("CREVI_vnfId")
315 String serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
317 String activateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "activate")
319 execution.setVariable("CREVI_activateSDNCRequest", activateSDNCRequest)
320 logDebug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest, isDebugLogEnabled)
321 utils.logAudit("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest)
324 log.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e, isDebugLogEnabled)
325 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
327 logDebug("======== COMPLETED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
330 public String buildSDNCRequest(Execution execution, String svcInstId, String action){
332 String uuid = execution.getVariable('testReqId') // for junits
334 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
336 def callbackURL = execution.getVariable("CREVI_sdncCallbackUrl")
337 def requestId = execution.getVariable("CREVI_requestId")
338 def serviceId = execution.getVariable("CREVI_serviceId")
339 def vnfType = execution.getVariable("CREVI_vnfType")
340 def vnfName = execution.getVariable("CREVI_vnfName")
341 def tenantId = execution.getVariable("CREVI_tenantId")
342 def source = execution.getVariable("CREVI_source")
343 def vnfId = execution.getVariable("CREVI_vnfId")
344 def cloudSiteId = execution.getVariable("CREVI_cloudSiteId")
346 String sdncVNFParamsXml = ""
348 if(execution.getVariable("CREVI_vnfParamsExistFlag") == true){
349 sdncVNFParamsXml = buildSDNCParamsXml(execution)
351 sdncVNFParamsXml = ""
355 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
356 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
357 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
358 <sdncadapter:RequestHeader>
359 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
360 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
361 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
362 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
363 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
364 </sdncadapter:RequestHeader>
365 <sdncadapterworkflow:SDNCRequestData>
366 <request-information>
367 <request-id>${requestId}</request-id>
368 <request-action>VNFActivateRequest</request-action>
369 <source>${source}</source>
371 </request-information>
372 <service-information>
373 <service-id>${serviceId}</service-id>
374 <service-type>${serviceId}</service-type>
375 <service-instance-id>${svcInstId}</service-instance-id>
376 <subscriber-name>notsurewecare</subscriber-name>
377 </service-information>
378 <vnf-request-information>
379 <vnf-id>${vnfId}</vnf-id>
380 <vnf-name>${vnfName}</vnf-name>
381 <vnf-type>${vnfType}</vnf-type>
382 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
383 <tenant>${tenantId}</tenant>
385 </vnf-request-information>
386 </sdncadapterworkflow:SDNCRequestData>
387 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
389 utils.logAudit("sdncRequest: " + sdncRequest)
393 public void validateSDNCResponse(Execution execution, String response, String method){
394 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
395 execution.setVariable("prefix",Prefix)
396 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
398 WorkflowException workflowException = execution.getVariable("WorkflowException")
399 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
401 utils.logAudit("workflowException: " + workflowException)
403 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
404 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
406 utils.logAudit("SDNCResponse: " + response)
408 String sdncResponse = response
409 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
410 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
413 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
414 throw new BpmnError("MSOWorkflowException")
416 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
419 public void prepareCompletionHandlerRequest(Execution execution){
420 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
421 execution.setVariable("prefix",Prefix)
423 utils.log("DEBUG", " *** STARTED CreateVnfInfra PrepareCompletionHandlerRequest Process *** ", isDebugEnabled)
426 String requestInfo = execution.getVariable("CREVI_requestInfo")
427 String vnfId = execution.getVariable("CREVI_vnfId")
428 requestInfo = utils.removeXmlPreamble(requestInfo)
431 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
432 xmlns:ns="http://org.openecomp/mso/request/types/v1">
434 <status-message>Vnf has been created successfully.</status-message>
435 <vnfId>${vnfId}</vnfId>
436 <mso-bpel-name>CreateVnfInfra</mso-bpel-name>
437 </aetgt:MsoCompletionRequest>"""
439 execution.setVariable("CREVI_completionHandlerRequest", request)
440 utils.log("DEBUG", "Completion Handler Request is: " + request, isDebugEnabled)
442 execution.setVariable("WorkflowResponse", "Success") // for junits
444 } catch (Exception ex) {
445 utils.log("DEBUG", "Error Occured in CreateVnfInfra PrepareCompletionHandlerRequest Process " + ex.getMessage(), isDebugEnabled)
446 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PrepareCompletionHandlerRequest Process")
449 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCompletionHandlerRequest Process ***", isDebugEnabled)
452 public void sendErrorResponse(Execution execution){
453 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
454 execution.setVariable("prefix",Prefix)
456 utils.log("DEBUG", " *** STARTED CreateVnfInfra sendErrorResponse Process *** ", isDebugEnabled)
458 def sentSyncResponse = execution.getVariable("CREVI_sentSyncResponse")
459 if(sentSyncResponse == false){
460 WorkflowException wfex = execution.getVariable("WorkflowException")
461 String response = exceptionUtil.buildErrorResponseXml(wfex)
463 utils.logAudit(response)
464 sendWorkflowResponse(execution, 500, response)
466 utils.log("DEBUG", "Not Sending Error Response. Sync Response Already Sent", isDebugEnabled)
469 } catch (Exception ex) {
470 utils.log("DEBUG", "Error Occured in CreateVnfInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)
471 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra sendErrorResponse Process")
474 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra sendErrorResponse Process ***", isDebugEnabled)
477 public void prepareFalloutRequest(Execution execution){
478 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
479 execution.setVariable("prefix",Prefix)
481 utils.log("DEBUG", " *** STARTED CreateVnfInfra prepareFalloutRequest Process *** ", isDebugEnabled)
484 WorkflowException wfex = execution.getVariable("WorkflowException")
485 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
486 String requestInfo = execution.getVariable("CREVI_requestInfo")
487 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
489 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
491 execution.setVariable("CREVI_falloutRequest", falloutRequest)
494 } catch (Exception ex) {
495 utils.log("DEBUG", "Error Occured in CreateVnfInfra prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
496 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra prepareFalloutRequest Process")
499 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra prepareFalloutRequest Process ***", isDebugEnabled)