Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import * as _ from 'lodash' |
| 2 | |
| 3 | export class Utils { |
| 4 | |
Yoav Schneiderman | 1f2a294 | 2019-12-09 16:42:21 +0200 | [diff] [blame] | 5 | static getMaxFirstLevel(properties, flags: { [key: string]: boolean }) : number | null{ |
Eylon Malin | 0b4cdc4 | 2019-12-11 08:11:02 +0200 | [diff] [blame] | 6 | return this.getMaxInstancesAllowed(properties, 'max_instances', flags) |
| 7 | } |
| 8 | |
| 9 | static getMaxVfModule(properties, flags: { [key: string]: boolean }) : number | null{ |
| 10 | return this.getMaxInstancesAllowed(properties, 'maxCountInstances', flags) |
| 11 | } |
| 12 | |
| 13 | static getMaxInstancesAllowed(properties, filedName: string, flags: { [key: string]: boolean }) : number | null{ |
| 14 | if (!_.isNil(properties) && !_.isNil(properties[filedName])) { |
| 15 | return properties[filedName]; |
Yoav Schneiderman | 1f2a294 | 2019-12-09 16:42:21 +0200 | [diff] [blame] | 16 | } |
Eylon Malin | 0b4cdc4 | 2019-12-11 08:11:02 +0200 | [diff] [blame] | 17 | return (flags && !!flags['FLAG_2002_UNLIMITED_MAX']) ? null : 1; |
Yoav Schneiderman | 1f2a294 | 2019-12-09 16:42:21 +0200 | [diff] [blame] | 18 | } |
| 19 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 20 | public static clampNumber = (number, min, max) => { |
| 21 | return Math.max(min, Math.min(number, max)); |
| 22 | }; |
| 23 | |
| 24 | public static hasContents(object: Object): boolean { |
| 25 | if (object === undefined || object === null || object === "") { |
| 26 | return false; |
| 27 | } |
| 28 | return true; |
| 29 | }; |
| 30 | |
| 31 | public static convertModel(serviceModel) { |
| 32 | |
| 33 | let isNewFlow:boolean = false; |
| 34 | |
| 35 | for (let networkCustomizationName in serviceModel.networks) { |
| 36 | let networkModel = serviceModel.networks[networkCustomizationName]; |
| 37 | if ( networkModel.customizationUuid != null ) { |
| 38 | isNewFlow = true; |
| 39 | break; |
| 40 | } |
| 41 | } |
| 42 | if ( !isNewFlow ) { |
| 43 | for (let vnfCustomizationName in serviceModel.vnfs) { |
| 44 | let vnfModel = serviceModel.vnfs[vnfCustomizationName]; |
| 45 | if ( vnfModel.customizationUuid != null ) { |
| 46 | isNewFlow = true; |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | if ( isNewFlow ) { |
| 52 | return (Utils.convertNewModel (serviceModel) ); |
| 53 | } |
| 54 | else { |
| 55 | return (Utils.convertOldModel (serviceModel) ); |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | private static convertNewModel (serviceModel ) { |
| 60 | let completeResources = new Array(); |
| 61 | let resource = {}; |
| 62 | let convertedAsdcModel = { |
| 63 | "service": serviceModel.service, |
| 64 | "networks": {}, |
| 65 | "vnfs": {}, |
| 66 | "pnfs": serviceModel.pnfs, |
| 67 | "serviceProxies": serviceModel.serviceProxies, |
| 68 | "completeDisplayInputs": {}, |
| 69 | "isNewFlow": true |
| 70 | }; |
| 71 | |
| 72 | for(let key in serviceModel.service.inputs) { |
| 73 | if(_.includes(["instance_node_target", "naming_policy", "vf_instance_name"], key)) { |
| 74 | delete convertedAsdcModel.service.inputs[key]; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | for (let networkCustomizationName in serviceModel.networks) { |
| 79 | let networkModel = serviceModel.networks[networkCustomizationName]; |
| 80 | |
| 81 | convertedAsdcModel.networks[networkModel.customizationUuid] = { |
| 82 | "uuid": networkModel.uuid, |
| 83 | "invariantUuid": networkModel.invariantUuid, |
| 84 | "version": networkModel.version, |
| 85 | "name": networkModel.name, |
| 86 | "modelCustomizationName": networkModel.modelCustomizationName, |
| 87 | "customizationUuid": networkModel.customizationUuid, |
| 88 | "inputs": "", |
| 89 | "description": networkModel.description, |
| 90 | "commands": {}, |
| 91 | "displayInputs": {} |
| 92 | }; |
| 93 | |
| 94 | resource = { |
| 95 | "name": networkModel.modelCustomizationName, |
| 96 | "description": networkModel.description |
| 97 | }; |
| 98 | |
| 99 | completeResources.push (resource); |
| 100 | |
| 101 | } |
| 102 | |
| 103 | _.forEach(serviceModel.configurations, function(element) { |
| 104 | element.isConfig = true; |
| 105 | }); |
| 106 | _.forEach(serviceModel.pnfs, function(element, key) { |
| 107 | element.isPnf= true; |
| 108 | element.modelCustomizationName= key; |
| 109 | }); |
| 110 | let mergedVnfs = Object.assign(serviceModel.vnfs, serviceModel.configurations, serviceModel.pnfs); |
| 111 | |
| 112 | for (let vnfCustomizationName in mergedVnfs) { |
| 113 | let vnfModel = mergedVnfs[vnfCustomizationName]; |
| 114 | let vnfCustomizationUuid = vnfModel.customizationUuid; |
| 115 | convertedAsdcModel.vnfs[vnfModel.customizationUuid] = { |
| 116 | "uuid": vnfModel.uuid, |
| 117 | "invariantUuid": vnfModel.invariantUuid, |
| 118 | "version": vnfModel.version, |
| 119 | "name": vnfModel.name, |
| 120 | "modelCustomizationName": vnfModel.modelCustomizationName, |
| 121 | "customizationUuid": vnfModel.customizationUuid, |
| 122 | "inputs": "", |
| 123 | "description": vnfModel.description, |
| 124 | "vfModules": {}, |
| 125 | "volumeGroups": {}, |
| 126 | "commands": {}, |
| 127 | "displayInputs": {}, |
| 128 | "properties": {}, |
| 129 | "nfRole": "", |
| 130 | "nfType": "", |
| 131 | "sourceNodes": vnfModel.sourceNodes, |
| 132 | "collectorNodes": vnfModel.collectorNodes, |
| 133 | "isConfigurationByPolicy": vnfModel.configurationByPolicy ? vnfModel.configurationByPolicy : false, |
| 134 | "isConfig": vnfModel.isConfig ? vnfModel.isConfig : false, |
| 135 | "isPnf": vnfModel.isPnf ? vnfModel.isPnf : false |
| 136 | }; |
| 137 | |
| 138 | resource = { |
| 139 | "name": vnfModel.modelCustomizationName, |
| 140 | "description": vnfModel.description |
| 141 | }; |
| 142 | completeResources.push (resource); |
| 143 | |
| 144 | if (vnfModel.commands != null) { |
| 145 | /* |
| 146 | * commands: { |
| 147 | * internal_net_param_ntu: { |
| 148 | * command: get_input, |
| 149 | * displaName: internal_net_param_ntu, |
| 150 | * inputName: vccfd1_internal_net_param_ntu // pointer to input key |
| 151 | * } |
| 152 | * If the input name (ptr) is one of instance_node_target, naming_policy or vf_instance_name |
| 153 | * then ignore it |
| 154 | * |
| 155 | */ |
| 156 | |
| 157 | convertedAsdcModel.vnfs[vnfCustomizationUuid].properties=vnfModel.properties; |
| 158 | // |
| 159 | let vnf_type = ""; |
| 160 | let vnf_role = ""; |
| 161 | let vnf_function = ""; |
| 162 | let vnf_code = ""; |
| 163 | if ( !( _.isEmpty(vnfModel.properties) ) ) { |
| 164 | if (this.hasContents (vnfModel.properties.nf_type) ) { |
| 165 | vnf_type = vnfModel.properties.nf_type; |
| 166 | } |
| 167 | if (this.hasContents (vnfModel.properties.nf_role) ) { |
| 168 | vnf_role = vnfModel.properties.nf_role; |
| 169 | } |
| 170 | if (this.hasContents (vnfModel.properties.nf_function) ) { |
| 171 | vnf_function = vnfModel.properties.nf_function; |
| 172 | } |
| 173 | if (this.hasContents (vnfModel.properties.nf_naming_code) ) { |
| 174 | vnf_code = vnfModel.properties.nf_naming_code; |
| 175 | } |
| 176 | } |
| 177 | convertedAsdcModel.vnfs[vnfCustomizationUuid]["nfType"] = vnf_type; |
| 178 | convertedAsdcModel.vnfs[vnfCustomizationUuid]["nfRole"] = vnf_role; |
| 179 | convertedAsdcModel.vnfs[vnfCustomizationUuid]["nfFunction"] = vnf_function; |
| 180 | convertedAsdcModel.vnfs[vnfCustomizationUuid]["nfCode"] = vnf_code; |
| 181 | // |
| 182 | for (let vfModuleCustomizationName in serviceModel.vnfs[vnfCustomizationName].vfModules) { |
| 183 | let vfModuleModel = serviceModel.vnfs[vnfCustomizationName].vfModules[vfModuleCustomizationName]; |
| 184 | convertedAsdcModel.vnfs[vnfCustomizationUuid].vfModules[vfModuleModel.customizationUuid] = vfModuleModel; |
| 185 | } |
| 186 | |
| 187 | for (let volumeGroupCustomizationName in serviceModel.vnfs[vnfCustomizationName].volumeGroups) { |
| 188 | let volumeGroupModel = serviceModel.vnfs[vnfCustomizationName].volumeGroups[volumeGroupCustomizationName]; |
| 189 | convertedAsdcModel.vnfs[vnfCustomizationUuid].volumeGroups[volumeGroupModel.customizationUuid] = volumeGroupModel; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return (convertedAsdcModel); |
| 195 | }; |
| 196 | |
Eylon Malin | 6225ebb | 2019-11-20 10:41:18 +0200 | [diff] [blame] | 197 | public static isALaCarte(instantiationType) { |
| 198 | return instantiationType !== 'Macro'; |
| 199 | } |
| 200 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 201 | private static convertOldModel(serviceModel ) { |
| 202 | let resource = {}; |
| 203 | let convertedAsdcModel = { |
| 204 | "service": serviceModel.service, |
| 205 | "networks": {}, |
| 206 | "vnfs": {}, |
| 207 | "pnfs": serviceModel.pnfs, |
| 208 | "serviceProxies": serviceModel.serviceProxies, |
| 209 | "completeDisplayInputs": {}, |
| 210 | "isNewFlow": false |
| 211 | }; |
| 212 | let completeResources = new Array(); |
| 213 | for (let networkCustomizationName in serviceModel.networks) { |
| 214 | let networkModel = serviceModel.networks[networkCustomizationName]; |
| 215 | convertedAsdcModel.networks[networkModel.invariantUuid] = {}; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 216 | convertedAsdcModel.networks[networkModel.uuid] = { |
| 217 | "uuid": networkModel.uuid, |
| 218 | "invariantUuid": networkModel.invariantUuid, |
| 219 | "version": networkModel.version, |
| 220 | "name": networkModel.name, |
| 221 | "modelCustomizationName": networkModel.modelCustomizationName, |
| 222 | "customizationUuid": networkModel.customizationUuid, |
| 223 | "inputs": "", |
| 224 | "description": networkModel.description, |
| 225 | "commands": {}, |
| 226 | "displayInputs": {} |
| 227 | }; |
| 228 | resource = { |
| 229 | "name": networkModel.modelCustomizationName, |
| 230 | "description": networkModel.description |
| 231 | }; |
| 232 | completeResources.push (resource); |
| 233 | } |
| 234 | |
| 235 | _.forEach(serviceModel.configurations, function(element) { |
| 236 | element.isConfig = true; |
| 237 | }); |
| 238 | _.forEach(serviceModel.pnfs, function(element, key) { |
| 239 | element.isPnf= true; |
| 240 | element.modelCustomizationName= key; |
| 241 | }); |
| 242 | let mergedVnfs = Object.assign(serviceModel.vnfs, serviceModel.configurations, serviceModel.pnfs); |
| 243 | |
| 244 | for (let vnfCustomizationName in mergedVnfs) { |
| 245 | let vnfModel = mergedVnfs[vnfCustomizationName]; |
| 246 | convertedAsdcModel.vnfs[vnfModel.uuid] = { |
| 247 | "uuid": vnfModel.uuid, |
| 248 | "invariantUuid": vnfModel.invariantUuid, |
| 249 | "version": vnfModel.version, |
| 250 | "name": vnfModel.name, |
| 251 | "modelCustomizationName": vnfModel.modelCustomizationName, |
| 252 | "customizationUuid": vnfModel.customizationUuid, |
| 253 | "inputs": "", |
| 254 | "description": vnfModel.description, |
| 255 | "vfModules": {}, |
| 256 | "volumeGroups": {}, |
| 257 | "commands": {}, |
| 258 | "displayInputs": {}, |
| 259 | "sourceNodes": vnfModel.sourceNodes, |
| 260 | "collectorNodes": vnfModel.collectorNodes, |
| 261 | "isConfigurationByPolicy": vnfModel.configurationByPolicy ? vnfModel.configurationByPolicy : false, |
| 262 | "isConfig": vnfModel.isConfig ? vnfModel.isConfig : false, |
| 263 | "isPnf": vnfModel.isPnf ? vnfModel.isPnf : false |
| 264 | }; |
| 265 | resource = { |
| 266 | "name": vnfModel.modelCustomizationName, |
| 267 | "description": vnfModel.description |
| 268 | }; |
| 269 | completeResources.push (resource); |
| 270 | |
| 271 | for (let vfModuleCustomizationName in serviceModel.vnfs[vnfCustomizationName].vfModules) { |
| 272 | let vfModuleModel = serviceModel.vnfs[vnfCustomizationName].vfModules[vfModuleCustomizationName]; |
| 273 | convertedAsdcModel.vnfs[vnfModel.uuid].vfModules[vfModuleModel.uuid] = vfModuleModel; |
| 274 | } |
| 275 | |
| 276 | for (let volumeGroupCustomizationName in serviceModel.vnfs[vnfCustomizationName].volumeGroups) { |
| 277 | let volumeGroupModel = serviceModel.vnfs[vnfCustomizationName].volumeGroups[volumeGroupCustomizationName]; |
| 278 | convertedAsdcModel.vnfs[vnfModel.uuid].volumeGroups[volumeGroupModel.uuid] = volumeGroupModel; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | let completeDisplayInputs = {}; |
| 283 | |
| 284 | return (convertedAsdcModel); |
| 285 | }; |
| 286 | } |