aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/models/vnf/vnf.model.info.ts
blob: ebcba162e0480a06ca019471e9a2084cd4bbbca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import {DynamicInputsService} from "../../dynamicInputs.service";
import {ILevelNodeInfo} from "../basic.model.info";
import {VFModuleModelInfo} from "../vfModule/vfModule.model.info";
import {VNFModel} from "../../../../../shared/models/vnfModel";
import {VnfInstance} from "../../../../../shared/models/vnfInstance";
import {VnfTreeNode} from "../../../../../shared/models/vnfTreeNode";
import {InputType} from "../../../../../shared/models/inputTypes";
import {SharedTreeService} from "../../shared.tree.service";
import {NgRedux} from "@angular-redux/store";
import {AppState} from "../../../../../shared/store/reducers";
import {DefaultDataGeneratorService} from "../../../../../shared/services/defaultDataServiceGenerator/default.data.generator.service";
import {
  GenericFormPopupComponent,
  PopupType
} from "../../../../../shared/components/genericFormPopup/generic-form-popup.component";
import {DialogService} from 'ng2-bootstrap-modal';
import {VnfPopupService} from "../../../../../shared/components/genericFormPopup/genericFormServices/vnf/vnf.popup.service";
import {VfModulePopuopService} from "../../../../../shared/components/genericFormPopup/genericFormServices/vfModule/vfModule.popuop.service";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
import {AvailableNodeIcons} from "../../../available-models-tree/available-models-tree.service";
import {DuplicateService} from "../../../duplicate/duplicate.service";
import {DuplicateVnfComponent} from "../../../duplicate/duplicate-vnf.component";
import {SdcUiServices} from "onap-ui-angular";
import {IframeService} from "../../../../../shared/utils/iframe.service";
import {changeInstanceCounter, removeInstance} from "../../../../../shared/storeUtil/utils/general/general.actions";
import {MessageBoxData} from "../../../../../shared/components/messageBox/messageBox.data";
import {MessageBoxService} from "../../../../../shared/components/messageBox/messageBox.service";
import {ServiceInstanceActions} from "../../../../../shared/models/serviceInstanceActions";
import {
  deleteActionVnfInstance,
  undoDeleteActionVnfInstance,
  undoUpgradeVnf,
  updateVnfPosition,
  upgradeVnf
} from "../../../../../shared/storeUtil/utils/vnf/vnf.actions";
import * as _ from 'lodash';
import {IModalConfig} from "onap-ui-angular/dist/modals/models/modal-config";
import {ComponentInfoType} from "../../../component-info/component-info-model";
import {ComponentInfoService} from "../../../component-info/component-info.service";
import {ModelInformationItem} from "../../../../../shared/components/model-information/model-information.component";

export class VnfModelInfo implements ILevelNodeInfo {
  constructor(private _dynamicInputsService: DynamicInputsService,
              private _sharedTreeService: SharedTreeService,
              private _defaultDataGeneratorService: DefaultDataGeneratorService,
              private _dialogService: DialogService,
              private _vnfPopupService: VnfPopupService,
              private _vfModulePopupService: VfModulePopuopService,
              private _duplicateService: DuplicateService,
              private modalService: SdcUiServices.ModalService,
              private _iframeService: IframeService,
              private _componentInfoService: ComponentInfoService,
              private _store: NgRedux<AppState>) {
  }

  name: string = 'vnfs';
  type: string = 'VNF';
  childNames: string[] = ['vfModules'];
  typeName: string = 'VNF';
  componentInfoType = ComponentInfoType.VNF;

  /***********************************************************
   * return if user should provide instance name or not.
   * @param currentModel - current Model object
   ************************************************************/
  isEcompGeneratedNaming = (currentModel): boolean => {
    const ecompGeneratedNaming = currentModel.properties.ecomp_generated_naming;
    return ecompGeneratedNaming === "true";
  };

