Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {Injectable} from "@angular/core"; |
| 2 | import {NgRedux} from "@angular-redux/store"; |
| 3 | import {AppState} from "../../../shared/store/reducers"; |
| 4 | import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions"; |
| 5 | import {MessageBoxData} from "../../../shared/components/messageBox/messageBox.data"; |
| 6 | import {MessageBoxService} from "../../../shared/components/messageBox/messageBox.service"; |
| 7 | import * as _ from "lodash"; |
| 8 | import {DrawingBoardModes} from "../drawing-board.modes"; |
| 9 | import {AuditInfoModalComponent} from "../../../shared/components/auditInfoModal/auditInfoModal.component"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 10 | import {ILevelNodeInfo} from "./models/basic.model.info"; |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 11 | import {ComponentInfoModel, ComponentInfoType} from "../component-info/component-info-model"; |
| 12 | import {ModelInformationItem} from "../../../shared/components/model-information/model-information.component"; |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame] | 13 | import {undoUpgradeService, upgradeService} from "../../../shared/storeUtil/utils/service/service.actions"; |
| 14 | import {VNFMethods} from "../../../shared/storeUtil/utils/vnf/vnf.actions"; |
| 15 | import {FeatureFlagsService, Features} from "../../../shared/services/featureFlag/feature-flags.service"; |
Yoav Schneiderman | 1f2a294 | 2019-12-09 16:42:21 +0200 | [diff] [blame] | 16 | import {Utils} from "../../../shared/utils/utils"; |
Eylon Malin | 0a26826 | 2019-12-15 10:03:03 +0200 | [diff] [blame] | 17 | import {Constants} from "../../../shared/utils/constants"; |
Ittay Stern | 18c3ce8 | 2019-12-26 15:21:17 +0200 | [diff] [blame] | 18 | import {NodeInstance} from "../../../shared/models/nodeInstance"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 19 | |
| 20 | @Injectable() |
| 21 | export class SharedTreeService { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 22 | constructor(private _store: NgRedux<AppState>) { |
| 23 | } |
| 24 | |
| 25 | /*********************************************************** |
| 26 | * return if instance has missing data |
| 27 | * @param instance - vnf instance |
| 28 | * @param dynamicInputs - from the instance |
| 29 | * @param isEcompGeneratedNaming |
| 30 | ************************************************************/ |
| 31 | selectedVNF: string = null; |
| 32 | |
| 33 | |
| 34 | getSelectedVNF(): string { |
| 35 | return this.selectedVNF; |
| 36 | } |
| 37 | |
| 38 | setSelectedVNF(node): void { |
| 39 | if (_.isNil(node) || node.data.type !== 'VF') { |
| 40 | this.selectedVNF = null; |
| 41 | } else { |
| 42 | this.selectedVNF = node.data.vnfStoreKey; |
| 43 | } |
| 44 | } |
| 45 | |
Ittay Stern | 18c3ce8 | 2019-12-26 15:21:17 +0200 | [diff] [blame] | 46 | /** |
| 47 | * Determines a consistent unique ID for a given right-tree |
| 48 | * node instance. |
| 49 | */ |
| 50 | modelUniqueId = (nodeInstance: NodeInstance): string => { |
| 51 | return _.isNil(nodeInstance.modelInfo) |
| 52 | ? null |
| 53 | : (nodeInstance.modelInfo.modelCustomizationId || nodeInstance.modelInfo.modelInvariantId); |
| 54 | }; |
| 55 | |
Ittay Stern | f84164f | 2020-02-04 14:13:24 +0200 | [diff] [blame] | 56 | modelUniqueNameOrId = (instance): string => { |
| 57 | if (_.isNil(instance)) { |
| 58 | return null; |
| 59 | } |
| 60 | |
| 61 | const innerInstance = _.find(instance) || {}; |
| 62 | |
| 63 | return instance.originalName |
| 64 | || this.modelUniqueId(instance) |
| 65 | || innerInstance.originalName |
| 66 | || this.modelUniqueId(innerInstance); |
| 67 | }; |
Ittay Stern | 74e6271 | 2020-01-29 18:20:23 +0200 | [diff] [blame] | 68 | |
Ittay Stern | 6b1e53d | 2020-01-21 12:20:37 +0200 | [diff] [blame] | 69 | /** |
| 70 | * Finds a model inside a full service model |
| 71 | * @param serviceModelFromHierarchy |
| 72 | * @param modelTypeName "vnfs" | "networks" | "vfModules" | "collectionResources" | ... |
Ittay Stern | 74e6271 | 2020-01-29 18:20:23 +0200 | [diff] [blame] | 73 | * @param modelUniqueNameOrId Either an entry name (i.e. "originalName"), modelCustomizationId or modelInvariantId. |
Ittay Stern | 6b1e53d | 2020-01-21 12:20:37 +0200 | [diff] [blame] | 74 | * Note that modelInvariantId will work only where model lacks a modelCustomizationId. |
Ittay Stern | 0814238 | 2020-02-02 18:09:40 +0200 | [diff] [blame] | 75 | * @param modelName An optional entry name (i.e. "originalName"); will not try to use as id |
Ittay Stern | 6b1e53d | 2020-01-21 12:20:37 +0200 | [diff] [blame] | 76 | */ |
Ittay Stern | 0814238 | 2020-02-02 18:09:40 +0200 | [diff] [blame] | 77 | modelByIdentifiers = (serviceModelFromHierarchy, modelTypeName: string, modelUniqueNameOrId: string, modelName?: string): any => { |
Ittay Stern | 74e6271 | 2020-01-29 18:20:23 +0200 | [diff] [blame] | 78 | const logErrorAndReturnUndefined = () => |
| 79 | console.info(`modelByIdentifiers: could not find a model matching query`, { |
Ittay Stern | 0814238 | 2020-02-02 18:09:40 +0200 | [diff] [blame] | 80 | modelTypeName, modelUniqueNameOrId, modelName, serviceModelFromHierarchy |
Ittay Stern | 74e6271 | 2020-01-29 18:20:23 +0200 | [diff] [blame] | 81 | }); |
| 82 | |
| 83 | if (_.isNil(serviceModelFromHierarchy)) return logErrorAndReturnUndefined(); |
Ittay Stern | 6b1e53d | 2020-01-21 12:20:37 +0200 | [diff] [blame] | 84 | |
| 85 | const modelsOfType = serviceModelFromHierarchy[modelTypeName]; |
Ittay Stern | 74e6271 | 2020-01-29 18:20:23 +0200 | [diff] [blame] | 86 | if (_.isNil(modelsOfType)) return logErrorAndReturnUndefined(); |
Ittay Stern | 6b1e53d | 2020-01-21 12:20:37 +0200 | [diff] [blame] | 87 | |
Ittay Stern | 74e6271 | 2020-01-29 18:20:23 +0200 | [diff] [blame] | 88 | const modelIfModelIdentifierIsEntryName = modelsOfType[modelUniqueNameOrId]; |
Ittay Stern | 0814238 | 2020-02-02 18:09:40 +0200 | [diff] [blame] | 89 | const modelIfModeNameExists = _.isNil(modelName) ? null : modelsOfType[modelName]; |
Ittay Stern | 74e6271 | 2020-01-29 18:20:23 +0200 | [diff] [blame] | 90 | |
| 91 | if (!_.isNil(modelIfModelIdentifierIsEntryName)) { |
| 92 | return modelIfModelIdentifierIsEntryName; |
| 93 | } else if (!_.isNil(modelIfModeNameExists)) { |
| 94 | return modelIfModeNameExists; |
| 95 | } else { |
| 96 | // try modelUniqueNameOrId as an id |
| 97 | return _.find(modelsOfType, o => (o.customizationUuid || o.invariantUuid) === modelUniqueNameOrId) || logErrorAndReturnUndefined() |
| 98 | } |
Ittay Stern | 6b1e53d | 2020-01-21 12:20:37 +0200 | [diff] [blame] | 99 | }; |
| 100 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 101 | hasMissingData(instance, dynamicInputs: any, isEcompGeneratedNaming: boolean, requiredFields: string[]): boolean { |
| 102 | if (!isEcompGeneratedNaming && _.isEmpty(instance.instanceName)) { |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | for (let field of requiredFields) { |
| 107 | if (_.isEmpty(instance[field])) { |
| 108 | return true; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | for (let field of dynamicInputs) { |
| 113 | if (field.isRequired && !_.isNil(instance.instanceParams) && _.isEmpty(instance.instanceParams[0][field.id])) { |
| 114 | return true; |
| 115 | } |
| 116 | } |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | addingStatusProperty(node) { |
| 122 | node['statusProperties'] = []; |
Alexey Sandler | a29c7c0 | 2020-03-31 22:40:10 +0300 | [diff] [blame] | 123 | node['statusProperties'].push({key: 'Prov Status: ', value: node.provStatus, testId: 'provStatus'}); |
| 124 | node['statusProperties'].push({key: 'Orch Status: ', value: node.orchStatus, testId: 'orchStatus'}); |
| 125 | if(node.type === 'VFmodule') { |
| 126 | node['statusProperties'].push({key: 'Model Version: ', value: this.getNodeModelVersion(node), testId: 'modelVersion'}); |
| 127 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 128 | if (node.inMaint) { |
| 129 | node['statusProperties'].push({key: 'In-maintenance', value: '', testId: 'inMaint'}); |
| 130 | } |
| 131 | return node; |
| 132 | } |
| 133 | |
Alexey Sandler | a29c7c0 | 2020-03-31 22:40:10 +0300 | [diff] [blame] | 134 | getNodeModelVersion(node): string | undefined { |
| 135 | if(!_.isNil(node.instanceModelInfo) && !_.isNil(node.instanceModelInfo.modelVersion)){ |
| 136 | return node.instanceModelInfo.modelVersion; |
| 137 | } |
| 138 | return undefined; |
| 139 | } |
| 140 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 141 | /********************************************** |
| 142 | * should delete or remove child instance's |
| 143 | "new" -> should remove |
| 144 | !new" -> should change action status |
| 145 | **********************************************/ |
| 146 | removeDeleteAllChild(node, serviceModelId: string, callback): void { |
| 147 | for (let nodeChild of node.children) { |
| 148 | if (nodeChild.data.action === ServiceInstanceActions.Create) { |
| 149 | if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['remove'])) { |
| 150 | nodeChild.data.menuActions['remove']['method'](nodeChild, serviceModelId); |
| 151 | } |
| 152 | } else { |
| 153 | if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['delete'])) { |
| 154 | nodeChild.data.menuActions['delete']['method'](nodeChild, serviceModelId); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | callback(node, serviceModelId); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /********************************************** |
| 163 | * should undo delete child instance's |
| 164 | **********************************************/ |
| 165 | undoDeleteAllChild(node, serviceModelId: string, callback): void { |
| 166 | for (let nodeChild of node.children) { |
| 167 | if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['undoDelete'])) { |
| 168 | nodeChild.data.menuActions['undoDelete']['method'](nodeChild, serviceModelId); |
| 169 | } |
| 170 | } |
| 171 | callback(node, serviceModelId); |
| 172 | } |
| 173 | |
| 174 | /********************************************** |
| 175 | * should return true if can delete |
| 176 | **********************************************/ |
Eylon Malin | aefc6a0 | 2020-01-29 15:11:47 +0200 | [diff] [blame] | 177 | shouldShowDelete(node, serviceModelId): boolean { |
| 178 | return this.shouldShowButtonGeneric(node, "delete", serviceModelId) |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /********************************************** |
| 182 | * should return true if can undo delete |
| 183 | **********************************************/ |
| 184 | shouldShowUndoDelete(node): boolean { |
| 185 | const mode = this._store.getState().global.drawingBoardStatus; |
| 186 | if (mode === DrawingBoardModes.EDIT && !_.isNil(node.data.action) && !_.isNil(node.data.menuActions['undoDelete'])) { |
| 187 | if (node.data.action === ServiceInstanceActions.Create || node.data.action === ServiceInstanceActions.Delete) { |
| 188 | return false; |
| 189 | } else if (node.data.action.split('_').pop() === 'Delete') { |
| 190 | return true |
| 191 | } |
| 192 | return false; |
| 193 | } |
| 194 | return false; |
| 195 | } |
| 196 | /********************************************** |
| 197 | * should return true if can remove or edit |
| 198 | * enabled only on edit/design mode and for new instances |
| 199 | **********************************************/ |
| 200 | shouldShowRemoveAndEdit(node): boolean { |
| 201 | const mode = this._store.getState().global.drawingBoardStatus; |
| 202 | if (!_.isNil(node) && !_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action === ServiceInstanceActions.Create && |
| 203 | mode !== DrawingBoardModes.VIEW && mode !== DrawingBoardModes.RETRY) { |
| 204 | return true; |
| 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | /********************************************** |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame] | 209 | * enabled only on edit/design |
| 210 | * enabled only if there's a newer version for VNF-M |
| 211 | **********************************************/ |
| 212 | upgradeBottomUp(node,serviceModelId: string): void { |
| 213 | this.iterateOverTreeBranchAndRunAction(node, serviceModelId, VNFMethods.UPGRADE); |
| 214 | this._store.dispatch(upgradeService(serviceModelId)); |
| 215 | } |
| 216 | |
| 217 | private iterateOverTreeBranchAndRunAction(node, serviceModelId: string, actionMethod) { |
| 218 | while (_.has(node.parent, 'data') && _.has(node.parent.data, 'menuActions') |
| 219 | && !_.isNil(node.parent.data.menuActions[actionMethod])) { |
| 220 | node = node.parent; |
| 221 | node.data.menuActions[actionMethod]['method'](node, serviceModelId); |
| 222 | } |
| 223 | } |
| 224 | |
Alexey Sandler | c8a3cff | 2020-05-06 18:58:14 +0300 | [diff] [blame^] | 225 | shouldShowPauseInstantiation(): boolean { |
| 226 | return (FeatureFlagsService.getFlagState(Features.FLAG_2006_PAUSE_VFMODULE_INSTANTIATION_CREATION, this._store)); |
| 227 | } |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame] | 228 | /**************************************************** |
| 229 | * should return true if customer can upgrade a VFM * |
| 230 | ****************************************************/ |
| 231 | shouldShowUpgrade(node, serviceModelId): boolean { |
Alexey Sandler | 5609338 | 2020-02-13 09:53:14 +0200 | [diff] [blame] | 232 | return (this.isVfMoudleCouldBeUpgraded(node, serviceModelId)) |
| 233 | && this.shouldShowButtonGeneric(node, VNFMethods.UPGRADE, serviceModelId) ; |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame] | 234 | } |
Alexey Sandler | 5609338 | 2020-02-13 09:53:14 +0200 | [diff] [blame] | 235 | |
| 236 | isVfMoudleCouldBeUpgraded(node, serviceModelId): boolean{ |
| 237 | return (FeatureFlagsService.getFlagState(Features.FLAG_FLASH_REPLACE_VF_MODULE, this._store) && |
Alexey Sandler | 32d65b8 | 2020-02-13 17:31:00 +0200 | [diff] [blame] | 238 | (this.isThereAnUpdatedLatestVersion(serviceModelId) || this.isVfModuleCustomizationIdNotExistsOnModel(node, serviceModelId))) |
| 239 | } |
| 240 | |
| 241 | isVfModuleCustomizationIdNotExistsOnModel(vfModuleNode, serviceModelId) { |
| 242 | |
| 243 | // prevent undefined |
| 244 | if (_.isNil(vfModuleNode.data) || _.isNil(vfModuleNode.data.modelCustomizationId)) { |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | let vfModulesHierarchyByGivenModelId = this._store.getState().service.serviceHierarchy[serviceModelId].vfModules; |
| 249 | return !_.some(vfModulesHierarchyByGivenModelId, vfmodel => vfmodel.customizationUuid === vfModuleNode.data.modelCustomizationId); |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame] | 250 | } |
| 251 | |
Yoav Schneiderman | a3e54c3 | 2020-02-02 20:00:00 +0200 | [diff] [blame] | 252 | |
Ittay Stern | f84164f | 2020-02-04 14:13:24 +0200 | [diff] [blame] | 253 | isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer(vfModuleNode, serviceModelId) : boolean { |
| 254 | /* |
| 255 | for `true`, should all: |
| 256 | 1. parent vnf found by model-mane |
| 257 | 2. vfmodule found by invariant |
| 258 | 3. vfmodule diff by customization |
| 259 | */ |
| 260 | |
| 261 | if (_.isNil(vfModuleNode.data)) { |
| 262 | return false; |
Yoav Schneiderman | a3e54c3 | 2020-02-02 20:00:00 +0200 | [diff] [blame] | 263 | } |
Ittay Stern | f84164f | 2020-02-04 14:13:24 +0200 | [diff] [blame] | 264 | |
| 265 | const vnfHierarchy = this.getParentVnfHierarchy(vfModuleNode, serviceModelId); |
| 266 | if (_.isNil(vnfHierarchy)) { |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | const vfModuleHierarchyByInvariantId = this.getVfModuleHFromVnfHierarchyByInvariantId(vfModuleNode, vnfHierarchy); |
| 271 | if(_.isNil(vfModuleHierarchyByInvariantId)){ |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | return vfModuleHierarchyByInvariantId.customizationUuid |
| 276 | && (vfModuleHierarchyByInvariantId.customizationUuid !== vfModuleNode.data.modelCustomizationId); |
Yoav Schneiderman | a3e54c3 | 2020-02-02 20:00:00 +0200 | [diff] [blame] | 277 | } |
| 278 | |
Ittay Stern | f84164f | 2020-02-04 14:13:24 +0200 | [diff] [blame] | 279 | getParentVnfHierarchy(vfModuleNode, serviceModelId) { |
| 280 | if (vfModuleNode.parent && vfModuleNode.parent.data) { |
| 281 | return this._store.getState().service.serviceHierarchy[serviceModelId].vnfs[vfModuleNode.parent.data.modelName]; |
| 282 | } else { |
| 283 | return null; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | getVfModuleHFromVnfHierarchyByInvariantId(vfModuleNode, parentVnfHierarchy) { |
| 288 | if(vfModuleNode.data.modelInvariantId && parentVnfHierarchy && parentVnfHierarchy.vfModules){ |
| 289 | return _.find(parentVnfHierarchy.vfModules, o => o.invariantUuid === vfModuleNode.data.modelInvariantId); |
Yoav Schneiderman | a3e54c3 | 2020-02-02 20:00:00 +0200 | [diff] [blame] | 290 | } |
| 291 | return null; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | isThereAnUpdatedLatestVersion(serviceModelId) : boolean{ |
Eylon Malin | aefc6a0 | 2020-01-29 15:11:47 +0200 | [diff] [blame] | 296 | let serviceInstance = this.getServiceInstance(serviceModelId); |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame] | 297 | return !_.isNil(serviceInstance.latestAvailableVersion) && (Number(serviceInstance.modelInfo.modelVersion) < serviceInstance.latestAvailableVersion); |
| 298 | } |
| 299 | |
Eylon Malin | aefc6a0 | 2020-01-29 15:11:47 +0200 | [diff] [blame] | 300 | private getServiceInstance(serviceModelId): any { |
| 301 | return this._store.getState().service.serviceInstance[serviceModelId]; |
| 302 | } |
| 303 | |
| 304 | shouldShowButtonGeneric(node, method, serviceModelId) { |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame] | 305 | const mode = this._store.getState().global.drawingBoardStatus; |
Eylon Malin | aefc6a0 | 2020-01-29 15:11:47 +0200 | [diff] [blame] | 306 | const isMacro = !(this.getServiceInstance(serviceModelId).isALaCarte); |
| 307 | |
| 308 | if (isMacro) { //if macro action allowed only for service level |
| 309 | return false; |
| 310 | } |
| 311 | |
Einat Vinouze | e1f7974 | 2019-08-27 16:01:01 +0300 | [diff] [blame] | 312 | if (!_.isNil(node) && !_.isNil(node.data) && !_.isNil(node.data.action) && !_.isNil(node.data.menuActions[method])) { |
| 313 | if (mode !== DrawingBoardModes.EDIT || node.data.action === ServiceInstanceActions.Create) { |
| 314 | return false; |
| 315 | } |
| 316 | else if (node.data.action === ServiceInstanceActions.None) { |
| 317 | return true |
| 318 | } |
| 319 | } |
| 320 | return false; |
| 321 | } |
| 322 | |
| 323 | /********************************************** |
| 324 | * return boolean according to |
| 325 | * current defined action of VFModule node |
| 326 | **********************************************/ |
| 327 | shouldShowUndoUpgrade(node): boolean { |
| 328 | const mode = this._store.getState().global.drawingBoardStatus; |
| 329 | if (mode === DrawingBoardModes.EDIT && !_.isNil(node.data.action) && !_.isNil(node.data.menuActions[VNFMethods.UNDO_UPGRADE])) { |
| 330 | if (node.data.action === ServiceInstanceActions.Upgrade) { |
| 331 | return false; |
| 332 | } else if (node.data.action.split('_').pop() === ServiceInstanceActions.Upgrade) { |
| 333 | return true |
| 334 | } |
| 335 | return false; |
| 336 | } |
| 337 | return false; |
| 338 | } |
| 339 | /********************************************** |
| 340 | * enabled only on edit/design |
| 341 | * enabled only if there's a newer version for VNF-M |
| 342 | **********************************************/ |
| 343 | undoUpgradeBottomUp(node,serviceModelId: string): void { |
| 344 | this.iterateOverTreeBranchAndRunAction(node, serviceModelId, VNFMethods.UNDO_UPGRADE); |
| 345 | this._store.dispatch(undoUpgradeService(serviceModelId)); |
| 346 | } |
| 347 | /********************************************** |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 348 | * should return true if can duplicate by mode |
| 349 | **********************************************/ |
| 350 | shouldShowDuplicate(node): boolean { |
| 351 | const mode = this._store.getState().global.drawingBoardStatus; |
| 352 | return !mode.includes('RETRY'); |
| 353 | } |
| 354 | |
| 355 | /********************************************** |
| 356 | * should return true if can audit info |
| 357 | **********************************************/ |
| 358 | shouldShowAuditInfo(node): boolean { |
| 359 | return this.isRetryMode() || (!_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action !== ServiceInstanceActions.Create); |
| 360 | } |
| 361 | |
| 362 | |
| 363 | isRetryMode(): boolean { |
| 364 | const mode = this._store.getState().global.drawingBoardStatus; |
| 365 | return mode.includes('RETRY'); |
| 366 | } |
| 367 | |
| 368 | |
| 369 | /********************************************** |
| 370 | * should return true if can add node instances |
| 371 | **********************************************/ |
| 372 | shouldShowAddIcon(): boolean{ |
| 373 | const mode = this._store.getState().global.drawingBoardStatus; |
Ittay Stern | 18c3ce8 | 2019-12-26 15:21:17 +0200 | [diff] [blame] | 374 | return mode === DrawingBoardModes.EDIT || mode=== DrawingBoardModes.CREATE || mode=== DrawingBoardModes.RECREATE; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 375 | } |
Yoav Schneiderman | 1f2a294 | 2019-12-09 16:42:21 +0200 | [diff] [blame] | 376 | |
| 377 | |
| 378 | isReachedToMaxInstances(properties, counter, flags): boolean{ |
| 379 | let maxInstances = Utils.getMaxFirstLevel(properties, flags); |
| 380 | if(_.isNil(maxInstances)){ |
| 381 | return false; |
| 382 | }else { |
| 383 | return !(maxInstances > counter); |
| 384 | } |
| 385 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 386 | /************************************************ |
| 387 | return number of instances with action Delete |
| 388 | @type: vnfs networks, vngGroups (not vfModule) |
| 389 | @node : node model from the left tree |
| 390 | ************************************************/ |
| 391 | getExistingInstancesWithDeleteMode(node, serviceModelId: string, type: string): number { |
| 392 | let counter = 0; |
Eylon Malin | aefc6a0 | 2020-01-29 15:11:47 +0200 | [diff] [blame] | 393 | const existingInstances = this.getServiceInstance(serviceModelId)[type]; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 394 | const modelUniqueId = node.data.modelUniqueId; |
| 395 | if (!_.isNil(existingInstances)) { |
| 396 | for (let instanceKey in existingInstances) { |
| 397 | if (!_.isNil(existingInstances[instanceKey].action)) { |
| 398 | if (existingInstances[instanceKey].modelInfo.modelUniqueId === modelUniqueId && existingInstances[instanceKey].action.split('_').pop() === 'Delete') { |
| 399 | counter++; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | return counter; |
| 405 | } |
| 406 | |
| 407 | |
| 408 | isServiceOnDeleteMode(serviceId: string): boolean { |
| 409 | return this._store.getState().service.serviceInstance[serviceId].action === ServiceInstanceActions.Delete; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | openModal(node : any | any[] , serviceModelId : string, cb : Function) : void { |
| 414 | let type: string = _.isArray(node) ? 'Service' : node.data.typeName; |
| 415 | let messageBoxData: MessageBoxData = new MessageBoxData( |
| 416 | "Mark for Delete", |
| 417 | `You are about to mark for delete this ${type} this will also mark all its children and remove all new instances just added`, |
| 418 | <any>"warning", |
| 419 | <any>"md", |
| 420 | [ |
| 421 | { |
| 422 | text: "Mark and remove", |
| 423 | size: "large", |
| 424 | callback: cb.bind(this, node, serviceModelId), |
| 425 | closeModal: true |
| 426 | }, |
| 427 | {text: "Don’t Remove", size: "medium", closeModal: true} |
| 428 | ]); |
| 429 | |
| 430 | MessageBoxService.openModal.next(messageBoxData); |
| 431 | } |
| 432 | |
| 433 | someChildHasCreateAction(nodes: any | any[]) : boolean { |
| 434 | let nodesArr = _.isArray(nodes) ? nodes : [nodes]; |
| 435 | for(const node of nodesArr){ |
| 436 | if(node.action === ServiceInstanceActions.Create) {return true;} |
| 437 | if(node.children){ |
| 438 | for (let nodeChild of node.children) { |
| 439 | if (nodeChild.action === ServiceInstanceActions.Create) { |
| 440 | return true; |
| 441 | } |
| 442 | if(nodeChild.children && nodeChild.children.length > 0){ |
| 443 | for(let child of nodeChild.children){ |
| 444 | let hasCreateAction = this.someChildHasCreateAction(child); |
| 445 | if(hasCreateAction) { |
| 446 | return true; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | shouldShowDeleteInstanceWithChildrenModal(node : any | any[] , serviceModelId : string, cb : Function) : void { |
| 457 | if(this.someChildHasCreateAction(node)){ |
| 458 | this.openModal(node , serviceModelId, cb); |
| 459 | }else { |
| 460 | cb(node, serviceModelId) |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | |
| 465 | isFailed(node): boolean { |
| 466 | return !_.isNil(node.data) ? node.data.isFailed : false; |
| 467 | } |
| 468 | |
| 469 | /************************************************ |
| 470 | in a case the node is failed e.g. not instantiated correctly |
| 471 | the function will call to openRetryInstanceAuditInfoModal |
| 472 | @node : node model from the left tree |
| 473 | @serviceModelId : serviceModelId |
| 474 | @instance : instance |
| 475 | @instanceType: instanceType |
| 476 | @modelInfoService : the model (vnf, vfmodule, network, vnfgroup)object that call to the function (this) |
| 477 | ************************************************/ |
| 478 | openAuditInfoModal(node, serviceModelId, instance, instanceType, modelInfoService : ILevelNodeInfo){ |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 479 | AuditInfoModalComponent.openInstanceAuditInfoModal.next({ |
| 480 | instanceId: serviceModelId, |
| 481 | type: instanceType, |
Ittay Stern | 0814238 | 2020-02-02 18:09:40 +0200 | [diff] [blame] | 482 | model: modelInfoService.getModel( |
| 483 | this.modelByIdentifiers( |
| 484 | this._store.getState().service.serviceHierarchy[serviceModelId], |
| 485 | modelInfoService.name, |
| 486 | this.modelUniqueNameOrId(instance), node.data.modelName |
| 487 | ) |
| 488 | ), |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 489 | instance |
| 490 | }); |
| 491 | } |
| 492 | |
Alexey Sandler | 4e32415 | 2020-02-29 22:11:26 +0200 | [diff] [blame] | 493 | getModelVersionEitherFromInstanceOrFromHierarchy(selectedNodeData, model): string | undefined { |
Alexey Sandler | 5c249d4 | 2020-03-09 11:04:52 +0200 | [diff] [blame] | 494 | return this.getNamedFieldFromInstanceOrFromHierarchy(selectedNodeData, "modelVersion", model, "version"); |
Alexey Sandler | 4e32415 | 2020-02-29 22:11:26 +0200 | [diff] [blame] | 495 | } |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 496 | |
Alexey Sandler | 4e32415 | 2020-02-29 22:11:26 +0200 | [diff] [blame] | 497 | getModelCustomizationIdEitherFromInstanceOrFromHierarchy(selectedNodeData, model): string | undefined { |
Alexey Sandler | 5c249d4 | 2020-03-09 11:04:52 +0200 | [diff] [blame] | 498 | return this.getNamedFieldFromInstanceOrFromHierarchy(selectedNodeData, "modelCustomizationId", model, "customizationUuid"); |
| 499 | } |
| 500 | |
| 501 | getModelInvariantIdEitherFromInstanceOrFromHierarchy(selectedNodeData, model): string | undefined { |
| 502 | return this.getNamedFieldFromInstanceOrFromHierarchy(selectedNodeData, "modelInvariantId", model, "invariantUuid"); |
| 503 | } |
| 504 | |
| 505 | getModelVersionIdEitherFromInstanceOrFromHierarchy(selectedNodeData, model): string | undefined { |
| 506 | return this.getNamedFieldFromInstanceOrFromHierarchy (selectedNodeData, "modelVersionId", model, "uuid"); |
| 507 | } |
| 508 | |
| 509 | |
| 510 | |
| 511 | getNamedFieldFromInstanceOrFromHierarchy(selectedNodeData, instanceModelInfoFieldName, model, modelFieldName): string | undefined { |
| 512 | if (instanceModelInfoFieldName && selectedNodeData && selectedNodeData.instanceModelInfo |
| 513 | && selectedNodeData.instanceModelInfo[instanceModelInfoFieldName]) { |
| 514 | return selectedNodeData.instanceModelInfo[instanceModelInfoFieldName]; |
| 515 | } else if (modelFieldName && model && model[modelFieldName]) { |
| 516 | return model[modelFieldName]; |
Alexey Sandler | 4e32415 | 2020-02-29 22:11:26 +0200 | [diff] [blame] | 517 | } |
| 518 | return undefined; |
| 519 | } |
| 520 | |
| 521 | addGeneralInfoItems(modelInfoSpecificItems: ModelInformationItem[], type: ComponentInfoType, model, selectedNodeData):ComponentInfoModel { |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 522 | let modelInfoItems: ModelInformationItem[] = [ |
Alexey Sandler | 4e32415 | 2020-02-29 22:11:26 +0200 | [diff] [blame] | 523 | ModelInformationItem.createInstance("Model version", this.getModelVersionEitherFromInstanceOrFromHierarchy(selectedNodeData, model)), |
| 524 | ModelInformationItem.createInstance("Model customization ID", this.getModelCustomizationIdEitherFromInstanceOrFromHierarchy(selectedNodeData, model)), |
| 525 | ModelInformationItem.createInstance("Instance ID", selectedNodeData ? selectedNodeData.instanceId : null), |
| 526 | ModelInformationItem.createInstance("Instance type", selectedNodeData ? selectedNodeData.instanceType : null), |
| 527 | ModelInformationItem.createInstance("In maintenance", selectedNodeData? selectedNodeData.inMaint : null), |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 528 | ]; |
| 529 | modelInfoItems = modelInfoItems.concat(modelInfoSpecificItems); |
Alexey Sandler | 4e32415 | 2020-02-29 22:11:26 +0200 | [diff] [blame] | 530 | return this.getComponentInfoModelByModelInformationItems(modelInfoItems, type, selectedNodeData); |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | getComponentInfoModelByModelInformationItems(modelInfoItems: ModelInformationItem[], type: ComponentInfoType, instance){ |
| 534 | const modelInfoItemsWithoutEmpty = _.filter(modelInfoItems, function(item){ return !item.values.every(_.isNil)}); |
| 535 | return new ComponentInfoModel(type, modelInfoItemsWithoutEmpty, [], instance != null); |
| 536 | } |
Eylon Malin | 0a26826 | 2019-12-15 10:03:03 +0200 | [diff] [blame] | 537 | |
| 538 | createMaximumToInstantiateModelInformationItem(model): ModelInformationItem { |
| 539 | return ModelInformationItem.createInstance( |
| 540 | "Max instances", |
| 541 | !_.isNil(model.max) ? String(model.max) : Constants.ModelInfo.UNLIMITED_DEFAULT |
| 542 | ); |
| 543 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 544 | } |