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)
209 public void preProcessSDNCAssignRequest(Execution execution){
210 def isDebugLogEnabled = execution.getVariable("isDebugLogEnabled")
211 execution.setVariable("prefix", Prefix)
212 logDebug(" ======== STARTED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
213 def vnfId = execution.getVariable("CREVI_vnfId")
214 def serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
215 logDebug("NEW VNF ID: " + vnfId, isDebugLogEnabled)
216 utils.logAudit("NEW VNF ID: " + vnfId)
221 String assignSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "assign")
223 assignSDNCRequest = utils.formatXml(assignSDNCRequest)
224 execution.setVariable("CREVI_assignSDNCRequest", assignSDNCRequest)
225 logDebug("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest, isDebugLogEnabled)
226 utils.logAudit("Outgoing AssignSDNCRequest is: \n" + assignSDNCRequest)
229 utils.log("ERROR", "Exception Occured Processing preProcessSDNCAssignRequest. Exception is:\n" + e, isDebugLogEnabled)
230 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareProvision Method:\n" + e.getMessage())
232 logDebug("======== COMPLETED preProcessSDNCAssignRequest ======== ", isDebugLogEnabled)
235 public void preProcessSDNCActivateRequest(Execution execution) {
236 def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
237 'execution=' + execution.getId() +
239 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
240 logDebug('Entered ' + method, isDebugLogEnabled)
241 execution.setVariable("prefix", Prefix)
242 logDebug(" ======== STARTED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
244 String vnfId = execution.getVariable("CREVI_vnfId")
245 String serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
247 String activateSDNCRequest = buildSDNCRequest(execution, serviceInstanceId, "activate")
249 execution.setVariable("CREVI_activateSDNCRequest", activateSDNCRequest)
250 logDebug("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest, isDebugLogEnabled)
251 utils.logAudit("Outgoing CommitSDNCRequest is: \n" + activateSDNCRequest)
254 log.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e, isDebugLogEnabled)
255 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
257 logDebug("======== COMPLETED preProcessSDNCActivateRequest Process ======== ", isDebugLogEnabled)
260 public String buildSDNCRequest(Execution execution, String svcInstId, String action){
262 String uuid = execution.getVariable('testReqId') // for junits
264 uuid = execution.getVariable("mso-request-id") + "-" + System.currentTimeMillis()
266 def callbackURL = execution.getVariable("CREVI_sdncCallbackUrl")
267 def requestId = execution.getVariable("CREVI_requestId")
268 def serviceId = execution.getVariable("CREVI_serviceId")
269 def vnfType = execution.getVariable("CREVI_vnfType")
270 def vnfName = execution.getVariable("CREVI_vnfName")
271 def tenantId = execution.getVariable("CREVI_tenantId")
272 def source = execution.getVariable("CREVI_source")
273 def vnfId = execution.getVariable("CREVI_vnfId")
274 def cloudSiteId = execution.getVariable("CREVI_cloudSiteId")
276 String sdncVNFParamsXml = ""
278 if(execution.getVariable("CREVI_vnfParamsExistFlag") == true){
279 sdncVNFParamsXml = buildSDNCParamsXml(execution)
281 sdncVNFParamsXml = ""
285 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
286 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
287 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
288 <sdncadapter:RequestHeader>
289 <sdncadapter:RequestId>${requestId}</sdncadapter:RequestId>
290 <sdncadapter:SvcInstanceId>${svcInstId}</sdncadapter:SvcInstanceId>
291 <sdncadapter:SvcAction>${action}</sdncadapter:SvcAction>
292 <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
293 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
294 </sdncadapter:RequestHeader>
295 <sdncadapterworkflow:SDNCRequestData>
296 <request-information>
297 <request-id>${requestId}</request-id>
298 <request-action>VNFActivateRequest</request-action>
299 <source>${source}</source>
301 </request-information>
302 <service-information>
303 <service-id>${serviceId}</service-id>
304 <service-type>${serviceId}</service-type>
305 <service-instance-id>${svcInstId}</service-instance-id>
306 <subscriber-name>notsurewecare</subscriber-name>
307 </service-information>
308 <vnf-request-information>
309 <vnf-id>${vnfId}</vnf-id>
310 <vnf-name>${vnfName}</vnf-name>
311 <vnf-type>${vnfType}</vnf-type>
312 <aic-cloud-region>${cloudSiteId}</aic-cloud-region>
313 <tenant>${tenantId}</tenant>
315 </vnf-request-information>
316 </sdncadapterworkflow:SDNCRequestData>
317 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
319 utils.logAudit("sdncRequest: " + sdncRequest)
323 public void validateSDNCResponse(Execution execution, String response, String method){
324 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
325 execution.setVariable("prefix",Prefix)
326 logDebug(" *** STARTED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
328 WorkflowException workflowException = execution.getVariable("WorkflowException")
329 boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
331 utils.logAudit("workflowException: " + workflowException)
333 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this)
334 sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
336 utils.logAudit("SDNCResponse: " + response)
338 String sdncResponse = response
339 if(execution.getVariable(Prefix + 'sdncResponseSuccess') == true){
340 logDebug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse, isDebugLogEnabled)
343 logDebug("Received a BAD Response from SDNC Adapter for " + method + " SDNC Call.", isDebugLogEnabled)
344 throw new BpmnError("MSOWorkflowException")
346 logDebug(" *** COMPLETED ValidateSDNCResponse Process*** ", isDebugLogEnabled)
349 public void prepareCompletionHandlerRequest(Execution execution){
350 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
351 execution.setVariable("prefix",Prefix)
353 utils.log("DEBUG", " *** STARTED CreateVnfInfra PrepareCompletionHandlerRequest Process *** ", isDebugEnabled)
356 String requestInfo = execution.getVariable("CREVI_requestInfo")
357 String vnfId = execution.getVariable("CREVI_vnfId")
358 requestInfo = utils.removeXmlPreamble(requestInfo)
361 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
362 xmlns:ns="http://org.openecomp/mso/request/types/v1">
364 <status-message>Vnf has been created successfully.</status-message>
365 <vnfId>${vnfId}</vnfId>
366 <mso-bpel-name>CreateVnfInfra</mso-bpel-name>
367 </aetgt:MsoCompletionRequest>"""
369 execution.setVariable("CREVI_completionHandlerRequest", request)
370 utils.log("DEBUG", "Completion Handler Request is: " + request, isDebugEnabled)
372 execution.setVariable("WorkflowResponse", "Success") // for junits
374 } catch (Exception ex) {
375 utils.log("DEBUG", "Error Occured in CreateVnfInfra PrepareCompletionHandlerRequest Process " + ex.getMessage(), isDebugEnabled)
376 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PrepareCompletionHandlerRequest Process")
379 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCompletionHandlerRequest Process ***", isDebugEnabled)
382 public void sendErrorResponse(Execution execution){
383 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
384 execution.setVariable("prefix",Prefix)
386 utils.log("DEBUG", " *** STARTED CreateVnfInfra sendErrorResponse Process *** ", isDebugEnabled)
388 def sentSyncResponse = execution.getVariable("CREVI_sentSyncResponse")
389 if(sentSyncResponse == false){
390 WorkflowException wfex = execution.getVariable("WorkflowException")
391 String response = exceptionUtil.buildErrorResponseXml(wfex)
393 utils.logAudit(response)
394 sendWorkflowResponse(execution, 500, response)
396 utils.log("DEBUG", "Not Sending Error Response. Sync Response Already Sent", isDebugEnabled)
399 } catch (Exception ex) {
400 utils.log("DEBUG", "Error Occured in CreateVnfInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)
401 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra sendErrorResponse Process")
404 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra sendErrorResponse Process ***", isDebugEnabled)
407 public void prepareFalloutRequest(Execution execution){
408 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
409 execution.setVariable("prefix",Prefix)
411 utils.log("DEBUG", " *** STARTED CreateVnfInfra prepareFalloutRequest Process *** ", isDebugEnabled)
414 WorkflowException wfex = execution.getVariable("WorkflowException")
415 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
416 String requestInfo = execution.getVariable("CREVI_requestInfo")
417 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
419 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
421 execution.setVariable("CREVI_falloutRequest", falloutRequest)
424 } catch (Exception ex) {
425 utils.log("DEBUG", "Error Occured in CreateVnfInfra prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
426 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra prepareFalloutRequest Process")
429 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra prepareFalloutRequest Process ***", isDebugEnabled)