  /***********************************************************
   * return model dynamic inputs
   * @param currentModel - current Model object
   ************************************************************/
  updateDynamicInputsDataFromModel = (currentModel): any => {
    let displayInputs;
    return _.isEmpty(displayInputs) ? [] : this._dynamicInputsService.getArbitraryInputs(displayInputs);
  };

  /***********************************************************
   * return vnf model
   * @param vnfModelId - current Model id
   * @param instance - vnf instance
   * @param serviceHierarchy - serviceHierarchy
   ************************************************************/
  getModel = (vnfModelId: string, instance: VnfInstance, serviceHierarchy): VNFModel => {
    const originalModelName = instance.originalName ? instance.originalName : vnfModelId;
    return new VNFModel(serviceHierarchy[this.name][originalModelName]);
  };


  /***********************************************************
   * return vnf instance tree node
   * @param instance - vnf instance
   * @param model - vnf model
   * @param parentModel
   * @param storeKey - store key if exist
   ************************************************************/
  createInstanceTreeNode = (instance: VnfInstance, model: VNFModel, parentModel, storeKey: string): VnfTreeNode => {
    let node = new VnfTreeNode(instance, model, storeKey);
    node.missingData = this.hasMissingData(instance, node, model.isEcompGeneratedNaming);
    node.typeName = this.typeName;
    node.menuActions = this.getMenuAction(<any>node, model.uuid);
    node.isFailed = _.isNil(instance.isFailed) ? false : instance.isFailed;
    node.statusMessage = !_.isNil(instance.statusMessage) ? instance.statusMessage: "";
    node = this._sharedTreeService.addingStatusProperty(node);
    return node;
  };

  /***********************************************************
   * return next level object (VFModule)
   ************************************************************/
  getNextLevelObject = (): VFModuleModelInfo => {
    return new VFModuleModelInfo(this._dynamicInputsService, this._sharedTreeService, this._dialogService, this._vfModulePopupService, this._iframeService, this._store, this._componentInfoService);
  };

  /***********************************************************
   * return if instance has missing data
   * @param instance - vnf instance
   * @param dynamicInputs
   * @param isEcompGeneratedNaming
   ************************************************************/
  hasMissingData(instance, dynamicInputs: any, isEcompGeneratedNaming: boolean): boolean {
    return this._sharedTreeService.hasMissingData(instance, dynamicInputs, isEcompGeneratedNaming, [InputType.LCP_REGION, InputType.TENANT, InputType.PLATFORM]);
  }

  getTooltip = (): string => 'VF';

  getType = (): string => 'VF';

  /***********************************************************
   * return if instance has missing data
   * @param node - VNF node
   * @param serviceModelId - current service id
   ************************************************************/
  onClickAdd(node, serviceModelId: string): void {
    this._dialogService.addDialog(GenericFormPopupComponent, {
      type: PopupType.VNF,
      uuidData: <any>{
        serviceId: serviceModelId,
        modelName: node.data.name,
        vnfStoreKey: null,
        modelId: node.data.modelVersionId,
        type: node.data.type,
        popupService: this._vnfPopupService
      },
      node: node,
      isUpdateMode: false
    })
  }

  /***********************************************************
   * return number of existing instances
   * @param node - VNF node
   * @param serviceModelId - current service id
   ************************************************************/
  getNodeCount(node: ITreeNode, serviceModelId: string): number {
    let map = null;
    if (!_.isNil(this._store.getState().service.serviceInstance[serviceModelId])) {
      map = this._store.getState().service.serviceInstance[serviceModelId].existingVNFCounterMap || 0;

      if (!_.isNil(map)) {
        let count = map[node.data.modelUniqueId] || 0;
        count -= this._sharedTreeService.getExistingInstancesWithDeleteMode(node, serviceModelId, 'vnfs');
        return count;
      }
    }
    return 0;
  }

