2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import org.onap.so.client.HttpClientFactory
26 import org.onap.so.logger.ErrorCode
28 import javax.ws.rs.core.Response
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.onap.so.bpmn.common.scripts.AaiUtil
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.core.domain.ModelInfo
36 import org.onap.so.bpmn.core.domain.ModuleResource
37 import org.onap.so.bpmn.core.domain.VnfResource
38 import org.onap.so.bpmn.core.json.JsonUtils
39 import org.onap.so.client.graphinventory.entities.uri.Depth
40 import org.onap.so.client.HttpClient
41 import org.onap.so.client.aai.AAIObjectType
42 import org.onap.so.client.aai.entities.uri.AAIResourceUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
44 import org.onap.so.logger.MessageEnum
45 import org.slf4j.Logger
46 import org.slf4j.LoggerFactory
47 import org.onap.so.utils.TargetEntity
50 * This class supports the VID Flow
51 * with the update of a generic vnf and related VF modules.
53 class DoUpdateVnfAndModules extends AbstractServiceTaskProcessor {
54 private static final Logger logger = LoggerFactory.getLogger( DoUpdateVnfAndModules.class);
56 String Prefix="DUVAM_"
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
58 JsonUtils jsonUtil = new JsonUtils()
61 * This method gets and validates the incoming
67 public void preProcessRequest(DelegateExecution execution) {
69 execution.setVariable("prefix",Prefix)
70 logger.trace("STARTED DoUpdateVnfAndModules PreProcessRequest Process")
75 String requestId = execution.getVariable("msoRequestId")
76 execution.setVariable("requestId", requestId)
77 execution.setVariable("mso-request-id", requestId)
78 logger.debug("Incoming Request Id is: " + requestId)
80 String serviceInstanceId = execution.getVariable("serviceInstanceId")
81 logger.debug("Incoming Service Instance Id is: " + serviceInstanceId)
83 String vnfId = execution.getVariable("vnfId")
84 logger.debug("Incoming Vnf Id is: " + vnfId)
87 execution.setVariable("DUVAM_source", source)
88 logger.debug("Incoming Source is: " + source)
90 String sdncVersion = execution.getVariable("sdncVersion")
91 if (sdncVersion == null) {
94 execution.setVariable("DUVAM_sdncVersion", sdncVersion)
95 logger.debug("Incoming Sdnc Version is: " + sdncVersion)
97 VnfResource vnfResource = (VnfResource) execution.getVariable("vnfResourceDecomposition")
99 String vnfModelInfo = execution.getVariable("vnfModelInfo")
100 String serviceModelInfo = execution.getVariable("serviceModelInfo")
102 String serviceId = execution.getVariable("productFamilyId")
103 execution.setVariable("DUVAM_serviceId", serviceId)
104 logger.debug("Incoming Service Id is: " + serviceId)
106 String modelUuid = jsonUtil.getJsonValue(vnfModelInfo, "modelUuid")
107 execution.setVariable("DUVAM_modelUuid", modelUuid)
108 logger.debug("Incoming modelUuid is: " + modelUuid)
110 String modelCustomizationUuid = jsonUtil.getJsonValue(vnfModelInfo, "modelCustomizationUuid")
111 execution.setVariable("DUVAM_modelCustomizationUuid", modelCustomizationUuid)
112 logger.debug("Incoming Model Customization Uuid is: " + modelCustomizationUuid)
114 String cloudSiteId = execution.getVariable("lcpCloudRegionId")
115 execution.setVariable("DUVAM_cloudSiteId", cloudSiteId)
116 logger.debug("Incoming Cloud Site Id is: " + cloudSiteId)
118 String tenantId = execution.getVariable("tenantId")
119 execution.setVariable("DUVAM_tenantId", tenantId)
120 logger.debug("Incoming Tenant Id is: " + tenantId)
122 String globalSubscriberId = execution.getVariable("globalSubscriberId")
123 if (globalSubscriberId == null) {
124 globalSubscriberId = ""
126 execution.setVariable("DUVAM_globalSubscriberId", globalSubscriberId)
127 logger.debug("Incoming Global Subscriber Id is: " + globalSubscriberId)
129 execution.setVariable("DUVAM_moduleCount", 0)
130 execution.setVariable("DUVAM_nextModule", 0)
134 logger.debug("Rethrowing MSOWorkflowException")
137 logger.debug(" Error Occured in DoUpdateVnfAndModules PreProcessRequest method!" + e.getMessage())
138 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoUpdateVnfAndModules PreProcessRequest")
141 logger.trace("COMPLETED DoUpdateVnfAndModules PreProcessRequest Process ")
145 * Using the received vnfId and vfModuleId, query AAI to get the corresponding VNF info.
146 * A 200 response is expected with the VNF info in the response body. Will find out the base module info.
148 * @param execution The flow's execution instance.
150 public void queryAAIVfModule(DelegateExecution execution) {
152 def method = getClass().getSimpleName() + '.queryAAIVfModule(' +
153 'execution=' + execution.getId() +
155 logger.trace('Entered ' + method)
158 def vnfId = execution.getVariable('vnfId')
160 AaiUtil aaiUriUtil = new AaiUtil(this)
161 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE)
162 String endPoint = aaiUriUtil.createAaiUri(uri)
163 logger.debug("AAI endPoint: " + endPoint)
166 HttpClient client = new HttpClientFactory().newXmlClient(new URL(endPoint), TargetEntity.AAI)
167 client.addAdditionalHeader('X-TransactionId', UUID.randomUUID().toString())
168 client.addAdditionalHeader('X-FromAppId', 'MSO')
169 client.addAdditionalHeader('Content-Type', 'application/xml')
170 client.addAdditionalHeader('Accept','application/xml')
172 def responseData = ''
174 logger.debug('sending GET to AAI endpoint \'' + endPoint + '\'')
175 Response response = client.get()
176 logger.debug("createVfModule - invoking httpGet() to AAI")
178 responseData = response.readEntity(String.class)
179 if (responseData != null) {
180 logger.debug("Received generic VNF data: " + responseData)
184 logger.debug("createVfModule - queryAAIVfModule Response: " + responseData)
185 logger.debug("createVfModule - queryAAIVfModule ResponseCode: " + response.getStatus())
187 execution.setVariable('DUVAM_queryAAIVfModuleResponseCode', response.getStatus())
188 execution.setVariable('DUVAM_queryAAIVfModuleResponse', responseData)
189 logger.debug('Response code:' + response.getStatus())
190 logger.debug('Response:' + System.lineSeparator() + responseData)
191 //Map<String, String>[] vfModules = new HashMap<String,String>[]
192 def vfModulesList = new ArrayList<Map<String,String>>()
194 def vfModuleBaseEntry = null
195 if (response.getStatus() == 200) {
196 // Parse the VNF record from A&AI to find base module info
197 logger.debug('Parsing the VNF data to find base module info')
198 if (responseData != null) {
199 def vfModulesText = utils.getNodeXml(responseData, "vf-modules")
200 logger.debug("vModulesText: " + vfModulesText)
201 if (vfModulesText != null && !vfModulesText.trim().isEmpty()) {
202 def xmlVfModules= new XmlSlurper().parseText(vfModulesText)
203 vfModules = xmlVfModules.'**'.findAll {it.name() == "vf-module"}
204 execution.setVariable("DUVAM_moduleCount", vfModules.size())
205 int vfModulesSize = 0
206 for (i in 0..vfModules.size()-1) {
207 def vfModuleXml = groovy.xml.XmlUtil.serialize(vfModules[i])
209 Map<String, String> vfModuleEntry = new HashMap<String, String>()
210 def vfModuleId = utils.getNodeText(vfModuleXml, "vf-module-id")
211 vfModuleEntry.put("vfModuleId", vfModuleId)
212 def vfModuleName = utils.getNodeText(vfModuleXml, "vf-module-name")
213 vfModuleEntry.put("vfModuleName", vfModuleName)
214 def modelInvariantUuid = utils.getNodeText(vfModuleXml, "model-invariant-id")
215 vfModuleEntry.put("modelInvariantUuid", modelInvariantUuid)
216 def modelUuid = utils.getNodeText(vfModuleXml, "model-version-id")
217 vfModuleEntry.put("modelUuid", modelUuid)
218 def modelCustomizationUuid = utils.getNodeText(vfModuleXml, "model-customization-id")
219 vfModuleEntry.put("modelCustomizationUuid", modelCustomizationUuid)
221 def isBaseVfModule = utils.getNodeText(vfModuleXml, "is-base-vf-module")
222 vfModuleEntry.put("isBaseVfModule", isBaseVfModule)
224 String volumeGroupId = ''
226 logger.debug("Next module!")
227 def vfModuleRelationships = vfModules[i].'**'.findAll {it.name() == 'relationship-data'}
228 if (vfModuleRelationships.size() > 0) {
229 for (j in 0..vfModuleRelationships.size()-1) {
230 if (vfModuleRelationships[j] != null) {
232 def relationshipKey = vfModuleRelationships[j].'**'.findAll {it.name() == 'relationship-key'}
234 if (relationshipKey[0] == 'volume-group.volume-group-id') {
235 def relationshipValue = vfModuleRelationships[j].'**'.findAll {it.name() == 'relationship-value'}
236 volumeGroupId = relationshipValue[0]
243 vfModuleEntry.put("volumeGroupId", volumeGroupId)
244 logger.debug("volumeGroupId is: " + volumeGroupId)
246 // Save base vf module to add it to the start of the list later
247 if (isBaseVfModule == "true") {
248 vfModuleBaseEntry = vfModuleEntry
251 vfModulesList.add(vfModuleEntry)
254 // Start the list with the base module if any
255 if (vfModuleBaseEntry != null) {
256 vfModulesList.add(0, vfModuleBaseEntry)
263 logger.debug('Response code from AAI GET is: ' + response.getStatusCode())
264 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Response code from AAI GET is: ' + response.getStatusCode())
266 execution.setVariable("DUVAM_vfModules", vfModulesList)
267 } catch (Exception ex) {
268 logger.debug('Exception occurred while executing AAI GET: {}', ex.getMessage(), ex)
269 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'AAI GET Failed:' + ex.getMessage())
271 logger.trace('Exited ' + method)
272 } catch (BpmnError e) {
274 } catch (Exception e) {
275 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
276 'Caught exception in ' + method, "BPMN",
277 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
278 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIVfModule(): ' + e.getMessage())
282 public void prepareNextModuleToUpdate(DelegateExecution execution){
284 execution.setVariable("prefix", Prefix)
285 logger.trace("STARTED prepareNextModuleToUpdate ")
288 int i = execution.getVariable("DUVAM_nextModule")
289 def vfModules = execution.getVariable("DUVAM_vfModules")
290 def vfModule = vfModules[i]
292 def vfModuleId = vfModule.get("vfModuleId")
293 execution.setVariable("DUVAM_vfModuleId", vfModuleId)
295 def vfModuleName = vfModule.get("vfModuleName")
296 execution.setVariable("DUVAM_vfModuleName", vfModuleName)
298 def isBaseVfModule = vfModule.get("isBaseVfModule")
299 execution.setVariable("DUVAM_isBaseVfModule", isBaseVfModule)
301 String modelInvariantUuid = vfModule.get("modelInvariantUuid")
302 logger.debug("ModelInvariantUuid: " + modelInvariantUuid)
304 def volumeGroupId = vfModule.get("volumeGroupId")
305 execution.setVariable("DUVAM_volumeGroupId", volumeGroupId)
307 execution.setVariable("DUVAM_volumeGroupName", "")
309 VnfResource vnfResource = (VnfResource) execution.getVariable("vnfResourceDecomposition")
310 List<ModuleResource> moduleResources = vnfResource.getVfModules()
312 if (moduleResources != null && !moduleResources.isEmpty()) {
314 for (j in 0..moduleResources.size()-1) {
315 ModelInfo modelInfo = moduleResources[j].getModelInfo()
316 String modelInvariantUuidFromDecomposition = modelInfo.getModelInvariantUuid()
317 logger.debug("modelInvariantUuidFromDecomposition: " + modelInvariantUuidFromDecomposition)
319 if (modelInvariantUuid.equals(modelInvariantUuidFromDecomposition)) {
320 String vfModuleModelInfo = modelInfo.toJsonString()
321 String vfModuleModelInfoValue = jsonUtil.getJsonValue(vfModuleModelInfo, "modelInfo")
322 execution.setVariable("DUVAM_vfModuleModelInfo", vfModuleModelInfoValue)
323 logger.debug("vfModuleModelInfo: " + vfModuleModelInfoValue)
331 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
332 "Exception Occured Processing preProcessAddOnModule. Exception is:\n" + e, "BPMN",
333 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
334 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during prepareNextModuleToUpdate Method:\n" + e.getMessage())
336 logger.trace("COMPLETED prepareNextModuleToUpdate ")
341 * Prepare a Request for invoking the UpdateAAIGenericVnf subflow.
343 * @param execution The flow's execution instance.
345 public void prepUpdateAAIGenericVnf(DelegateExecution execution) {
346 def method = getClass().getSimpleName() + '.prepUpdateAAIGenericVnf(' +
347 'execution=' + execution.getId() +
350 logger.trace('Entered ' + method)
353 def vnfId = execution.getVariable('vnfId')
354 VnfResource vnfResource = (VnfResource) execution.getVariable("vnfResourceDecomposition")
355 ModelInfo vnfDecompModelInfo = vnfResource.getModelInfo()
356 String vnfModelInfo = execution.getVariable("vnfModelInfo")
357 String modelUuid = execution.getVariable("DUVAM_modelUuid")
358 if (modelUuid == null || modelUuid.isEmpty()) {
359 modelUuid = vnfDecompModelInfo.getModelUuid()
361 String modelCustomizationUuid = execution.getVariable("DUVAM_modelCustomizationUuid")
362 if (modelCustomizationUuid == null || modelCustomizationUuid.isEmpty()) {
363 modelCustomizationUuid = vnfDecompModelInfo.getModelCustomizationUuid()
365 String nfType = vnfResource.getNfType()
366 String nfTypeString = ''
367 if (nfType != null && !nfType.isEmpty()) {
368 nfTypeString = "<nf-type>" + nfType + "</nf-type>"
370 String nfRole = vnfResource.getNfRole()
371 String nfRoleString = ''
372 if (nfRole != null && !nfRole.isEmpty()) {
373 nfRoleString = "<nf-role>" + nfRole + "</nf-role>"
375 String nfFunction = vnfResource.getNfFunction()
376 String nfFunctionString = ''
377 if (nfFunction != null && !nfFunction.isEmpty()) {
378 nfFunctionString = "<nf-function>" + nfFunction + "</nf-function>"
380 String nfNamingCode = vnfResource.getNfNamingCode()
381 String nfNamingCodeString = ''
382 if (nfNamingCode != null && !nfNamingCode.isEmpty()) {
383 nfNamingCodeString = "<nf-naming-code>" + nfNamingCode + "</nf-naming-code>"
386 String updateAAIGenericVnfRequest = """
387 <UpdateAAIGenericVnfRequest>
388 <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
389 <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id>
390 <model-customization-id>${MsoUtils.xmlEscape(modelCustomizationUuid)}</model-customization-id>
394 ${nfNamingCodeString}
395 </UpdateAAIGenericVnfRequest>
397 updateAAIGenericVnfRequest = utils.formatXml(updateAAIGenericVnfRequest)
398 execution.setVariable('DUVAM_updateAAIGenericVnfRequest', updateAAIGenericVnfRequest)
399 logger.debug("updateAAIGenericVnfRequest : " + updateAAIGenericVnfRequest)
400 logger.debug('Request for UpdateAAIGenericVnf:\n' + updateAAIGenericVnfRequest)
403 logger.trace('Exited ' + method)
404 } catch (BpmnError e) {
406 } catch (Exception e) {
407 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
408 'Caught exception in ' + method, "BPMN",
409 ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
410 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepUpdateAAIGenericVnf(): ' + e.getMessage())
415 * APP-C Call - placeholder.
417 * @param execution The flow's execution instance.
419 public void callAppCf(DelegateExecution execution) {
420 def method = getClass().getSimpleName() + '.callAppC(' +
421 'execution=' + execution.getId() +
424 logger.trace('Entered ' + method)