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.common.scripts
23 import groovy.json.JsonBuilder
24 import groovy.json.JsonSlurper
26 import org.json.JSONObject
28 import org.openecomp.mso.bpmn.core.xml.XmlTool
32 public MsoUtils utils = new MsoUtils()
33 private AbstractServiceTaskProcessor taskProcessor
35 public VidUtils(AbstractServiceTaskProcessor taskProcessor) {
36 this.taskProcessor = taskProcessor
40 * Create a volume-request XML using a JSON string
41 * @param jsonReq - JSON request from VID
45 public String createXmlVolumeRequest(String jsonReq, String action, String serviceInstanceId) {
46 def jsonSlurper = new JsonSlurper()
48 Map reqMap = jsonSlurper.parseText(jsonReq)
49 return createXmlVolumeRequest(reqMap, action, serviceInstanceId)
57 * Create a volume-request XML using a map
58 * @param requestMap - map created from VID JSON
60 * @param serviceInstanceId
63 public String createXmlVolumeRequest(Map requestMap, String action, String serviceInstanceId) {
64 createXmlVolumeRequest(requestMap, action, serviceInstanceId, '')
69 * Create a volume-request XML using a map
72 * @param serviceInstanceId
73 * @param volumeGroupId
76 public String createXmlVolumeRequest(Map requestMap, String action, String serviceInstanceId, String volumeGroupId) {
79 def modelCustomizationName = ''
80 def asdcServiceModelVersion = ''
82 def suppressRollback = requestMap.requestDetails.requestInfo.suppressRollback
84 def backoutOnFailure = ""
85 if(suppressRollback != null){
86 if ( suppressRollback == true) {
87 backoutOnFailure = "false"
88 } else if ( suppressRollback == false) {
89 backoutOnFailure = "true"
93 def volGrpName = requestMap.requestDetails.requestInfo?.instanceName ?: ''
94 def serviceId = requestMap.requestDetails.requestParameters?.serviceId ?: ''
95 def relatedInstanceList = requestMap.requestDetails.relatedInstanceList
96 relatedInstanceList.each {
97 if (it.relatedInstance.modelInfo?.modelType == 'service') {
98 serviceName = it.relatedInstance.modelInfo?.modelName
99 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
101 if (it.relatedInstance.modelInfo?.modelType == 'vnf') {
102 modelCustomizationName = it.relatedInstance.modelInfo?.modelCustomizationName
106 vnfType = serviceName + '/' + modelCustomizationName
108 def userParams = requestMap.requestDetails?.requestParameters?.userParams
109 def userParamsNode = ''
110 if(userParams != null) {
111 userParamsNode = buildUserParams(userParams)
113 def modelCustomizationId = requestMap.requestDetails?.modelInfo?.modelCustomizationId ?: ''
116 <volume-request xmlns="http://www.w3.org/2001/XMLSchema">
118 <action>${action}</action>
119 <source>${requestMap.requestDetails.requestInfo.source}</source>
120 <service-instance-id>${serviceInstanceId}</service-instance-id>
123 <volume-group-id>${volumeGroupId}</volume-group-id>
124 <volume-group-name>${volGrpName}</volume-group-name>
125 <vnf-type>${vnfType}</vnf-type>
126 <vf-module-model-name>${requestMap.requestDetails.modelInfo.modelName}</vf-module-model-name>
127 <asdc-service-model-version>${asdcServiceModelVersion}</asdc-service-model-version>
128 <aic-cloud-region>${requestMap.requestDetails.cloudConfiguration.lcpCloudRegionId}</aic-cloud-region>
129 <tenant-id>${requestMap.requestDetails.cloudConfiguration.tenantId}</tenant-id>
130 <service-id>${serviceId}</service-id>
131 <backout-on-failure>${backoutOnFailure}</backout-on-failure>
132 <model-customization-id>${modelCustomizationId}</model-customization-id>
139 // return a pretty-print of the volume-request xml without the preamble
140 return groovy.xml.XmlUtil.serialize(xmlReq.normalize().replaceAll("\t", "").replaceAll("\n", "")).replaceAll("(<\\?[^<]*\\?>\\s*[\\r\\n]*)?", "")
144 * A common method that can be used to build volume-params node from a map.
145 * @param Map userParams
148 public String buildUserParams(userParams) {
149 if (userParams == null) return ""
153 userParams.each {it ->
154 key = it.name.replaceAll(/\B[A-Z]/) { '_' + it }.toLowerCase()
156 xml += "<param name=\"${key}\">${value}</param>"
163 * A common method that can be used to extract 'requestDetails'
165 * @return String json requestDetails
168 public getJsonRequestDetails(String jsonInput) {
170 if (jsonInput.isEmpty() || jsonInput == null) {
173 def jsonMapObject = new JsonSlurper().parseText(jsonInput)
174 if (jsonMapObject instanceof Map) {
175 String jsonString = new JsonBuilder(jsonMapObject.requestDetails)
176 rtn = '{'+"requestDetails"+":"+jsonString+'}'
185 * A common method that can be used to extract 'requestDetails' in Xml
187 * @return String xml requestDetails
190 public getJsonRequestDetailstoXml(String jsonInput) {
192 def jsonString = getJsonRequestDetails(jsonInput)
193 if (jsonString == null) {
196 JSONObject jsonObj = new JSONObject(jsonString)
197 return XmlTool.normalize(XML.toString(jsonObj))
202 * Create a network-request XML using a map
204 * @param xmlRequestDetails - requestDetails in xml
206 * Note: See latest version: createXmlNetworkRequestInstance()
208 public String createXmlNetworkRequestInfra(execution, def networkJsonIncoming) {
210 def requestId = execution.getVariable("requestId")
211 def serviceInstanceId = execution.getVariable("serviceInstanceId")
212 def requestAction = execution.getVariable("requestAction")
213 def networkId = (execution.getVariable("networkId")) != null ? execution.getVariable("networkId") : ""
215 def jsonSlurper = new JsonSlurper()
217 Map reqMap = jsonSlurper.parseText(networkJsonIncoming)
218 def instanceName = reqMap.requestDetails.requestInfo.instanceName
219 def modelName = reqMap.requestDetails.modelInfo.modelName
220 def lcpCloudRegionId = reqMap.requestDetails.cloudConfiguration.lcpCloudRegionId
221 def tenantId = reqMap.requestDetails.cloudConfiguration.tenantId
222 def serviceId = reqMap.requestDetails.requestInfo.productFamilyId
223 def suppressRollback = reqMap.requestDetails.requestInfo.suppressRollback.toString()
224 def backoutOnFailure = ""
225 if(suppressRollback != null){
226 if (suppressRollback == true || suppressRollback == "true") {
227 backoutOnFailure = "false"
228 } else if (suppressRollback == false || suppressRollback == "false") {
229 backoutOnFailure = "true"
233 //def userParams = reqMap.requestDetails.requestParameters.userParams
234 //def userParamsNode = buildUserParams(userParams)
235 def userParams = reqMap.requestDetails?.requestParameters?.userParams
236 def userParamsNode = ''
237 if(userParams != null) {
238 userParamsNode = buildUserParams(userParams)
241 //'sdncVersion' = current, '1610' (non-RPC SDNC) or '1702' (RPC SDNC)
242 def sdncVersion = execution.getVariable("sdncVersion")
245 <network-request xmlns="http://www.w3.org/2001/XMLSchema">
247 <request-id>${requestId}</request-id>
248 <action>${requestAction}</action>
250 <service-instance-id>${serviceInstanceId}</service-instance-id>
253 <network-id>${networkId}</network-id>
254 <network-name>${instanceName}</network-name>
255 <network-type>${modelName}</network-type>
256 <aic-cloud-region>${lcpCloudRegionId}</aic-cloud-region>
257 <tenant-id>${tenantId}</tenant-id>
258 <service-id>${serviceId}</service-id>
259 <backout-on-failure>${backoutOnFailure}</backout-on-failure>
260 <sdncVersion>${sdncVersion}</sdncVersion>
267 // return a pretty-print of the volume-request xml without the preamble
268 return groovy.xml.XmlUtil.serialize(xmlReq.normalize().replaceAll("\t", "").replaceAll("\n", "")).replaceAll("(<\\?[^<]*\\?>\\s*[\\r\\n]*)?", "")
270 } catch(Exception e) {
276 * Create a network-request XML using a map,
280 public String createXmlNetworkRequestInstance(execution) {
282 def networkModelVersionId = ""
283 def networkModelName = ""
284 def networkModelType = ""
285 def networkModelVersion = ""
286 def networkModelCustomizationId = ""
287 def networkModelInvariantId = ""
289 // verify the DB Catalog response JSON structure
290 def networkModelInfo = execution.getVariable("networkModelInfo")
291 def jsonSlurper = new JsonSlurper()
292 if (networkModelInfo != null) {
294 Map modelMap = jsonSlurper.parseText(networkModelInfo)
295 if (modelMap != null) {
296 if (networkModelInfo.contains("modelVersionId")) {
297 networkModelVersionId = modelMap.modelVersionId !=null ? modelMap.modelVersionId : ""
299 if (networkModelInfo.contains("modelName")) {
300 networkModelName = modelMap.modelName !=null ? modelMap.modelName : ""
302 if (networkModelInfo.contains("modelType")) {
303 networkModelType = modelMap.modelType !=null ? modelMap.modelType : ""
305 if (networkModelInfo.contains("modelVersion")) {
306 networkModelVersion = modelMap.modelVersion !=null ? modelMap.modelVersion : ""
308 if (networkModelInfo.contains("modelCustomizationId")) {
309 networkModelCustomizationId = modelMap.modelCustomizationId !=null ? modelMap.modelCustomizationId : ""
311 if (networkModelInfo.contains("modelInvariantId")) {
312 networkModelInvariantId = modelMap.modelInvariantId !=null ? modelMap.modelInvariantId : ""
315 } catch (Exception ex) {
320 def serviceModelVersionId = ""
321 def serviceModelName = ""
322 def serviceModelType = ""
323 def serviceModelVersion = ""
324 def serviceModelCustomizationId = ""
325 def serviceModelInvariantId = ""
327 // verify the DB Catalog response JSON structure
328 def serviceModelInfo = execution.getVariable("serviceModelInfo")
329 def jsonServiceSlurper = new JsonSlurper()
330 if (serviceModelInfo != null) {
332 Map modelMap = jsonServiceSlurper.parseText(serviceModelInfo)
333 if (modelMap != null) {
334 if (serviceModelInfo.contains("modelVersionId")) {
335 serviceModelVersionId = modelMap.modelVersionId !=null ? modelMap.modelVersionId : ""
337 if (serviceModelInfo.contains("modelName")) {
338 serviceModelName = modelMap.modelName !=null ? modelMap.modelName : ""
340 if (serviceModelInfo.contains("modelType")) {
341 serviceModelType = modelMap.modelType !=null ? modelMap.modelType : ""
343 if (serviceModelInfo.contains("modelVersion")) {
344 serviceModelVersion = modelMap.modelVersion !=null ? modelMap.modelVersion : ""
346 if (serviceModelInfo.contains("modelCustomizationId")) {
347 serviceModelCustomizationId = modelMap.modelCustomizationId !=null ? modelMap.modelCustomizationId : ""
349 if (serviceModelInfo.contains("modelInvariantId")) {
350 serviceModelInvariantId = modelMap.modelInvariantId !=null ? modelMap.modelInvariantId : ""
353 } catch (Exception ex) {
359 def subscriptionServiceType = execution.getVariable("subscriptionServiceType") != null ? execution.getVariable("subscriptionServiceType") : ""
360 def globalSubscriberId = execution.getVariable("globalSubscriberId") != null ? execution.getVariable("globalSubscriberId") : ""
361 def requestId = execution.getVariable("msoRequestId")
362 def serviceInstanceId = execution.getVariable("serviceInstanceId") != null ? execution.getVariable("serviceInstanceId") : ""
363 def networkId = (execution.getVariable("networkId")) != null ? execution.getVariable("networkId") : "" // optional
364 def networkName = execution.getVariable("networkName") != null ? execution.getVariable("networkName") : "" // optional
365 def aicCloudReqion = execution.getVariable("lcpCloudRegionId") != null ? execution.getVariable("lcpCloudRegionId") : ""
366 def tenantId = execution.getVariable("tenantId") != null ? execution.getVariable("tenantId") : ""
367 def serviceId = execution.getVariable("productFamilyId") != null ? execution.getVariable("productFamilyId") : ""
368 def failIfExist = execution.getVariable("failIfExists") != null ? execution.getVariable("failIfExists") : ""
369 def suppressRollback = execution.getVariable("disableRollback")
370 def backoutOnFailure = ""
371 if(suppressRollback != null){
372 if (suppressRollback == true || suppressRollback == "true") {
373 backoutOnFailure = "false"
374 } else if (suppressRollback == false || suppressRollback == "'false") {
375 backoutOnFailure = "true"
379 //'sdncVersion' = current, '1610' (non-RPC SDNC) or '1702' (RPC SDNC)
380 def sdncVersion = execution.getVariable("sdncVersion")
383 def action = execution.getVariable("action")
385 def userParamsNode = ""
386 def userParams = execution.getVariable("networkInputParams")
387 if(userParams != null) {
388 userParamsNode = buildUserParams(userParams)
392 <network-request xmlns="http://www.w3.org/2001/XMLSchema">
394 <request-id>${requestId}</request-id>
395 <action>${action}</action>
396 <source>${source}</source>
397 <service-instance-id>${serviceInstanceId}</service-instance-id>
400 <network-id>${networkId}</network-id>
401 <network-name>${networkName}</network-name>
402 <network-type>${networkModelType}</network-type>
403 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
404 <global-customer-id>${globalSubscriberId}</global-customer-id>
405 <aic-cloud-region>${aicCloudReqion}</aic-cloud-region>
406 <tenant-id>${tenantId}</tenant-id>
407 <service-id>${serviceId}</service-id>
408 <backout-on-failure>${backoutOnFailure}</backout-on-failure>
409 <failIfExist>${failIfExist}</failIfExist>
411 <modelName>${networkModelName}</modelName>
412 <modelUuid>${networkModelVersionId}</modelUuid>
413 <modelInvariantUuid>${networkModelInvariantId}</modelInvariantUuid>
414 <modelVersion>${networkModelVersion}</modelVersion>
415 <modelCustomizationUuid>${networkModelCustomizationId}</modelCustomizationUuid>
416 <modelType>${networkModelType}</modelType>
419 <modelName>${serviceModelName}</modelName>
420 <modelUuid>${serviceModelVersionId}</modelUuid>
421 <modelInvariantUuid>${serviceModelInvariantId}</modelInvariantUuid>
422 <modelVersion>${serviceModelVersion}</modelVersion>
423 <modelCustomizationUuid>${serviceModelCustomizationId}</modelCustomizationUuid>
424 <modelType>${serviceModelType}</modelType>
426 <sdncVersion>${sdncVersion}</sdncVersion>
433 // return a pretty-print of the volume-request xml without the preamble
434 return groovy.xml.XmlUtil.serialize(xmlReq.normalize().replaceAll("\t", "").replaceAll("\n", "")).replaceAll("(<\\?[^<]*\\?>\\s*[\\r\\n]*)?", "")
439 * Create a vnf-request XML using a map
440 * @param requestMap - map created from VID JSON
444 public String createXmlVfModuleRequest(execution, Map requestMap, String action, String serviceInstanceId) {
446 //def relatedInstanceList = requestMap.requestDetails.relatedInstanceList
448 //relatedInstanceList.each {
449 // if (it.relatedInstance.modelInfo.modelType == 'vnf') {
450 // vnfType = it.relatedInstance.modelInfo.modelName
451 // vnfId = it.relatedInstance.modelInfo.modelInvariantId
456 def asdcServiceModelInfo = ''
458 def relatedInstanceList = requestMap.requestDetails?.relatedInstanceList
461 if (relatedInstanceList != null) {
462 relatedInstanceList.each {
463 if (it.relatedInstance.modelInfo?.modelType == 'service') {
464 asdcServiceModelInfo = it.relatedInstance.modelInfo?.modelVersion
466 if (it.relatedInstance.modelInfo.modelType == 'vnf') {
467 vnfName = it.relatedInstance.instanceName ?: ''
472 def vnfType = execution.getVariable('vnfType')
473 def vnfId = execution.getVariable('vnfId')
475 def vfModuleId = execution.getVariable('vfModuleId')
476 def volumeGroupId = execution.getVariable('volumeGroupId')
477 def userParams = requestMap.requestDetails?.requestParameters?.userParams
480 def userParamsNode = ''
481 if(userParams != null) {
482 userParamsNode = buildUserParams(userParams)
485 def isBaseVfModule = "false"
486 if (execution.getVariable('isBaseVfModule') == true) {
487 isBaseVfModule = "true"
490 def requestId = execution.getVariable("mso-request-id")
491 def vfModuleName = requestMap.requestDetails?.requestInfo?.instanceName ?: ''
492 def vfModuleModelName = requestMap.requestDetails?.modelInfo?.modelName ?: ''
493 def suppressRollback = requestMap.requestDetails?.requestInfo?.suppressRollback
495 def backoutOnFailure = ""
496 if(suppressRollback != null){
497 if ( suppressRollback == true) {
498 backoutOnFailure = "false"
499 } else if ( suppressRollback == false) {
500 backoutOnFailure = "true"
504 def serviceId = requestMap.requestDetails?.requestParameters?.serviceId ?: ''
505 def aicCloudRegion = requestMap.requestDetails?.cloudConfiguration?.lcpCloudRegionId ?: ''
506 def tenantId = requestMap.requestDetails?.cloudConfiguration?.tenantId ?: ''
507 def personaModelId = requestMap.requestDetails?.modelInfo?.modelInvariantId ?: ''
508 def personaModelVersion = requestMap.requestDetails?.modelInfo?.modelVersion ?: ''
509 def modelCustomizationId = requestMap.requestDetails?.modelInfo?.modelCustomizationId ?: ''
514 <request-id>${requestId}</request-id>
515 <action>${action}</action>
517 <!-- new 1610 field -->
518 <service-instance-id>${serviceInstanceId}</service-instance-id>
521 <!-- not in use in 1610 -->
522 <vnf-name>${vnfName}</vnf-name>
523 <vnf-type>${vnfType}</vnf-type>
524 <vnf-id>${vnfId}</vnf-id>
525 <volume-group-id>${volumeGroupId}</volume-group-id>
526 <vf-module-id>${vfModuleId}</vf-module-id>
527 <vf-module-name>${vfModuleName}</vf-module-name>
528 <vf-module-model-name>${vfModuleModelName}</vf-module-model-name>
529 <model-customization-id>${modelCustomizationId}</model-customization-id>
530 <is-base-vf-module>${isBaseVfModule}</is-base-vf-module>
531 <asdc-service-model-version>${asdcServiceModelInfo}</asdc-service-model-version>
532 <aic-cloud-region>${aicCloudRegion}</aic-cloud-region>
533 <tenant-id>${tenantId}</tenant-id>
534 <service-id>${serviceId}</service-id>
535 <backout-on-failure>${backoutOnFailure}</backout-on-failure>
536 <persona-model-id>${personaModelId}</persona-model-id>
537 <persona-model-version>${personaModelVersion}</persona-model-version>
545 // return a pretty-print of the volume-request xml without the preamble
546 return groovy.xml.XmlUtil.serialize(xmlReq.normalize().replaceAll("\t", "").replaceAll("\n", "")).replaceAll("(<\\?[^<]*\\?>\\s*[\\r\\n]*)?", "")