  /***********************************************************
   * should show node icon
   * @param node - current ITrees node
   * @param serviceModelId - service id
   ************************************************************/
  showNodeIcons(node: ITreeNode, serviceModelId: string): AvailableNodeIcons {
    let counter: number = !_.isNil(this._store.getState().service.serviceInstance[serviceModelId]) ?
      (this._store.getState().service.serviceInstance[serviceModelId].existingVNFCounterMap[node.data.modelUniqueId] || 0) : 0;
    counter -= this._sharedTreeService.getExistingInstancesWithDeleteMode(node, serviceModelId, 'vnfs');

    const properties = this._store.getState().service.serviceHierarchy[serviceModelId].vnfs[node.data.name].properties;
    const maxInstances: number = !_.isNil(properties) ? (properties.max_instances || 1) : 1;
    const isReachedLimit = !(maxInstances > counter);
    const showAddIcon = this._sharedTreeService.shouldShowAddIcon() && !isReachedLimit;
    return new AvailableNodeIcons(showAddIcon, isReachedLimit)
  }

  getMenuAction(node: ITreeNode, serviceModelId: string): { [methodName: string]: { method: Function, visible: Function, enable: Function } } {
    return <any>{
      edit: {
        method: (node, serviceModelId) => {
          this._iframeService.addClassOpenModal('content');
          this._dialogService.addDialog(GenericFormPopupComponent, {
            type: PopupType.VNF,
            uuidData: <any>{
              serviceId: serviceModelId,
              modelName: node.data.modelName,
              vnfStoreKey: node.data.vnfStoreKey,
              modelId: node.data.modelId,
              type: node.data.type,
              popupService: this._vnfPopupService
            },
            node: node,
            isUpdateMode: true
          });
        },
        visible: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
        enable: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
      },
      showAuditInfo: {
        method: (node, serviceModelId) => {
            const instance = this._store.getState().service.serviceInstance[serviceModelId].vnfs[node.data.vnfStoreKey];
            this._sharedTreeService.openAuditInfoModal(node, serviceModelId, instance, 'VNF', this);
          },
        visible: (node) => this._sharedTreeService.shouldShowAuditInfo(node),
        enable: (node) => this._sharedTreeService.shouldShowAuditInfo(node)
      },
      duplicate: {
        method: (node, serviceModelId) => {
          const storeKey = node.data.vnfStoreKey;
          let modalConfig: IModalConfig = this._duplicateService.openDuplicateModal(serviceModelId, node.data.modelUniqueId, node.data.modelName, storeKey, 1, this._store, node);
          this.modalService.openCustomModal(modalConfig, DuplicateVnfComponent);
        },
        visible: (node) => this._sharedTreeService.shouldShowDuplicate(node) && !_.isNil(node.data) && !_.isNil(node.data.action) && node.data.action === ServiceInstanceActions.Create && this._duplicateService.canDuplicate(node),
        enable: (node, serviceModelId) => this._duplicateService.isEnabled(node, this._store, serviceModelId)
      },
      remove: {
        method: (node, serviceModelId) => {
          if ((!_.isNil(node.data.children) && node.data.children.length === 0) || _.isNil(node.data.children)) {
            let storeKey: string = node.data.vnfStoreKey;
            this._store.dispatch(removeInstance(node.data.vnfStoreKey, serviceModelId, storeKey, node));
            this._store.dispatch(changeInstanceCounter(node.data.modelUniqueId, serviceModelId, -1, node));
            this._sharedTreeService.selectedVNF = null;
          } else {
            let messageBoxData: MessageBoxData = new MessageBoxData(
              "Remove VNF",  // modal title
              "You are about to remove this VNF and all its children from this service. Are you sure you want to remove it?",
              <any>"warning",
              <any>"md",
              [
                {
                  text: "Remove VNF",
                  size: "large",
                  callback: this.removeVnf.bind(this, node, serviceModelId),
                  closeModal: true
                },
                {text: "Don’t Remove", size: "medium", closeModal: true}
              ]);

            MessageBoxService.openModal.next(messageBoxData);
          }
        },
        visible: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
        enable: (node) => this._sharedTreeService.shouldShowRemoveAndEdit(node),
      },
      delete: {
        method: (node, serviceModelId) => {
          if ((!_.isNil(node.data.children) && node.data.children.length === 0) || _.isNil(node.data.children)) {
            this._store.dispatch(deleteActionVnfInstance(node.data.vnfStoreKey, serviceModelId));
          } else {
            this._sharedTreeService.shouldShowDeleteInstanceWithChildrenModal(node, serviceModelId, (node, serviceModelId) => {
              this._sharedTreeService.removeDeleteAllChild(node, serviceModelId, (node, serviceModelId) => {
                this._store.dispatch(deleteActionVnfInstance(node.data.vnfStoreKey, serviceModelId));
              });
            });
          }
        },
        visible: (node) => this._sharedTreeService.shouldShowDelete(node),
        enable: (node) => this._sharedTreeService.shouldShowDelete(node)
      },
      undoDelete: {
        method: (node, serviceModelId) => {
          if ((!_.isNil(node.data.children) && node.data.children.length === 0) || _.isNil(node.data.children)) {
            this._store.dispatch(undoDeleteActionVnfInstance(node.data.vnfStoreKey, serviceModelId));
          } else {
            this._sharedTreeService.undoDeleteAllChild(node, serviceModelId, (node, serviceModelId) => {
              this._store.dispatch(undoDeleteActionVnfInstance(node.data.vnfStoreKey, serviceModelId));
            });
          }
        },
        visible: (node) => this._sharedTreeService.shouldShowUndoDelete(node),
        enable: (node, serviceModelId) => this._sharedTreeService.shouldShowUndoDelete(node) && !this._sharedTreeService.isServiceOnDeleteMode(serviceModelId)
      },
      upgrade: {
        method: (node, serviceModelId) => {
          this._store.dispatch(upgradeVnf(node.data.vnfStoreKey, serviceModelId));
        },
        visible: () => false,
        enable: () => false
      },
      undoUpgrade: {
        method: (node, serviceModelId) => {
          this._store.dispatch(undoUpgradeVnf(node.data.vnfStoreKey, serviceModelId));
        },
        visible: () => false,
        enable: () => false
      },
    }
  }

