blob: 26776d05daedbda8fa236713efcb3206c0060cee [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {Injectable} from "@angular/core";
2import {NgRedux} from "@angular-redux/store";
3import {AppState} from "../../../shared/store/reducers";
ikram09a65622020-07-22 10:28:15 -04004import {PauseStatus, ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
Ittay Stern6f900cc2018-08-29 17:01:32 +03005import {MessageBoxData} from "../../../shared/components/messageBox/messageBox.data";
6import {MessageBoxService} from "../../../shared/components/messageBox/messageBox.service";
7import * as _ from "lodash";
8import {DrawingBoardModes} from "../drawing-board.modes";
9import {AuditInfoModalComponent} from "../../../shared/components/auditInfoModal/auditInfoModal.component";
Ittay Stern6f900cc2018-08-29 17:01:32 +030010import {ILevelNodeInfo} from "./models/basic.model.info";
Ittay Sternf7926712019-07-07 19:23:03 +030011import {ComponentInfoModel, ComponentInfoType} from "../component-info/component-info-model";
12import {ModelInformationItem} from "../../../shared/components/model-information/model-information.component";
Einat Vinouzee1f79742019-08-27 16:01:01 +030013import {undoUpgradeService, upgradeService} from "../../../shared/storeUtil/utils/service/service.actions";
14import {VNFMethods} from "../../../shared/storeUtil/utils/vnf/vnf.actions";
15import {FeatureFlagsService, Features} from "../../../shared/services/featureFlag/feature-flags.service";
Yoav Schneiderman1f2a2942019-12-09 16:42:21 +020016import {Utils} from "../../../shared/utils/utils";
Eylon Malin0a268262019-12-15 10:03:03 +020017import {Constants} from "../../../shared/utils/constants";
Ittay Stern18c3ce82019-12-26 15:21:17 +020018import {NodeInstance} from "../../../shared/models/nodeInstance";
Ittay Stern6f900cc2018-08-29 17:01:32 +030019
20@Injectable()
21export class SharedTreeService {
Ittay Stern6f900cc2018-08-29 17:01:32 +030022 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 ************************************************************/
Mateusz Gołuchowskid74f6cc2020-11-05 10:11:08 +010031 selectedNF: string = null;
Ittay Stern6f900cc2018-08-29 17:01:32 +030032
Mateusz Gołuchowskid74f6cc2020-11-05 10:11:08 +010033 getSelectedNF(): string {
34 return this.selectedNF;
Ittay Stern6f900cc2018-08-29 17:01:32 +030035 }
36
Mateusz Gołuchowskid74f6cc2020-11-05 10:11:08 +010037 setSelectedNF(node): void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030038 if (_.isNil(node) || node.data.type !== 'VF') {
Mateusz Gołuchowskid74f6cc2020-11-05 10:11:08 +010039 this.selectedNF = null;
40 } else if (node.data.type === 'VF'){
41 this.selectedNF = node.data.vnfStoreKey;
42 } else if (node.data.type === 'PNF'){
43 this.selectedNF = node.data.pnfStoreKey;
Ittay Stern6f900cc2018-08-29 17:01:32 +030044 }
Mateusz Gołuchowskid74f6cc2020-11-05 10:11:08 +010045
Ittay Stern6f900cc2018-08-29 17:01:32 +030046 }
47
Ittay Stern18c3ce82019-12-26 15:21:17 +020048 /**
49 * Determines a consistent unique ID for a given right-tree
50 * node instance.
51 */
52 modelUniqueId = (nodeInstance: NodeInstance): string => {
53 return _.isNil(nodeInstance.modelInfo)
54 ? null
55 : (nodeInstance.modelInfo.modelCustomizationId || nodeInstance.modelInfo.modelInvariantId);
56 };
57
Ittay Sternf84164f2020-02-04 14:13:24 +020058 modelUniqueNameOrId = (instance): string => {
59 if (_.isNil(instance)) {
60 return null;
61 }
62
63 const innerInstance = _.find(instance) || {};
64
65 return instance.originalName
66 || this.modelUniqueId(instance)
67 || innerInstance.originalName
68 || this.modelUniqueId(innerInstance);
69 };
Ittay Stern74e62712020-01-29 18:20:23 +020070
Ittay Stern6b1e53d2020-01-21 12:20:37 +020071 /**
72 * Finds a model inside a full service model
73 * @param serviceModelFromHierarchy
74 * @param modelTypeName "vnfs" | "networks" | "vfModules" | "collectionResources" | ...
Ittay Stern74e62712020-01-29 18:20:23 +020075 * @param modelUniqueNameOrId Either an entry name (i.e. "originalName"), modelCustomizationId or modelInvariantId.
Ittay Stern6b1e53d2020-01-21 12:20:37 +020076 * Note that modelInvariantId will work only where model lacks a modelCustomizationId.
Ittay Stern08142382020-02-02 18:09:40 +020077 * @param modelName An optional entry name (i.e. "originalName"); will not try to use as id
Ittay Stern6b1e53d2020-01-21 12:20:37 +020078 */
Ittay Stern08142382020-02-02 18:09:40 +020079 modelByIdentifiers = (serviceModelFromHierarchy, modelTypeName: string, modelUniqueNameOrId: string, modelName?: string): any => {
Ittay Stern74e62712020-01-29 18:20:23 +020080 const logErrorAndReturnUndefined = () =>
81 console.info(`modelByIdentifiers: could not find a model matching query`, {
Ittay Stern08142382020-02-02 18:09:40 +020082 modelTypeName, modelUniqueNameOrId, modelName, serviceModelFromHierarchy
Ittay Stern74e62712020-01-29 18:20:23 +020083 });
84
85 if (_.isNil(serviceModelFromHierarchy)) return logErrorAndReturnUndefined();
Ittay Stern6b1e53d2020-01-21 12:20:37 +020086
87 const modelsOfType = serviceModelFromHierarchy[modelTypeName];
Ittay Stern74e62712020-01-29 18:20:23 +020088 if (_.isNil(modelsOfType)) return logErrorAndReturnUndefined();
Ittay Stern6b1e53d2020-01-21 12:20:37 +020089
Ittay Stern74e62712020-01-29 18:20:23 +020090 const modelIfModelIdentifierIsEntryName = modelsOfType[modelUniqueNameOrId];
Ittay Stern08142382020-02-02 18:09:40 +020091 const modelIfModeNameExists = _.isNil(modelName) ? null : modelsOfType[modelName];
Ittay Stern74e62712020-01-29 18:20:23 +020092
93 if (!_.isNil(modelIfModelIdentifierIsEntryName)) {
94 return modelIfModelIdentifierIsEntryName;
95 } else if (!_.isNil(modelIfModeNameExists)) {
96 return modelIfModeNameExists;
97 } else {
98 // try modelUniqueNameOrId as an id
99 return _.find(modelsOfType, o => (o.customizationUuid || o.invariantUuid) === modelUniqueNameOrId) || logErrorAndReturnUndefined()
100 }
Ittay Stern6b1e53d2020-01-21 12:20:37 +0200101 };
102
Ittay Stern6f900cc2018-08-29 17:01:32 +0300103 hasMissingData(instance, dynamicInputs: any, isEcompGeneratedNaming: boolean, requiredFields: string[]): boolean {
104 if (!isEcompGeneratedNaming && _.isEmpty(instance.instanceName)) {
105 return true;
106 }
107
108 for (let field of requiredFields) {
109 if (_.isEmpty(instance[field])) {
110 return true;
111 }
112 }
113
114 for (let field of dynamicInputs) {
115 if (field.isRequired && !_.isNil(instance.instanceParams) && _.isEmpty(instance.instanceParams[0][field.id])) {
116 return true;
117 }
118 }
119 return false;
120 }
121
122
123 addingStatusProperty(node) {
124 node['statusProperties'] = [];
Alexey Sandlera29c7c02020-03-31 22:40:10 +0300125 node['statusProperties'].push({key: 'Prov Status: ', value: node.provStatus, testId: 'provStatus'});
126 node['statusProperties'].push({key: 'Orch Status: ', value: node.orchStatus, testId: 'orchStatus'});
127 if(node.type === 'VFmodule') {
128 node['statusProperties'].push({key: 'Model Version: ', value: this.getNodeModelVersion(node), testId: 'modelVersion'});
129 }
Ittay Stern6f900cc2018-08-29 17:01:32 +0300130 if (node.inMaint) {
131 node['statusProperties'].push({key: 'In-maintenance', value: '', testId: 'inMaint'});
132 }
133 return node;
134 }
135
Alexey Sandlera29c7c02020-03-31 22:40:10 +0300136 getNodeModelVersion(node): string | undefined {
137 if(!_.isNil(node.instanceModelInfo) && !_.isNil(node.instanceModelInfo.modelVersion)){
138 return node.instanceModelInfo.modelVersion;
139 }
140 return undefined;
141 }
142
Ittay Stern6f900cc2018-08-29 17:01:32 +0300143 /**********************************************
144 * should delete or remove child instance's
145 "new" -> should remove
146 !new" -> should change action status
147 **********************************************/
148 removeDeleteAllChild(node, serviceModelId: string, callback): void {
149 for (let nodeChild of node.children) {
150 if (nodeChild.data.action === ServiceInstanceActions.Create) {
151 if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['remove'])) {
152 nodeChild.data.menuActions['remove']['method'](nodeChild, serviceModelId);
153 }
154 } else {
155 if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['delete'])) {
156 nodeChild.data.menuActions['delete']['method'](nodeChild, serviceModelId);
157 }
158 }
159 }
160 callback(node, serviceModelId);
161 }
162
163
164 /**********************************************
165 * should undo delete child instance's
166 **********************************************/
167 undoDeleteAllChild(node, serviceModelId: string, callback): void {
168 for (let nodeChild of node.children) {
169 if (!_.isNil(nodeChild.data) && !_.isNil(nodeChild.data.menuActions) && !_.isNil(nodeChild.data.menuActions['undoDelete'])) {
170 nodeChild.data.menuActions['undoDelete']['method'](nodeChild, serviceModelId);
171 }
172 }
173 callback(node, serviceModelId);
174 }
175
176 /**********************************************
177 * should return true if can delete
178 **********************************************/
Eylon Malinaefc6a02020-01-29 15:11:47 +0200179 shouldShowDelete(node, serviceModelId): boolean {
180 return this.shouldShowButtonGeneric(node, "delete", serviceModelId)
Ittay Stern6f900cc2018-08-29 17:01:32 +0300181 }
182
183 /**********************************************
184 * should return true if can undo delete
185 **********************************************/
186 shouldShowUndoDelete(node): boolean {
187 const mode = this._store.getState().global.drawingBoardStatus;
188 if (mode === DrawingBoardModes.EDIT && !_.isNil(node.data.action) && !_.isNil(node.data.menuActions['undoDelete'])) {
189 if (node.data.action === ServiceInstanceActions.Create || node.data.action === ServiceInstanceActions.Delete) {
190 return false;
191 } else if (node.data.action.split('_').pop() === 'Delete') {
192 return true
193 }
194 return false;
195 }
196 return false;
197 }
198 /**********************************************
199 * should return true if can remove or edit
200 * enabled only on edit/design mode and for new instances
201 **********************************************/
202 shouldShowRemoveAndEdit(node): boolean {
203 const mode = this._store.getState().global.drawingBoardStatus;
204 if (!_.isNil(node) && !_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action === ServiceInstanceActions.Create &&
205 mode !== DrawingBoardModes.VIEW && mode !== DrawingBoardModes.RETRY) {
206 return true;
207 }
208 return false;
209 }
210 /**********************************************
Einat Vinouzee1f79742019-08-27 16:01:01 +0300211 * enabled only on edit/design
212 * enabled only if there's a newer version for VNF-M
213 **********************************************/
214 upgradeBottomUp(node,serviceModelId: string): void {
215 this.iterateOverTreeBranchAndRunAction(node, serviceModelId, VNFMethods.UPGRADE);
216 this._store.dispatch(upgradeService(serviceModelId));
217 }
218
219 private iterateOverTreeBranchAndRunAction(node, serviceModelId: string, actionMethod) {
220 while (_.has(node.parent, 'data') && _.has(node.parent.data, 'menuActions')
221 && !_.isNil(node.parent.data.menuActions[actionMethod])) {
222 node = node.parent;
223 node.data.menuActions[actionMethod]['method'](node, serviceModelId);
224 }
225 }
226
ikram09a65622020-07-22 10:28:15 -0400227 shouldShowRemovePause(node) : boolean {
228 if(FeatureFlagsService.getFlagState(Features.FLAG_2008_REMOVE_PAUSE_INSTANTIATION, this._store)){
229 return node.pauseInstantiation === PauseStatus.AFTER_COMPLETION;
230 }
231 return false;
232 }
Rachitha Ramappab47aac82020-10-13 19:27:45 +0530233
234 showPauseWithOrchStatus(node): boolean {
235 if(node.orchStatus == "Active"){
236 return false;
237 }
238 return true;
239 }
ikram09a65622020-07-22 10:28:15 -0400240
241 shouldShowPauseInstantiation(node): boolean {
242 if(FeatureFlagsService.getFlagState(Features.FLAG_2008_REMOVE_PAUSE_INSTANTIATION, this._store)){
243 return (FeatureFlagsService.getFlagState(Features.FLAG_2006_PAUSE_VFMODULE_INSTANTIATION_CREATION, this._store) && node.pauseInstantiation == null);
244 }
Alexey Sandlerc8a3cff2020-05-06 18:58:14 +0300245 return (FeatureFlagsService.getFlagState(Features.FLAG_2006_PAUSE_VFMODULE_INSTANTIATION_CREATION, this._store));
246 }
Einat Vinouzee1f79742019-08-27 16:01:01 +0300247 /****************************************************
248 * should return true if customer can upgrade a VFM *
249 ****************************************************/
250 shouldShowUpgrade(node, serviceModelId): boolean {
Alexey Sandler56093382020-02-13 09:53:14 +0200251 return (this.isVfMoudleCouldBeUpgraded(node, serviceModelId))
252 && this.shouldShowButtonGeneric(node, VNFMethods.UPGRADE, serviceModelId) ;
Einat Vinouzee1f79742019-08-27 16:01:01 +0300253 }
Alexey Sandler56093382020-02-13 09:53:14 +0200254
255 isVfMoudleCouldBeUpgraded(node, serviceModelId): boolean{
256 return (FeatureFlagsService.getFlagState(Features.FLAG_FLASH_REPLACE_VF_MODULE, this._store) &&
Alexey Sandler32d65b82020-02-13 17:31:00 +0200257 (this.isThereAnUpdatedLatestVersion(serviceModelId) || this.isVfModuleCustomizationIdNotExistsOnModel(node, serviceModelId)))
258 }
259
260 isVfModuleCustomizationIdNotExistsOnModel(vfModuleNode, serviceModelId) {
261
262 // prevent undefined
263 if (_.isNil(vfModuleNode.data) || _.isNil(vfModuleNode.data.modelCustomizationId)) {
264 return false;
265 }
266
267 let vfModulesHierarchyByGivenModelId = this._store.getState().service.serviceHierarchy[serviceModelId].vfModules;
268 return !_.some(vfModulesHierarchyByGivenModelId, vfmodel => vfmodel.customizationUuid === vfModuleNode.data.modelCustomizationId);
Einat Vinouzee1f79742019-08-27 16:01:01 +0300269 }
270
Yoav Schneidermana3e54c32020-02-02 20:00:00 +0200271
Ittay Sternf84164f2020-02-04 14:13:24 +0200272 isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer(vfModuleNode, serviceModelId) : boolean {
273 /*
274 for `true`, should all:
275 1. parent vnf found by model-mane
276 2. vfmodule found by invariant
277 3. vfmodule diff by customization
278 */
279
280 if (_.isNil(vfModuleNode.data)) {
281 return false;
Yoav Schneidermana3e54c32020-02-02 20:00:00 +0200282 }
Ittay Sternf84164f2020-02-04 14:13:24 +0200283
284 const vnfHierarchy = this.getParentVnfHierarchy(vfModuleNode, serviceModelId);
285 if (_.isNil(vnfHierarchy)) {
286 return false;
287 }
288
289 const vfModuleHierarchyByInvariantId = this.getVfModuleHFromVnfHierarchyByInvariantId(vfModuleNode, vnfHierarchy);
290 if(_.isNil(vfModuleHierarchyByInvariantId)){
291 return false;
292 }
293
294 return vfModuleHierarchyByInvariantId.customizationUuid
295 && (vfModuleHierarchyByInvariantId.customizationUuid !== vfModuleNode.data.modelCustomizationId);
Yoav Schneidermana3e54c32020-02-02 20:00:00 +0200296 }
297
Ittay Sternf84164f2020-02-04 14:13:24 +0200298 getParentVnfHierarchy(vfModuleNode, serviceModelId) {
299 if (vfModuleNode.parent && vfModuleNode.parent.data) {
300 return this._store.getState().service.serviceHierarchy[serviceModelId].vnfs[vfModuleNode.parent.data.modelName];
301 } else {
302 return null;
303 }
304 }
305
306 getVfModuleHFromVnfHierarchyByInvariantId(vfModuleNode, parentVnfHierarchy) {
307 if(vfModuleNode.data.modelInvariantId && parentVnfHierarchy && parentVnfHierarchy.vfModules){
308 return _.find(parentVnfHierarchy.vfModules, o => o.invariantUuid === vfModuleNode.data.modelInvariantId);
Yoav Schneidermana3e54c32020-02-02 20:00:00 +0200309 }
310 return null;
311 }
312
313
314 isThereAnUpdatedLatestVersion(serviceModelId) : boolean{
Eylon Malinaefc6a02020-01-29 15:11:47 +0200315 let serviceInstance = this.getServiceInstance(serviceModelId);
Einat Vinouzee1f79742019-08-27 16:01:01 +0300316 return !_.isNil(serviceInstance.latestAvailableVersion) && (Number(serviceInstance.modelInfo.modelVersion) < serviceInstance.latestAvailableVersion);
317 }
318
Eylon Malinaefc6a02020-01-29 15:11:47 +0200319 private getServiceInstance(serviceModelId): any {
320 return this._store.getState().service.serviceInstance[serviceModelId];
321 }
322
323 shouldShowButtonGeneric(node, method, serviceModelId) {
Einat Vinouzee1f79742019-08-27 16:01:01 +0300324 const mode = this._store.getState().global.drawingBoardStatus;
Eylon Malinaefc6a02020-01-29 15:11:47 +0200325 const isMacro = !(this.getServiceInstance(serviceModelId).isALaCarte);
326
327 if (isMacro) { //if macro action allowed only for service level
328 return false;
329 }
330
Einat Vinouzee1f79742019-08-27 16:01:01 +0300331 if (!_.isNil(node) && !_.isNil(node.data) && !_.isNil(node.data.action) && !_.isNil(node.data.menuActions[method])) {
332 if (mode !== DrawingBoardModes.EDIT || node.data.action === ServiceInstanceActions.Create) {
333 return false;
334 }
335 else if (node.data.action === ServiceInstanceActions.None) {
336 return true
337 }
338 }
339 return false;
340 }
341
342 /**********************************************
343 * return boolean according to
344 * current defined action of VFModule node
345 **********************************************/
346 shouldShowUndoUpgrade(node): boolean {
347 const mode = this._store.getState().global.drawingBoardStatus;
348 if (mode === DrawingBoardModes.EDIT && !_.isNil(node.data.action) && !_.isNil(node.data.menuActions[VNFMethods.UNDO_UPGRADE])) {
349 if (node.data.action === ServiceInstanceActions.Upgrade) {
350 return false;
351 } else if (node.data.action.split('_').pop() === ServiceInstanceActions.Upgrade) {
352 return true
353 }
354 return false;
355 }
356 return false;
357 }
358 /**********************************************
359 * enabled only on edit/design
360 * enabled only if there's a newer version for VNF-M
361 **********************************************/
362 undoUpgradeBottomUp(node,serviceModelId: string): void {
363 this.iterateOverTreeBranchAndRunAction(node, serviceModelId, VNFMethods.UNDO_UPGRADE);
364 this._store.dispatch(undoUpgradeService(serviceModelId));
365 }
366 /**********************************************
Ittay Stern6f900cc2018-08-29 17:01:32 +0300367 * should return true if can duplicate by mode
368 **********************************************/
369 shouldShowDuplicate(node): boolean {
370 const mode = this._store.getState().global.drawingBoardStatus;
371 return !mode.includes('RETRY');
372 }
373
374 /**********************************************
375 * should return true if can audit info
376 **********************************************/
377 shouldShowAuditInfo(node): boolean {
378 return this.isRetryMode() || (!_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action !== ServiceInstanceActions.Create);
379 }
380
381
382 isRetryMode(): boolean {
383 const mode = this._store.getState().global.drawingBoardStatus;
384 return mode.includes('RETRY');
385 }
386
387
388 /**********************************************
389 * should return true if can add node instances
390 **********************************************/
391 shouldShowAddIcon(): boolean{
392 const mode = this._store.getState().global.drawingBoardStatus;
Ittay Stern18c3ce82019-12-26 15:21:17 +0200393 return mode === DrawingBoardModes.EDIT || mode=== DrawingBoardModes.CREATE || mode=== DrawingBoardModes.RECREATE;
Ittay Stern6f900cc2018-08-29 17:01:32 +0300394 }
Yoav Schneiderman1f2a2942019-12-09 16:42:21 +0200395
396
397 isReachedToMaxInstances(properties, counter, flags): boolean{
398 let maxInstances = Utils.getMaxFirstLevel(properties, flags);
399 if(_.isNil(maxInstances)){
400 return false;
401 }else {
402 return !(maxInstances > counter);
403 }
404 }
Ittay Stern6f900cc2018-08-29 17:01:32 +0300405 /************************************************
406 return number of instances with action Delete
407 @type: vnfs networks, vngGroups (not vfModule)
408 @node : node model from the left tree
409 ************************************************/
410 getExistingInstancesWithDeleteMode(node, serviceModelId: string, type: string): number {
411 let counter = 0;
Eylon Malinaefc6a02020-01-29 15:11:47 +0200412 const existingInstances = this.getServiceInstance(serviceModelId)[type];
Ittay Stern6f900cc2018-08-29 17:01:32 +0300413 const modelUniqueId = node.data.modelUniqueId;
414 if (!_.isNil(existingInstances)) {
415 for (let instanceKey in existingInstances) {
416 if (!_.isNil(existingInstances[instanceKey].action)) {
417 if (existingInstances[instanceKey].modelInfo.modelUniqueId === modelUniqueId && existingInstances[instanceKey].action.split('_').pop() === 'Delete') {
418 counter++;
419 }
420 }
421 }
422 }
423 return counter;
424 }
425
426
427 isServiceOnDeleteMode(serviceId: string): boolean {
428 return this._store.getState().service.serviceInstance[serviceId].action === ServiceInstanceActions.Delete;
429 }
430
431
432 openModal(node : any | any[] , serviceModelId : string, cb : Function) : void {
433 let type: string = _.isArray(node) ? 'Service' : node.data.typeName;
434 let messageBoxData: MessageBoxData = new MessageBoxData(
435 "Mark for Delete",
436 `You are about to mark for delete this ${type} this will also mark all its children and remove all new instances just added`,
437 <any>"warning",
438 <any>"md",
439 [
440 {
441 text: "Mark and remove",
442 size: "large",
443 callback: cb.bind(this, node, serviceModelId),
444 closeModal: true
445 },
446 {text: "Don’t Remove", size: "medium", closeModal: true}
447 ]);
448
449 MessageBoxService.openModal.next(messageBoxData);
450 }
451
452 someChildHasCreateAction(nodes: any | any[]) : boolean {
453 let nodesArr = _.isArray(nodes) ? nodes : [nodes];
454 for(const node of nodesArr){
455 if(node.action === ServiceInstanceActions.Create) {return true;}
456 if(node.children){
457 for (let nodeChild of node.children) {
458 if (nodeChild.action === ServiceInstanceActions.Create) {
459 return true;
460 }
461 if(nodeChild.children && nodeChild.children.length > 0){
462 for(let child of nodeChild.children){
463 let hasCreateAction = this.someChildHasCreateAction(child);
464 if(hasCreateAction) {
465 return true;
466 }
467 }
468 }
469 }
470 }
471 }
472 return false;
473 }
474
475 shouldShowDeleteInstanceWithChildrenModal(node : any | any[] , serviceModelId : string, cb : Function) : void {
476 if(this.someChildHasCreateAction(node)){
477 this.openModal(node , serviceModelId, cb);
478 }else {
479 cb(node, serviceModelId)
480 }
481 }
482
483
484 isFailed(node): boolean {
485 return !_.isNil(node.data) ? node.data.isFailed : false;
486 }
487
488 /************************************************
489 in a case the node is failed e.g. not instantiated correctly
490 the function will call to openRetryInstanceAuditInfoModal
491 @node : node model from the left tree
492 @serviceModelId : serviceModelId
493 @instance : instance
494 @instanceType: instanceType
495 @modelInfoService : the model (vnf, vfmodule, network, vnfgroup)object that call to the function (this)
496 ************************************************/
497 openAuditInfoModal(node, serviceModelId, instance, instanceType, modelInfoService : ILevelNodeInfo){
Ittay Sternf7926712019-07-07 19:23:03 +0300498 AuditInfoModalComponent.openInstanceAuditInfoModal.next({
499 instanceId: serviceModelId,
500 type: instanceType,
Ittay Stern08142382020-02-02 18:09:40 +0200501 model: modelInfoService.getModel(
502 this.modelByIdentifiers(
503 this._store.getState().service.serviceHierarchy[serviceModelId],
504 modelInfoService.name,
505 this.modelUniqueNameOrId(instance), node.data.modelName
506 )
507 ),
Ittay Sternf7926712019-07-07 19:23:03 +0300508 instance
509 });
510 }
511
Alexey Sandler4e324152020-02-29 22:11:26 +0200512 getModelVersionEitherFromInstanceOrFromHierarchy(selectedNodeData, model): string | undefined {
Alexey Sandler5c249d42020-03-09 11:04:52 +0200513 return this.getNamedFieldFromInstanceOrFromHierarchy(selectedNodeData, "modelVersion", model, "version");
Alexey Sandler4e324152020-02-29 22:11:26 +0200514 }
Ittay Sternf7926712019-07-07 19:23:03 +0300515
Alexey Sandler4e324152020-02-29 22:11:26 +0200516 getModelCustomizationIdEitherFromInstanceOrFromHierarchy(selectedNodeData, model): string | undefined {
Alexey Sandler5c249d42020-03-09 11:04:52 +0200517 return this.getNamedFieldFromInstanceOrFromHierarchy(selectedNodeData, "modelCustomizationId", model, "customizationUuid");
518 }
519
520 getModelInvariantIdEitherFromInstanceOrFromHierarchy(selectedNodeData, model): string | undefined {
521 return this.getNamedFieldFromInstanceOrFromHierarchy(selectedNodeData, "modelInvariantId", model, "invariantUuid");
522 }
523
524 getModelVersionIdEitherFromInstanceOrFromHierarchy(selectedNodeData, model): string | undefined {
525 return this.getNamedFieldFromInstanceOrFromHierarchy (selectedNodeData, "modelVersionId", model, "uuid");
526 }
527
528
529
530 getNamedFieldFromInstanceOrFromHierarchy(selectedNodeData, instanceModelInfoFieldName, model, modelFieldName): string | undefined {
531 if (instanceModelInfoFieldName && selectedNodeData && selectedNodeData.instanceModelInfo
532 && selectedNodeData.instanceModelInfo[instanceModelInfoFieldName]) {
533 return selectedNodeData.instanceModelInfo[instanceModelInfoFieldName];
534 } else if (modelFieldName && model && model[modelFieldName]) {
535 return model[modelFieldName];
Alexey Sandler4e324152020-02-29 22:11:26 +0200536 }
537 return undefined;
538 }
539
540 addGeneralInfoItems(modelInfoSpecificItems: ModelInformationItem[], type: ComponentInfoType, model, selectedNodeData):ComponentInfoModel {
Ittay Sternf7926712019-07-07 19:23:03 +0300541 let modelInfoItems: ModelInformationItem[] = [
Alexey Sandler4e324152020-02-29 22:11:26 +0200542 ModelInformationItem.createInstance("Model version", this.getModelVersionEitherFromInstanceOrFromHierarchy(selectedNodeData, model)),
543 ModelInformationItem.createInstance("Model customization ID", this.getModelCustomizationIdEitherFromInstanceOrFromHierarchy(selectedNodeData, model)),
544 ModelInformationItem.createInstance("Instance ID", selectedNodeData ? selectedNodeData.instanceId : null),
545 ModelInformationItem.createInstance("Instance type", selectedNodeData ? selectedNodeData.instanceType : null),
546 ModelInformationItem.createInstance("In maintenance", selectedNodeData? selectedNodeData.inMaint : null),
Ittay Sternf7926712019-07-07 19:23:03 +0300547 ];
548 modelInfoItems = modelInfoItems.concat(modelInfoSpecificItems);
Alexey Sandler4e324152020-02-29 22:11:26 +0200549 return this.getComponentInfoModelByModelInformationItems(modelInfoItems, type, selectedNodeData);
Ittay Sternf7926712019-07-07 19:23:03 +0300550 }
551
552 getComponentInfoModelByModelInformationItems(modelInfoItems: ModelInformationItem[], type: ComponentInfoType, instance){
553 const modelInfoItemsWithoutEmpty = _.filter(modelInfoItems, function(item){ return !item.values.every(_.isNil)});
554 return new ComponentInfoModel(type, modelInfoItemsWithoutEmpty, [], instance != null);
555 }
Eylon Malin0a268262019-12-15 10:03:03 +0200556
557 createMaximumToInstantiateModelInformationItem(model): ModelInformationItem {
558 return ModelInformationItem.createInstance(
559 "Max instances",
560 !_.isNil(model.max) ? String(model.max) : Constants.ModelInfo.UNLIMITED_DEFAULT
561 );
562 }
ikram32af6472020-08-07 15:49:11 -0400563
564 isAddPositionFlagTrue():boolean{
565 return FeatureFlagsService.getFlagState(Features.FLAG_2008_CREATE_VFMODULE_INSTANTIATION_ORDER_NUMBER, this._store);
566 }
Ittay Stern6f900cc2018-08-29 17:01:32 +0300567}