aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/instantiationStatus/instantiationStatus.component.service.ts
blob: 3c45632eec20e7a4a65e12bc044f76c51e7f2800 (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
import {Injectable} from '@angular/core';
import {ServiceInfoModel, ServiceInfoUiModel} from '../shared/server/serviceInfo/serviceInfo.model';
import * as _ from 'lodash';
import {Observable} from 'rxjs/Observable';
import {NgRedux} from "@angular-redux/store";
import {AppState} from "../shared/store/reducers";
import {AaiService} from "../shared/services/aaiService/aai.service";
import {ServiceModel} from "../shared/models/serviceModel";
import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service";
import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes";
import {updateDrawingBoardStatus} from "../shared/storeUtil/utils/global/global.actions";
import {Router, UrlTree} from "@angular/router";
import {of} from "rxjs";
import {MsoService} from "../shared/services/msoService/mso.service";
import {ServiceAction} from "../shared/models/serviceInstanceActions";
import {InstantiationBase} from "../shared/models/InstantiationBase";

export let PENDING : string = "pending";
export let INPROGRESS : string = "in_progress";
export let PAUSE : string = "pause";
export let X_O : string = "x-circle-o";
export let SUCCESS_CIRCLE : string = "success-circle-o";
export let STOPPED : string = "stop";
export let COMPLETED_WITH_ERRORS : string = "success_with_warning";
export let UNKNOWN : string = "question-mark-circle-o";


@Injectable()
export class InstantiationStatusComponentService {
  constructor( private _aaiService: AaiService,
               private _msoService: MsoService,
               private _router : Router,
               private _store: NgRedux<AppState>,
               private _featureFlagsService:FeatureFlagsService) {
  }

  generateServiceInfoDataMapping(arr: ServiceInfoModel[]) : { [serviceInstanceId: string]: ServiceInfoModel[]}{
    let serviceInfoData: { [serviceInstanceId: string]: ServiceInfoModel[]; } = {};
    for(let item of arr){
      if(_.isNil(serviceInfoData[item.templateId])){
        serviceInfoData[item.templateId] = [item];
      }else {
        serviceInfoData[item.templateId].push(item);
      }
    }
    return serviceInfoData;
  }

  convertObjectToArray(arr: ServiceInfoModel[]) : Observable<ServiceInfoUiModel[]>{
    const obj = this.generateServiceInfoDataMapping(arr);
    let index:number = 0;
    let result = [];
    for(let item in obj) {
      obj[item].map(item => {
        item['serviceStatus'] = this.getStatus(item.jobStatus);
        item['serviceIndex'] = index;
      });
      index++;
      result = result.concat(obj[item]);
    }

    console.log(result);
    return of(result);
  }

  isDrawingBoardViewEdit(serviceModel: ServiceModel): boolean {
    if (!_.isNil(serviceModel.vidNotions) && !_.isNil(serviceModel.vidNotions.viewEditUI)
      && serviceModel.vidNotions.viewEditUI !== 'legacy'){
      return true;
    }
    return false;
  }

  open(item: ServiceInfoModel): void {
    if (this._featureFlagsService.getFlagState(Features.FLAG_1902_VNF_GROUPING)) {
      this._aaiService.getServiceModelById(item['serviceModelId']).subscribe((result)=>{
        const serviceModel =  new ServiceModel(result);

        if (this.isDrawingBoardViewEdit(serviceModel)) {
          this.navigateToNewViewEdit(item, DrawingBoardModes.EDIT);
          return;
        }

        this.navigateToNewViewOnlyOrOldEditView(item);

      });
    }

    /*this else is here only to save time in case we don't need to retrieve service model
    it can be removed once it service model is always needed, and it doesn't save time*/
    else {
      this.navigateToNewViewOnlyOrOldEditView(item);
    }
  }

  navigateToNewViewOnlyOrOldEditView(item: ServiceInfoModel) {
    if (this._featureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT)) {
      this.navigateToNewViewEdit(item, DrawingBoardModes.VIEW);
    }
    else {
      this.navigateToOldViewEdit(item);
    }
  }

  navigateToOldViewEdit(item: ServiceInfoModel) {
    let query =
      `subscriberId=${item.subscriberId}&` +
      `subscriberName=${item.subscriberName}&` +
      `serviceType=${item.serviceType}&` +
      `serviceInstanceId=${item.serviceInstanceId}`;

    this._store.dispatch(updateDrawingBoardStatus(DrawingBoardModes.OLD_VIEW_EDIT));
    window.parent.location.assign('../../serviceModels.htm#/instantiate?' + query);
  }

  navigateToNewViewEdit(item: InstantiationBase, mode: DrawingBoardModes): void {
    this._store.dispatch(updateDrawingBoardStatus(mode));
    const viewEditUrlTree:UrlTree = this.getNewViewEditUrlTree(item, mode);
    this._router.navigateByUrl(viewEditUrlTree);
    window.parent.location.assign(this.getViewEditUrl(viewEditUrlTree));
  }

  getNewViewEditUrlTree(item: InstantiationBase, mode: DrawingBoardModes): UrlTree {
    return this._router.createUrlTree(
      ['/servicePlanning/' + mode],
      {
        queryParams:
        mode==DrawingBoardModes.RECREATE ?
          this.getRecreateQueryParams(item) :
          this.getDefaultViewEditQueryParams(<ServiceInfoModel> item)
      });
  }

  private getDefaultViewEditQueryParams(item: ServiceInfoModel) {
    return {
      serviceModelId: item.serviceModelId,
      serviceInstanceId: item.serviceInstanceId,
      serviceType: item.serviceType,
      subscriberId: item.subscriberId,
      jobId: item.jobId
    };
  }

  private getRecreateQueryParams(item: InstantiationBase) {
    return {
      serviceModelId: item.serviceModelId,
      jobId: item.jobId
    };
  }

  getViewEditUrl(viewEditUrlTree:UrlTree): string {
    return '../../serviceModels.htm#' + viewEditUrlTree.toString();
  }

  getStatus(status : string) : ServiceStatus {
    switch(`${status}`.toUpperCase()) {
      case  'PENDING' :
        return new ServiceStatus(PENDING, 'primary', 'Pending: The action required will be sent as soon as possible.');
      case  'IN_PROGRESS' :
        return new ServiceStatus(INPROGRESS, 'primary', 'In-progress: the service is in process of the action required.');
      case  'PAUSED' :
        return new ServiceStatus(PAUSE, 'primary', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.');
      case  'FAILED' :
        return new ServiceStatus(X_O, 'error', 'Failed: All planned actions have failed.');
      case  'COMPLETED' :
        return new ServiceStatus(SUCCESS_CIRCLE, 'success', 'Completed successfully: Service is successfully instantiated, updated or deleted.');
      case  'STOPPED' :
        return new ServiceStatus(STOPPED, 'error', 'Stopped: Due to previous failure, will not be instantiated.');
      case  'COMPLETED_WITH_ERRORS' :
        return new ServiceStatus(COMPLETED_WITH_ERRORS, 'success', 'Completed with errors: some of the planned actions where successfully committed while other have not.\n Open the service to check it out.');

      default:
        return new ServiceStatus(UNKNOWN, 'primary', `Unexpected status: "${status}"`);
    }
  }

  retry(item: ServiceInfoModel): void {
      this.navigateToNewViewEdit(item, DrawingBoardModes.RETRY_EDIT);
  }

  recreate(item: ServiceInfoModel): void {
    this.navigateToNewViewEdit(item, DrawingBoardModes.RECREATE);
  }

  isRecreateEnabled(item: ServiceInfoModel): boolean {
    return item.action === ServiceAction.INSTANTIATE;
  }

  isRecreateVisible(): boolean {
    return this._featureFlagsService.getFlagState(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE);
  }
}


export class ServiceStatus {
  iconClassName : string;
  color : string;
  tooltip : string;

  constructor(_iconClassName : string, _color : string, _tooltip : string){
    this.iconClassName = _iconClassName;
    this.color = _color;
    this.tooltip = _tooltip;
  }
}