  removeVnf(this, node, serviceModelId) {
    this._store.dispatch(removeInstance(node.data.modelName, serviceModelId, node.data.vnfStoreKey, node));
    this._store.dispatch(changeInstanceCounter(node.data.modelUniqueId, serviceModelId, -1, node));
    this._sharedTreeService.selectedVNF = null;
  }

  /***********************************************************
   * should update node position inside the tree
   * @param node - current ITrees node
   ************************************************************/
  updatePosition(that, node, instanceId): void {
    that.store.dispatch(updateVnfPosition(node, instanceId, node.vnfStoreKey));
  }

  /***********************************************************
   * return the position of the current node in the tree
   * @param instance - current ITrees node instance
   ************************************************************/
  getNodePosition(instance): number {
    return !_.isNil(instance) ? instance.position : null;
  }

  getInfo(model, instance): ModelInformationItem[] {
    const modelInformation = !_.isEmpty(model) ? [
      ModelInformationItem.createInstance("Min instances",  !_.isNull(model.min)? String(model.min): null),
      ModelInformationItem.createInstance("Max instances",  !_.isNull(model.max)? String(model.max): null)
    ] : [];

    const instanceInfo = !_.isEmpty(instance) ? [
      ModelInformationItem.createInstance("NF type", instance.nfType),
      ModelInformationItem.createInstance("NF role", instance.nfRole)
    ] : [];

    const result = [modelInformation, instanceInfo];
    return _.uniq(_.flatten(result));
  }
}