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 com.att.bpm.scripts
23 import java.util.UUID;
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.runtime.Execution;
27 import static org.apache.commons.lang3.StringUtils.*;
29 import org.openecomp.mso.bpmn.core.WorkflowException
30 import org.openecomp.mso.bpmn.core.json.JsonUtils;
34 * This class supports the CreateVnfInfra Flow
35 * with the creation of a generic vnf for
38 class CreateVnfInfra extends AbstractServiceTaskProcessor {
40 String Prefix="CREVI_"
41 ExceptionUtil exceptionUtil = new ExceptionUtil()
42 JsonUtils jsonUtil = new JsonUtils()
43 VidUtils vidUtils = new VidUtils(this)
46 * This method gets and validates the incoming
51 public void preProcessRequest(Execution execution) {
52 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
53 execution.setVariable("prefix",Prefix)
54 utils.log("DEBUG", " *** STARTED CreateVnfInfra PreProcessRequest Process*** ", isDebugEnabled)
56 execution.setVariable("CREVI_sentSyncResponse", false)
60 String createVnfRequest = execution.getVariable("bpmnRequest")
61 execution.setVariable("CREVI_createVnfRequest", createVnfRequest)
62 utils.logAudit("Incoming CreateVnfInfra Request is: \n" + createVnfRequest)
64 if(createVnfRequest != null){
66 String requestId = execution.getVariable("att-mso-request-id")
67 execution.setVariable("CREVI_requestId", requestId)
68 utils.log("DEBUG", "Incoming Request Id is: " + requestId, isDebugEnabled)
70 String serviceInstanceId = execution.getVariable("serviceInstanceId")
71 execution.setVariable("CREVI_serviceInstanceId", serviceInstanceId)
72 utils.log("DEBUG", "Incoming Service Instance Id is: " + serviceInstanceId, isDebugEnabled)
74 String vnfType = execution.getVariable("vnfType")
75 execution.setVariable("CREVI_vnfType", vnfType)
76 utils.log("DEBUG", "Incoming Vnf Type is: " + vnfType, isDebugEnabled)
78 String vnfName = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.instanceName")
79 execution.setVariable("CREVI_vnfName", vnfName)
80 utils.log("DEBUG", "Incoming Vnf Name is: " + vnfName, isDebugEnabled)
82 String serviceId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.productFamilyId")
83 execution.setVariable("CREVI_serviceId", serviceId)
84 utils.log("DEBUG", "Incoming Service Id is: " + serviceId, isDebugEnabled)
86 String source = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.source")
87 execution.setVariable("CREVI_source", source)
88 utils.log("DEBUG", "Incoming Source is: " + source, isDebugEnabled)
90 String suppressRollback = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.requestInfo.suppressRollback")
91 execution.setVariable("CREVI_suppressRollback", suppressRollback)
92 utils.log("DEBUG", "Incoming Suppress Rollback is: " + suppressRollback, isDebugEnabled)
94 String modelInvariantId = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo.modelInvariantId")
95 execution.setVariable("CREVI_modelInvariantId", modelInvariantId)
96 utils.log("DEBUG", "Incoming Invariant Id is: " + modelInvariantId, isDebugEnabled)
98 String modelVersion = jsonUtil.getJsonValue(createVnfRequest, "requestDetails.modelInfo.modelVersion")
99 execution.setVariable("CREVI_modelVersion", modelVersion)
100 utils.log("DEBUG", "Incoming Model Version is: " + modelVersion, isDebugEnabled)
102 //For Completion Handler & Fallout Handler
104 """<request-info xmlns="http://ecomp.att.com/mso/infra/vnf-request/v1">
105 <request-id>${requestId}</request-id>
106 <action>CREATE</action>
107 <source>${source}</source>
110 execution.setVariable("CREVI_requestInfo", requestInfo)
112 //TODO: Orch Status - TBD, will come from SDN-C Response in 1702
113 String orchStatus = "Created"
114 execution.setVariable("CREVI_orchStatus", orchStatus)
116 //TODO: Equipment Role - Should come from SDN-C Response in 1702
117 String equipmentRole = " "
118 execution.setVariable("CREVI_equipmentRole", equipmentRole)
120 String vnfId = execution.getVariable("testVnfId") // for junits
122 vnfId = UUID.randomUUID().toString()
123 utils.log("DEBUG", "Generated Vnf Id is: " + vnfId, isDebugEnabled)
125 execution.setVariable("CREVI_vnfId", vnfId)
127 // Setting for Sub Flow Calls
128 execution.setVariable("CREVI_type", "generic-vnf")
129 execution.setVariable("GENGS_type", "service-instance")
132 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Incoming Bpmn Request is Null.")
136 utils.log("DEBUG", "Rethrowing MSOWorkflowException", isDebugEnabled)
139 utils.log("DEBUG", " Error Occured in CreateVnfInfra PreProcessRequest method!" + e.getMessage(), isDebugEnabled)
140 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PreProcessRequest")
143 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PreProcessRequest Process ***", isDebugEnabled)
146 public void sendSyncResponse (Execution execution) {
147 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
148 execution.setVariable("prefix",Prefix)
150 utils.log("DEBUG", " *** STARTED CreateVnfInfra SendSyncResponse Process *** ", isDebugEnabled)
153 String requestId = execution.getVariable("CREVI_requestId")
154 String vnfId = execution.getVariable("CREVI_vnfId")
156 String createVnfResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
158 utils.log("DEBUG", " CreateVnfInfra Sync Response is: \n" + createVnfResponse, isDebugEnabled)
160 sendWorkflowResponse(execution, 202, createVnfResponse)
162 execution.setVariable("CREVI_sentSyncResponse", true)
164 } catch (Exception ex) {
165 utils.log("DEBUG", "Error Occured in CreateVnfInfra SendSyncResponse Process " + ex.getMessage(), isDebugEnabled)
166 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra SendSyncResponse Process")
169 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra SendSyncResponse Process ***", isDebugEnabled)
172 public void prepareCreateGenericVnf (Execution execution) {
173 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
174 execution.setVariable("prefix",Prefix)
176 utils.log("DEBUG", " *** STARTED CreateVnfInfra PrepareCreateGenericVnf Process *** ", isDebugEnabled)
179 String vnfId = execution.getVariable("CREVI_vnfId")
180 def vnfName = execution.getVariable("CREVI_vnfName")
181 def vnfType = execution.getVariable("CREVI_vnfType")
182 def serviceId = execution.getVariable("CREVI_serviceId")
183 def orchStatus = execution.getVariable("CREVI_orchStatus")
184 def modelInvariantId = execution.getVariable("CREVI_modelInvariantId")
185 def modelVersion = execution.getVariable("CREVI_modelVersion")
186 // TODO: 1702 Variable
187 def equipmentRole = execution.getVariable("CREVI_equipmentRole")
189 //Get Service Instance Info
190 def serviceInstanceId = execution.getVariable("CREVI_serviceInstanceId")
191 String siRelatedLink = execution.getVariable("GENGS_siResourceLink")
193 int custStart = siRelatedLink.indexOf("customer/")
194 int custEnd = siRelatedLink.indexOf("/service-subscriptions")
195 String globalCustId = siRelatedLink.substring(custStart + 9, custEnd)
196 int serviceStart = siRelatedLink.indexOf("service-subscription/")
197 int serviceEnd = siRelatedLink.indexOf("/service-instances/")
198 String serviceType = siRelatedLink.substring(serviceStart + 21, serviceEnd)
201 AaiUtil aaiUtil = new AaiUtil(this)
202 def aai_uri = aaiUtil.getNetworkGenericVnfUri(execution)
203 String namespace = aaiUtil.getNamespaceFromUri(aai_uri)
206 """<generic-vnf xmlns="${namespace}">
207 <vnf-id>${vnfId}</vnf-id>
208 <vnf-name>${vnfName}</vnf-name>
209 <service-id>${serviceId}</service-id>
210 <vnf-type>${vnfType}</vnf-type>
211 <orchestration-status>${orchStatus}</orchestration-status>
212 <persona-model-id>${modelInvariantId}</persona-model-id>
213 <persona-model-version>${modelVersion}</persona-model-version>
216 <related-to>service-instance</related-to>
217 <related-link>${siRelatedLink}</related-link>
219 <relationship-key>customer.global-customer-id</relationship-key>
220 <relationship-value>${globalCustId}</relationship-value>
223 <relationship-key>service-subscription.service-type</relationship-key>
224 <relationship-value>${serviceType}</relationship-value>
227 <relationship-key>service-instance.service-instance-id</relationship-key>
228 <relationship-value>${serviceInstanceId}</relationship-value>
234 execution.setVariable("CREVI_genericVnfPayload", payload)
236 }catch(Exception ex) {
237 utils.log("DEBUG", "Error Occured in CreateVnfInfra PrepareCreateGenericVnf Process " + ex.getMessage(), isDebugEnabled)
238 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PrepareCreateGenericVnf Process")
240 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCreateGenericVnf Process ***", isDebugEnabled)
243 public void prepareCompletionHandlerRequest(Execution execution){
244 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
245 execution.setVariable("prefix",Prefix)
247 utils.log("DEBUG", " *** STARTED CreateVnfInfra PrepareCompletionHandlerRequest Process *** ", isDebugEnabled)
250 String requestInfo = execution.getVariable("CREVI_requestInfo")
251 String vnfId = execution.getVariable("CREVI_vnfId")
252 requestInfo = utils.removeXmlPreamble(requestInfo)
255 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://ecomp.att.com/mso/workflow/schema/v1"
256 xmlns:ns="http://ecomp.att.com/mso/request/types/v1">
258 <status-message>Vnf has been created successfully.</status-message>
259 <vnfId>${vnfId}</vnfId>
260 <mso-bpel-name>CreateVnfInfra</mso-bpel-name>
261 </aetgt:MsoCompletionRequest>"""
263 execution.setVariable("CREVI_completionHandlerRequest", request)
264 utils.log("DEBUG", "Completion Handler Request is: " + request, isDebugEnabled)
266 execution.setVariable("WorkflowResponse", "Success") // for junits
268 } catch (Exception ex) {
269 utils.log("DEBUG", "Error Occured in CreateVnfInfra PrepareCompletionHandlerRequest Process " + ex.getMessage(), isDebugEnabled)
270 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra PrepareCompletionHandlerRequest Process")
273 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra PrepareCompletionHandlerRequest Process ***", isDebugEnabled)
276 public void sendErrorResponse(Execution execution){
277 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
278 execution.setVariable("prefix",Prefix)
280 utils.log("DEBUG", " *** STARTED CreateVnfInfra sendErrorResponse Process *** ", isDebugEnabled)
282 def sentSyncResponse = execution.getVariable("CREVI_sentSyncResponse")
283 if(sentSyncResponse == false){
284 WorkflowException wfex = execution.getVariable("WorkflowException")
285 String response = exceptionUtil.buildErrorResponseXml(wfex)
287 utils.logAudit(response)
288 sendWorkflowResponse(execution, 500, response)
290 utils.log("DEBUG", "Not Sending Error Response. Sync Response Already Sent", isDebugEnabled)
293 } catch (Exception ex) {
294 utils.log("DEBUG", "Error Occured in CreateVnfInfra sendErrorResponse Process " + ex.getMessage(), isDebugEnabled)
295 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra sendErrorResponse Process")
298 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra sendErrorResponse Process ***", isDebugEnabled)
301 public void prepareFalloutRequest(Execution execution){
302 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
303 execution.setVariable("prefix",Prefix)
305 utils.log("DEBUG", " *** STARTED CreateVnfInfra prepareFalloutRequest Process *** ", isDebugEnabled)
308 WorkflowException wfex = execution.getVariable("WorkflowException")
309 utils.log("DEBUG", " Incoming Workflow Exception: " + wfex.toString(), isDebugEnabled)
310 String requestInfo = execution.getVariable("CREVI_requestInfo")
311 utils.log("DEBUG", " Incoming Request Info: " + requestInfo, isDebugEnabled)
313 String falloutRequest = exceptionUtil.processMainflowsBPMNException(execution, requestInfo)
315 execution.setVariable("CREVI_falloutRequest", falloutRequest)
318 } catch (Exception ex) {
319 utils.log("DEBUG", "Error Occured in CreateVnfInfra prepareFalloutRequest Process " + ex.getMessage(), isDebugEnabled)
320 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in CreateVnfInfra prepareFalloutRequest Process")
323 utils.log("DEBUG", "*** COMPLETED CreateVnfInfra prepareFalloutRequest Process ***", isDebugEnabled)